{"title":"Terraform","description":"Manage Altertable environments, buckets, catalogs, service accounts, members, credentials, and roles with the Terraform provider.","order":650,"askSuggestions":["How do I import resources I already created in the app?","How do I give a CI service account lakehouse credentials?","When should I use Terraform instead of the CLI?"],"navigation":true,"body":{"code":"var Component=(()=>{var h=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var f=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),_=(n,e)=>{for(var t in e)i(n,t,{get:e[t],enumerable:!0})},c=(n,e,t,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of b(e))!v.call(n,o)&&o!==t&&i(n,o,{get:()=>e[o],enumerable:!(a=p(e,o))||a.enumerable});return n};var x=(n,e,t)=>(t=n!=null?h(g(n)):{},c(e||!n||!n.__esModule?i(t,\"default\",{value:n,enumerable:!0}):t,n)),y=n=>c(i({},\"__esModule\",{value:!0}),n);var d=f((T,l)=>{l.exports=_jsx_runtime});var k={};_(k,{default:()=>m,frontmatter:()=>w});var r=x(d()),w={title:\"Terraform\",description:\"Manage Altertable environments, buckets, catalogs, service accounts, members, credentials, and roles with the Terraform provider.\",order:650,askSuggestions:[\"How do I import resources I already created in the app?\",\"How do I give a CI service account lakehouse credentials?\",\"When should I use Terraform instead of the CLI?\"]};function u(n){let e={a:\"a\",code:\"code\",h1:\"h1\",h2:\"h2\",p:\"p\",pre:\"pre\",strong:\"strong\",...n.components},{DocsPreviewDocument:t,DocsPreviewSection:a,DocsTable:o}=e;return t||s(\"DocsPreviewDocument\",!0),a||s(\"DocsPreviewSection\",!0),o||s(\"DocsTable\",!0),(0,r.jsxs)(t,{anchors:\"terraform setup resources example import-existing-resources source-code\",children:[(0,r.jsxs)(a,{sectionId:\"terraform\",anchors:\"\",ancestors:\"\",index:\"0\",children:[(0,r.jsx)(e.h1,{id:\"terraform\",children:\"Terraform\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"The Altertable Terraform provider manages Altertable resources from configuration: environments, storage buckets, catalogs, service accounts, organization members, lakehouse credentials, and role grants. Use it to review platform changes as plans, keep environments reproducible, and provision access for automation alongside the rest of your infrastructure. It works with Terraform \",(0,r.jsx)(e.code,{children:\"1.0+\"}),\" and OpenTofu.\"]}),`\n`,(0,r.jsxs)(e.p,{children:[\"Use Terraform for declarative infrastructure state. Use the \",(0,r.jsx)(e.a,{href:\"/docs/lakehouse/clients/cli\",children:\"CLI\"}),\" for interactive checks, one-off operations, and scripts that need to inspect or act on existing Altertable resources.\"]}),`\n`]}),(0,r.jsxs)(a,{sectionId:\"setup\",anchors:\"\",ancestors:\"\",index:\"1\",children:[(0,r.jsx)(e.h2,{id:\"setup\",children:\"Setup\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"Add the provider to \",(0,r.jsx)(e.code,{children:\"required_providers\"}),\" and configure it with a management API key:\"]}),`\n`,(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:\"language-terraform\",children:`terraform {\n  required_version = \">= 1.0\"\n  required_providers {\n    altertable = {\n      source = \"altertable-ai/altertable\"\n    }\n  }\n}\n\nprovider \"altertable\" {\n  api_key = var.altertable_management_api_key\n}\n`})}),`\n`,(0,r.jsxs)(e.p,{children:[\"Issue a management API key from \",(0,r.jsx)(e.strong,{children:\"Organization settings \\u2192 Management API keys\"}),\", then pass it as \",(0,r.jsx)(e.code,{children:\"api_key\"}),\" or set the \",(0,r.jsx)(e.code,{children:\"ALTERTABLE_API_KEY\"}),\" environment variable.\"]}),`\n`]}),(0,r.jsxs)(a,{sectionId:\"resources\",anchors:\"\",ancestors:\"\",index:\"2\",children:[(0,r.jsx)(e.h2,{id:\"resources\",children:\"Resources\"}),`\n`,(0,r.jsx)(o,{columns:[\"Resource\",\"Manages\"],data:[{Resource:\"`altertable_environment`\",Manages:\"Environments and their cloud provider\"},{Resource:\"`altertable_bucket`\",Manages:\"Object-storage buckets connected to an environment, backing lakehouse catalogs\"},{Resource:\"`altertable_catalog`\",Manages:'Native databases (`engine = \"altertable\"`) and external connections such as Postgres, MySQL, BigQuery, or Snowflake'},{Resource:\"`altertable_service_account`\",Manages:\"Service accounts for automation\"},{Resource:\"`altertable_user`\",Manages:\"Organization members, invited by email\"},{Resource:\"`altertable_credential`\",Manages:\"Lakehouse credentials for a user or service account in an environment\"},{Resource:\"`altertable_role_set`\",Manages:\"The complete set of role grants for one principal\"}]}),`\n`,(0,r.jsxs)(e.p,{children:[`Similarly, data sources exist for buckets, catalogs, credentials, environments, service accounts, and users.\nA special `,(0,r.jsx)(e.code,{children:\"altertable_whoami\"}),\" data source looks up the identity behind the configured key.\"]}),`\n`,(0,r.jsxs)(e.p,{children:[\"Full argument reference for every resource and data source lives on the \",(0,r.jsx)(e.a,{href:\"https://registry.terraform.io/providers/altertable-ai/altertable/latest/docs\",children:\"Terraform Registry\"}),\".\"]}),`\n`]}),(0,r.jsxs)(a,{sectionId:\"example\",anchors:\"\",ancestors:\"\",index:\"3\",children:[(0,r.jsx)(e.h2,{id:\"example\",children:\"Example\"}),`\n`,(0,r.jsx)(e.p,{children:\"A complete setup: an environment with a native and an external catalog, and a service account with scoped roles and a lakehouse credential for CI.\"}),`\n`,(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:\"language-terraform\",children:`resource \"altertable_environment\" \"production\" {\n  name           = \"Production\"\n  cloud_provider = \"aws\"\n  cloud_provider_region = \"us-east-1\"\n}\n\nresource \"altertable_catalog\" \"warehouse\" {\n  environment_id = altertable_environment.production.id\n  engine         = \"altertable\"\n  name           = \"Warehouse\"\n}\n\nresource \"altertable_catalog\" \"analytics\" {\n  environment_id = altertable_environment.production.id\n  engine         = \"postgres\"\n  name           = \"Analytics\"\n\n  postgres_config = {\n    host     = \"db.example.com\"\n    port     = 5432\n    database = \"analytics\"\n    username = \"altertable\"\n    password = var.pg_password\n  }\n}\n\nresource \"altertable_user\" \"teammate\" {\n  email = \"teammate@example.com\"\n}\n\nresource \"altertable_role_set\" \"teammate\" {\n  user_id = altertable_user.teammate.id\n\n  roles = [\n    { role = \"organization:member\" },\n    { role = \"environment:writer\", resource_id = altertable_environment.production.id },\n  ]\n}\n\nresource \"altertable_service_account\" \"ci\" {\n  label = \"CI Deploy\"\n}\n\nresource \"altertable_role_set\" \"ci\" {\n  service_account_id = altertable_service_account.ci.id\n\n  roles = [\n    { role = \"organization:member\" },\n    { role = \"environment:writer\", resource_id = altertable_environment.production.id },\n  ]\n}\n\nresource \"altertable_credential\" \"ci\" {\n  principal_type = \"service_account\"\n  principal_id   = altertable_service_account.ci.id\n  environment_id = altertable_environment.production.id\n  label          = \"CI\"\n}\n\noutput \"ci_password\" {\n  value     = altertable_credential.ci.password\n  sensitive = true\n}\n`})}),`\n`,(0,r.jsxs)(e.p,{children:[\"A role set declares the complete set of grants for a single principal: one \",(0,r.jsx)(e.code,{children:\"altertable_role_set\"}),\" per user or service account, mixing organization-wide roles with roles scoped to a \",(0,r.jsx)(e.code,{children:\"resource_id\"}),\". See \",(0,r.jsx)(e.a,{href:\"/docs/administration/access-control\",children:\"Access control\"}),\" for the available roles.\"]}),`\n`]}),(0,r.jsxs)(a,{sectionId:\"import-existing-resources\",anchors:\"\",ancestors:\"\",index:\"4\",children:[(0,r.jsx)(e.h2,{id:\"import-existing-resources\",children:\"Import existing resources\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"Bring resources created in the app under Terraform with \",(0,r.jsx)(e.code,{children:\"import\"}),\" blocks (Terraform \",(0,r.jsx)(e.code,{children:\"1.12+\"}),\") and resource identities:\"]}),`\n`,(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:\"language-terraform\",children:`import {\n  to = altertable_environment.production\n  identity = {\n    id = \"7d3e1b9a-2c4f-4a6b-9e8d-5f0a1b2c3d4e\"\n  }\n}\n`})}),`\n`,(0,r.jsxs)(e.p,{children:[\"Environments, buckets, catalogs, service accounts, credentials, and users support identity import. Nested resources use composite identities \\u2014 a catalog, for example, is identified by its \",(0,r.jsx)(e.code,{children:\"environment_id\"}),\" and \",(0,r.jsx)(e.code,{children:\"id\"}),\". A user is imported by its raw \",(0,r.jsx)(e.code,{children:\"user_id\"}),\".\"]}),`\n`]}),(0,r.jsxs)(a,{sectionId:\"source-code\",anchors:\"\",ancestors:\"\",index:\"5\",children:[(0,r.jsx)(e.h2,{id:\"source-code\",children:\"Source code\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"The provider is published on the \",(0,r.jsx)(e.a,{href:\"https://registry.terraform.io/providers/altertable-ai/altertable\",children:\"Terraform Registry\"}),\", and its source code is available at \",(0,r.jsx)(e.a,{href:\"https://github.com/altertable-ai/terraform-provider-altertable\",children:\"github.com/altertable-ai/terraform-provider-altertable\"}),\".\"]})]})]})}function m(n={}){let{wrapper:e}=n.components||{};return e?(0,r.jsx)(e,{...n,children:(0,r.jsx)(u,{...n})}):u(n)}function s(n,e){throw new Error(\"Expected \"+(e?\"component\":\"object\")+\" `\"+n+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return y(k);})();\n;return Component;"},"_id":"docs/administration/infrastructure-as-code.mdx","_raw":{"sourceFilePath":"docs/administration/infrastructure-as-code.mdx","sourceFileName":"infrastructure-as-code.mdx","sourceFileDir":"docs/administration","contentType":"mdx","flattenedPath":"docs/administration/infrastructure-as-code"},"type":"Docs","path":"/administration/infrastructure-as-code","level":2,"parent":"administration"}