Repository Public
1# Terraform provider23> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.45The official [OpenAI Terraform provider](https://github.com/openai/terraform-provider-openai) lets you manage OpenAI organization resources with infrastructure as code. The provider uses the [Administration API](https://developers.openai.com/api/reference/administration/overview) to manage projects, users, groups, roles, service accounts, certificates, rate limits, spend alerts, and related project settings.67This guide creates an OpenAI project. Continue to the use-case guides for project access, service accounts, operational limits, project controls, and imports.89## Before you begin1011You need:1213- [Terraform](https://developer.hashicorp.com/terraform/install) 1.0 or later. The import examples require Terraform 1.5 or later.14- An OpenAI organization with permission to create an [Admin API key](https://platform.openai.com/settings/organization/admin-keys).1516Administration API endpoints require Admin API keys, which don't work with non-administration OpenAI API endpoints. Store the key in an environment variable or a secrets manager. Don't commit it to your Terraform configuration or source control.1718## Configure the provider1920Create a new directory and add a `main.tf` file with the following configuration:2122```terraform23terraform {24 required_version = ">= 1.0"2526 required_providers {27 openai = {28 source = "openai/openai"29 version = ">= 1.0.0"30 }31 }32}3334provider "openai" {}3536resource "openai_project" "example" {37 name = "terraform-managed"38}3940output "project_id" {41 value = openai_project.example.project_id42}43```4445The version constraint allows provider version 1.0.0 and later. Review the [provider releases](https://github.com/openai/terraform-provider-openai/releases) before upgrading.4647Set your Admin API key in the environment:4849```bash50export OPENAI_ADMIN_KEY="<your-admin-api-key>"51```5253The provider reads `OPENAI_ADMIN_KEY` by default. You can also set `OPENAI_ORG_ID` and `OPENAI_PROJECT_ID` to send the `OpenAI-Organization` and `OpenAI-Project` headers with API requests. When these optional variables aren't set, OpenAI resolves the organization and project from the API key. Set them when you want to explicitly identify which organization or project your Terraform configuration manages. See the [provider configuration reference](https://registry.terraform.io/providers/openai/openai/latest/docs) for all available arguments.5455## Initialize and apply5657Initialize the working directory, then format and check the configuration:5859```bash60terraform init61terraform fmt62terraform validate63```6465Terraform downloads the provider and creates `.terraform.lock.hcl`. Commit the lock file to source control so future runs select the same provider version. Run `terraform init -upgrade` to select the latest provider version allowed by the constraint.6667Review the changes Terraform will make:6869```bash70terraform plan71```7273The plan should show one `openai_project` resource to add. Apply the configuration only after you have reviewed the plan:7475```bash76terraform apply77```7879Confirm the apply when prompted. Terraform creates the project and prints its ID from the `project_id` output.8081## Choose a use-case guide8283| Guide | Use it to |84| ----------------------------------------------------------------------------- | ------------------------------------------------------------------------ |85| [Projects and access](https://developers.openai.com/api/docs/guides/terraform/projects-and-access) | Create projects and configure role-based and group-based access. |86| [Service accounts](https://developers.openai.com/api/docs/guides/terraform/service-accounts) | Create service accounts for workload identity or API-key authentication. |87| [Rate limits and spend](https://developers.openai.com/api/docs/guides/terraform/rate-limits-and-spend) | Reconcile existing rate limits and configure spend alerts. |88| [Model, tool, and data controls](https://developers.openai.com/api/docs/guides/terraform/project-controls) | Configure model access, hosted tools, and data retention. |89| [Import and reconciliation](https://developers.openai.com/api/docs/guides/terraform/import-and-reconcile) | Adopt existing resources and detect drift. |9091For individual arguments and import formats, use the [provider resource and data source reference](https://registry.terraform.io/providers/openai/openai/latest/docs).