The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
docs: add federated terraform docs (#21307)
Charis538fb7ee0ce7
diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.tsindex 512de1e8198..b533e6779b9 100644--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts@@ -1656,6 +1656,24 @@ export const platform: NavMenuConstant = {{ name: 'SSO with Okta', url: '/guides/platform/sso/okta' },],},+ {+ name: 'Terraform',+ url: undefined,+ items: [+ {+ name: 'Terraform Provider',+ url: '/guides/platform/terraform',+ },+ {+ name: 'Terraform Tutorial',+ url: '/guides/platform/terraform/tutorial',+ },+ {+ name: 'Reference',+ url: '/guides/platform/terraform/reference',+ },+ ],+ },{name: 'Production Readiness',url: undefined,diff --git a/apps/docs/package.json b/apps/docs/package.jsonindex b934a33525a..2d37fe12d91 100644--- a/apps/docs/package.json+++ b/apps/docs/package.json@@ -33,11 +33,13 @@"@supabase/supabase-js": "^2.39.3","@tanstack/react-query": "^5.13.4","common": "*",+ "common-tags": "^1.8.2","config": "*","framer-motion": "^11.0.3","github-slugger": "^2.0.0","gray-matter": "^4.0.3","hast-util-has-property": "^2.0.1",+ "icons": "*","isbot": "^3.6.5","jsrsasign": "^11.0.0","lodash": "^4.17.21",diff --git a/apps/docs/pages/guides/platform/terraform/[[...slug]].tsx b/apps/docs/pages/guides/platform/terraform/[[...slug]].tsxnew file mode 100644index 00000000000..1eb6d14123f--- /dev/null+++ b/apps/docs/pages/guides/platform/terraform/[[...slug]].tsx@@ -0,0 +1,167 @@+import { CodeHikeConfig, remarkCodeHike } from '@code-hike/mdx'+import matter from 'gray-matter'+import { GetStaticPaths, GetStaticProps, InferGetStaticPropsType } from 'next'+import { MDXRemote } from 'next-mdx-remote'+import { serialize } from 'next-mdx-remote/serialize'+import remarkGfm from 'remark-gfm'+import rehypeSlug from 'rehype-slug'++import codeHikeTheme from 'config/code-hike.theme.json' assert { type: 'json' }++import components from '~/components'+import { MenuId } from '~/components/Navigation/NavigationMenu/NavigationMenu'+import Layout from '~/layouts/DefaultGuideLayout'+import { isValidGuideFrontmatter } from '~/lib/docs'+import { UrlTransformFunction, linkTransform } from '~/lib/mdx/plugins/rehypeLinkTransform'+import remarkMkDocsAdmonition from '~/lib/mdx/plugins/remarkAdmonition'+import { removeTitle } from '~/lib/mdx/plugins/remarkRemoveTitle'+import remarkPyMdownTabs from '~/lib/mdx/plugins/remarkTabs'++// We fetch these docs at build time from an external repo+export const org = 'supabase'+export const repo = 'terraform-provider-supabase'+export const branch = 'v1.1.3'+export const docsDir = 'docs'++// Each external docs page is mapped to a local page+const pageMap = [+ {+ remoteFile: 'README.md',+ meta: {+ title: 'Terraform Provider',+ },+ useRoot: true,+ },+ {+ slug: 'tutorial',+ remoteFile: 'tutorial.md',+ meta: {+ title: 'Using the Supabase Terraform Provider',+ },+ },+]++export default function TerraformDocs({+ source,+ meta,+ editLink,+}: InferGetStaticPropsType<typeof getStaticProps>) {+ return (+ <Layout menuId={MenuId.Platform} meta={meta} editLink={editLink}>+ <MDXRemote {...source} components={components} />+ </Layout>+ )+}++/**+ * The GitHub repo uses relative links, which don't lead to the right locations+ * in docs.+ *+ * @param url The original link, as written in the Markdown file+ * @returns The rewritten link+ */+const urlTransform: UrlTransformFunction = (url: string) => {+ try {+ const placeholderHostname = 'placeholder'+ const { hostname, pathname, hash } = new URL(url, `http://${placeholderHostname}`)++ // Don't modify a url with a FQDN or a url that's only a hash+ if (hostname !== placeholderHostname || pathname === '/') {+ return url+ }++ const getBasename = (pathname: string) =>+ pathname.endsWith('.md') ? pathname.replace(/\.md$/, '') : pathname+ const stripLeadingPrefix = (pathname: string) => pathname.replace(/^\//, '')+ const stripLeadingDocs = (pathname: string) => pathname.replace(/^docs\//, '')++ const relativePath = stripLeadingPrefix(getBasename(pathname))++ const page = pageMap.find(+ ({ remoteFile, useRoot }) =>+ (useRoot && `${relativePath}.md` === remoteFile) ||+ (!useRoot && `${stripLeadingDocs(relativePath)}.md` === remoteFile)+ )++ if (page) {+ return 'terraform' + `/${page.slug}` + hash+ }++ // If we don't have this page in our docs, link to GitHub repo+ return `https://github.com/${org}/${repo}/blob/${branch}${pathname}${hash}`+ } catch (err) {+ console.error('Error transforming markdown URL', err)+ return url+ }+}++/**+ * Fetch markdown from external repo and transform links+ */+export const getStaticProps = (async ({ params }) => {+ const [slug] = params.slug ?? []+ const page = pageMap.find((page) => page.slug === slug)++ if (!page) {+ throw new Error(`No page mapping found for slug '${slug}'`)+ }++ const { meta, remoteFile, useRoot } = page++ let response = await fetch(+ `https://raw.githubusercontent.com/${org}/${repo}/${branch}/${useRoot ? '' : `${docsDir}/`}${remoteFile}`+ )++ let content = await response.text()+ // Strip out HTML comments+ content = content.replace(/<!--.*?-->/, '')+ const { content: source, data } = matter(content)+ Object.assign(meta, data)++ if (!isValidGuideFrontmatter(meta)) {+ throw Error('Guide frontmatter is invalid.')+ }++ const codeHikeOptions: CodeHikeConfig = {+ theme: codeHikeTheme,+ lineNumbers: true,+ showCopyButton: true,+ skipLanguages: [],+ autoImport: false,+ }++ const mdxSource = await serialize(source, {+ scope: {+ chCodeConfig: codeHikeOptions,+ },+ mdxOptions: {+ remarkPlugins: [+ remarkGfm,+ remarkMkDocsAdmonition,+ remarkPyMdownTabs,+ [removeTitle, meta.title],+ [remarkCodeHike, codeHikeOptions],+ ],+ rehypePlugins: [[linkTransform, urlTransform], rehypeSlug],+ },+ })++ return {+ props: {+ source: mdxSource,+ meta,+ editLink: `${org}/${repo}/blob/${branch}/${docsDir}/${slug}.md`,+ },+ }+}) satisfies GetStaticProps++export const getStaticPaths = (async () => {+ return {+ paths: pageMap.map(({ slug }) => ({+ params: {+ slug: slug ? [slug] : [],+ },+ })),+ fallback: false,+ }+}) satisfies GetStaticPathsdiff --git a/apps/docs/pages/guides/platform/terraform/reference.tsx b/apps/docs/pages/guides/platform/terraform/reference.tsxnew file mode 100644index 00000000000..8004ab606c9--- /dev/null+++ b/apps/docs/pages/guides/platform/terraform/reference.tsx@@ -0,0 +1,400 @@+import { codeBlock } from 'common-tags'+import { GetStaticProps, InferGetStaticPropsType } from 'next'+import Link from 'next/link'+import ReactMarkdown from 'react-markdown'++import {+ CodeBlock,+ Heading,+ IconCheck,+ IconPlusCircle,+ PopoverContent_Shadcn_,+ PopoverTrigger_Shadcn_,+ Popover_Shadcn_,+ Tabs,+} from 'ui'++import { MenuId } from '~/components/Navigation/NavigationMenu/NavigationMenu'+import Layout from '~/layouts/DefaultGuideLayout'+import { org, repo, branch, docsDir } from './[[...slug]]'++function ProviderSettings({ schema }: { schema: any }) {+ const attributes = schema.block.attributes++ const example = codeBlock`+ provider "supabase" {+ ${Object.keys(attributes).map(+ (attribute) =>+ `${attribute} = ${attributes[attribute].type === 'string' ? `""` : '<value>'}`+ )}+ }+ `++ return (+ <section aria-labelledby="provider-settings" className="prose max-w-none">+ <Heading tag="h2">Provider settings</Heading>+ <p>+ Use these settings to configure your Supabase provider and authenticate to your Supabase+ project.+ </p>+ <Heading tag="h3">Example usage</Heading>+ <CodeBlock className="not-prose">{example}</CodeBlock>+ <Heading tag="h3">Details</Heading>+ {/* extra div because width restriction doesn't work on table itself */}+ <div className="w-full overflow-auto">+ <table>+ <thead>+ <tr>+ <th>Attribute</th>+ <th>Description</th>+ <th>Type</th>+ <th>Optional</th>+ <th>Sensitive</th>+ </tr>+ </thead>+ <tbody>+ {Object.keys(schema.block.attributes).map((attribute) => (+ <tr key={attribute}>+ <td>{attribute}</td>+ <td>+ <ReactMarkdown>{attributes[attribute].description}</ReactMarkdown>+ </td>+ <td>{attributes[attribute].type}</td>+ <td className="align-middle">+ {attributes[attribute].optional && (+ <>+ <IconCheck className="ml-[2.5ch]" />+ <span className="sr-only">true</span>+ </>+ )}+ </td>+ <td className="align-middle">+ {attributes[attribute].sensitive && (+ <>+ <IconCheck className="ml-[2.5ch]" />+ <span className="sr-only">true</span>+ </>+ )}+ </td>+ </tr>+ ))}+ </tbody>+ </table>+ </div>+ </section>+ )+}++function Resources({ schema }: { schema: any }) {+ return (+ <section aria-labelledby="resources" className="prose max-w-none">+ <Heading tag="h2">Resources</Heading>+ <p>You can configure these resources using the Supabase Terraform provider:</p>+ <Tabs>+ {Object.keys(schema).map((resource) => (+ <Tabs.Panel id={resource} label={resource}>+ <Heading tag="h4">Example usage</Heading>+ <CodeBlock className="not-prose">{codeBlock`+ resource "${resource}" "<label>" {+ ${Object.keys(schema[resource].block.attributes)+ .filter((attribute) => !schema[resource].block.attributes[attribute].computed)+ .map(+ (attribute) =>+ `${attribute} = ${+ schema[resource].block.attributes[attribute].type === 'string'+ ? `""`+ : '<value>'+ }`+ )}+ }+ `}</CodeBlock>+ <Heading tag="h4">Details</Heading>+ <table>+ <thead>+ <tr>+ <th>Attribute</th>+ <th>Description</th>+ <th>Type</th>+ <th>Required</th>+ <th>Optional</th>+ <th>Read-only</th>+ </tr>+ </thead>+ <tbody>+ {Object.keys(schema[resource].block.attributes).map((attribute) => (+ <tr key={attribute}>+ <td>+ <code>{attribute}</code>+ </td>+ <td>+ <ReactMarkdown>+ {schema[resource].block.attributes[attribute].description}+ </ReactMarkdown>+ </td>+ <td>+ {schema[resource].block.attributes[attribute].type ?? (+ <Popover_Shadcn_>+ <PopoverTrigger_Shadcn_ asChild>+ <button className="flex items-center justify-between gap-2">+ Nested type+ <IconPlusCircle size={14} className="shrink-0" />+ </button>+ </PopoverTrigger_Shadcn_>+ <PopoverContent_Shadcn_ className="max-h-[50vh] overflow-auto">+ <ul>+ {Object.keys(+ schema[resource].block.attributes[attribute].nested_type.attributes+ ).map((nestedAttribute) => (+ <li key={nestedAttribute}>+ {nestedAttribute}+ <ul>+ <li>+ <ReactMarkdown className="*:!m-0">+ {+ schema[resource].block.attributes[attribute].nested_type+ .attributes[nestedAttribute].description+ }+ </ReactMarkdown>+ </li>+ <li>+ {schema[resource].block.attributes[attribute].nested_type+ .attributes[nestedAttribute].type ?? 'nested type'}+ </li>+ {schema[resource].block.attributes[attribute].nested_type+ .attributes[nestedAttribute].required && <li>Required</li>}+ {schema[resource].block.attributes[attribute].nested_type+ .attributes[nestedAttribute].optional && <li>Optional</li>}+ {schema[resource].block.attributes[attribute].nested_type+ .attributes[nestedAttribute].computed && <li>Read-only</li>}+ </ul>+ </li>+ ))}+ </ul>+ </PopoverContent_Shadcn_>+ </Popover_Shadcn_>+ )}+ </td>+ <td className="align-middle">+ {schema[resource].block.attributes[attribute].required && (+ <>+ <IconCheck className="ml-[2.5ch]" />+ <span className="sr-only">true</span>+ </>+ )}+ </td>+ <td className="align-middle">+ {schema[resource].block.attributes[attribute].optional && (+ <>+ <IconCheck className="ml-[2.5ch]" />+ <span className="sr-only">true</span>+ </>+ )}+ </td>+ <td className="align-middle">+ {schema[resource].block.attributes[attribute].computed && (+ <>+ <IconCheck className="ml-[2.5ch]" />+ <span className="sr-only">true</span>+ </>+ )}+ </td>+ </tr>+ ))}+ </tbody>+ </table>+ </Tabs.Panel>+ ))}+ </Tabs>+ </section>+ )+}++function DataSources({ schema }: { schema: any }) {+ return (+ <section aria-labelledby="data-sources" className="prose max-w-none">+ <Heading tag="h2">Data sources</Heading>+ <p>You can read these resources using the Supabase Terraform provider:</p>+ <Tabs>+ {Object.keys(schema).map((dataSource) => (+ <Tabs.Panel id={dataSource} label={dataSource}>+ <Heading tag="h4">Example usage</Heading>+ <CodeBlock className="not-prose">{codeBlock`+ resource "${dataSource}" "all" {+ ${Object.keys(schema[dataSource].block.attributes)+ .filter(+ (attribute) => !schema[dataSource].block.attributes[attribute].computed+ )+ .map(+ (attribute) =>+ `${attribute} = ${+ schema[dataSource].block.attributes[attribute].type === 'string'+ ? `""`+ : '<value>'+ }`+ )}+ }+ `}</CodeBlock>+ <Heading tag="h4">Details</Heading>+ <table>+ <thead>+ <tr>+ <th>Attribute</th>+ <th>Description</th>+ <th>Type</th>+ <th>Required</th>+ <th>Optional</th>+ <th>Read-only</th>+ </tr>+ </thead>+ <tbody>+ {Object.keys(schema[dataSource].block.attributes).map((attribute) => (+ <tr key={attribute}>+ <td>+ <code>{attribute}</code>+ </td>+ <td>+ <ReactMarkdown>+ {schema[dataSource].block.attributes[attribute].description}+ </ReactMarkdown>+ </td>+ <td>+ {schema[dataSource].block.attributes[attribute].type ?? (+ <Popover_Shadcn_>+ <PopoverTrigger_Shadcn_ asChild>+ <button className="flex items-center justify-between gap-2">+ Nested type+ <IconPlusCircle size={14} />+ </button>+ </PopoverTrigger_Shadcn_>+ <PopoverContent_Shadcn_ className="max-h-[50vh] overflow-auto">+ {schema[dataSource].block.attributes[attribute].nested_type+ .nesting_mode === 'set' && 'Array of:'}+ <ul>+ {Object.keys(+ schema[dataSource].block.attributes[attribute].nested_type+ .attributes+ ).map((nestedAttribute) => (+ <li key={nestedAttribute}>+ {nestedAttribute}+ <ul>+ <li>+ <ReactMarkdown className="*:!m-0">+ {+ schema[dataSource].block.attributes[attribute].nested_type+ .attributes[nestedAttribute].description+ }+ </ReactMarkdown>+ </li>+ <li>+ {schema[dataSource].block.attributes[attribute].nested_type+ .attributes[nestedAttribute].type ?? 'nested type'}+ </li>+ {schema[dataSource].block.attributes[attribute].nested_type+ .attributes[nestedAttribute].required && <li>Required</li>}+ {schema[dataSource].block.attributes[attribute].nested_type+ .attributes[nestedAttribute].optional && <li>Optional</li>}+ {schema[dataSource].block.attributes[attribute].nested_type+ .attributes[nestedAttribute].computed && <li>Read-only</li>}+ </ul>+ </li>+ ))}+ </ul>+ </PopoverContent_Shadcn_>+ </Popover_Shadcn_>+ )}+ </td>+ <td className="align-middle">+ {schema[dataSource].block.attributes[attribute].required && (+ <>+ <IconCheck className="ml-[2.5ch]" />+ <span className="sr-only">true</span>+ </>+ )}+ </td>+ <td className="align-middle">+ {schema[dataSource].block.attributes[attribute].optional && (+ <>+ <IconCheck className="ml-[2.5ch]" />+ <span className="sr-only">true</span>+ </>+ )}+ </td>+ <td className="align-middle">+ {schema[dataSource].block.attributes[attribute].computed && (+ <>+ <IconCheck className="ml-[2.5ch]" />+ <span className="sr-only">true</span>+ </>+ )}+ </td>+ </tr>+ ))}+ </tbody>+ </table>+ </Tabs.Panel>+ ))}+ </Tabs>+ </section>+ )+}++export default function PGGraphQLDocs({+ meta,+ schema,+}: InferGetStaticPropsType<typeof getStaticProps>) {+ return (+ <Layout menuId={MenuId.Platform} meta={meta}>+ The Terraform Provider provices access to{' '}+ <Link+ href="https://developer.hashicorp.com/terraform/language/resources"+ rel="noopener noreferrer"+ >+ resources+ </Link>{' '}+ and{' '}+ <Link+ href="https://developer.hashicorp.com/terraform/language/data-sources"+ rel="noreferrer noopener"+ >+ data sources+ </Link>+ . Resources are infrastructure objects, such as a Supabase project, that you can declaratively+ configure. Data sources are sources of information about your Supabase instances.+ <ProviderSettings+ schema={schema.provider_schemas['registry.terraform.io/supabase/supabase'].provider}+ />+ <Resources+ schema={schema.provider_schemas['registry.terraform.io/supabase/supabase'].resource_schemas}+ />+ <DataSources+ schema={+ schema.provider_schemas['registry.terraform.io/supabase/supabase'].data_source_schemas+ }+ />+ </Layout>+ )+}++/**+ * Fetch JSON schema from external repo+ */+export const getStaticProps = (async () => {+ const meta = {+ title: 'Terraform Provider reference',+ subtitle: 'Resources and data sources available through the Terraform Provider',+ }++ let response = await fetch(+ `https://raw.githubusercontent.com/${org}/${repo}/${branch}/${docsDir}/schema.json`+ )+ if (!response.ok) throw Error('Failed to fetch Terraform JSON schema from GitHub')++ const schema = await response.json()++ return {+ props: {+ meta,+ schema,+ },+ }+}) satisfies GetStaticPropsdiff --git a/package-lock.json b/package-lock.jsonindex cd59786c63e..81a1b75a996 100644--- a/package-lock.json+++ b/package-lock.json@@ -475,6 +475,7 @@"@supabase/supabase-js": "^2.39.3","@tanstack/react-query": "^5.13.4","common": "*",+ "common-tags": "^1.8.2","config": "*","framer-motion": "^11.0.3","github-slugger": "^2.0.0",@@ -18355,7 +18356,8 @@},"node_modules/common-tags": {"version": "1.8.2",- "license": "MIT",+ "resolved": "https://registry.npmjs.org/common-tags/-/common-tags-1.8.2.tgz",+ "integrity": "sha512-gk/Z852D2Wtb//0I+kRFNKKE9dIIVirjoqPoA1wJU+XePVXZfGeBpk45+A1rKO4Q43prqWBNY/MiIeRLbPWUaA==","engines": {"node": ">=4.0.0"}diff --git a/packages/ui/src/components/CodeBlock/CodeBlock.tsx b/packages/ui/src/components/CodeBlock/CodeBlock.tsxindex f94469634e1..a78b34f1cca 100644--- a/packages/ui/src/components/CodeBlock/CodeBlock.tsx+++ b/packages/ui/src/components/CodeBlock/CodeBlock.tsx@@ -19,7 +19,7 @@ import { useTheme } from 'next-themes'export interface CodeBlockProps {title?: string- language: 'js' | 'jsx' | 'sql' | 'py' | 'bash' | 'ts' | 'dart' | 'json' | 'csharp' | 'kotlin'+ language?: 'js' | 'jsx' | 'sql' | 'py' | 'bash' | 'ts' | 'dart' | 'json' | 'csharp' | 'kotlin'linesToHighlight?: number[]hideCopy?: booleanhideLineNumbers?: boolean