> ## Documentation Index
> Fetch the complete documentation index at: https://docs.opper.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Manage Opper with Terraform

> Install the Opper Terraform provider, provision a project, and import existing configuration.

Use the [Opper Terraform provider](https://registry.terraform.io/providers/opper-ai/opper/latest/docs)
to declare your Opper configuration in HCL and review changes before applying
them. The provider uses the [Management API](https://docs.opper.ai/control-plane/management-api.md).

## Set up the provider

Use Terraform 1.11 or later. In the Opper dashboard, select the organization
you want to manage and create a key under
**Settings → API Keys → Management keys**. The management key determines
which organization Terraform manages.

Give the key `projects:read` to refresh or import projects and
`projects:write` to create or update them. Grant `projects:delete` only to
operators who need to delete projects. For a CI job that only runs plans, use a
separate key with the read scopes for the resources in your configuration.

Set `OPPER_MANAGEMENT_API_KEY` in your shell or inject it from your CI secret
store. The provider expects a management key (`op-mak-…`). Applications use a
separate runtime key (`op-…`) for inference. Keep credentials out of HCL and
version control.

Save the following as `main.tf` in an empty directory. Choose a unique project
name in the organization. The example creates a project with Organization
access. If the project needs to start out Restricted, set `initial_access`
before applying and grant the key `project_access:write` in addition to
`projects:write`.

```hcl main.tf theme={null}
terraform {
  required_version = ">= 1.11"

  required_providers {
    opper = {
      source  = "opper-ai/opper"
      version = "~> 0.3.0"
    }
  }
}

provider "opper" {}

resource "opper_project" "app" {
  name        = "checkout-service"
  description = "Model calls from the checkout service"
}
```

Initialize the directory and review the plan. For a new project, Terraform
should show one resource to add. Run `terraform apply` when you're ready to
create it, and review the proposed change at the confirmation prompt.

```bash theme={null}
terraform init
terraform plan
terraform apply
```

## Import an existing project

To adopt a project you already have, start in an empty directory with the
`terraform` and `provider` blocks from the example. Add the resource and import
blocks below, using the project's current name, description, and UUID. Leave
`initial_access` out, and make sure no other Terraform state manages the project.
If you're adding the project to an existing Terraform configuration, use an
unused resource address and match it in the import block.

```hcl theme={null}
resource "opper_project" "app" {
  name        = "checkout-service"
  description = "Model calls from the checkout service"
}

import {
  to = opper_project.app
  id = "01234567-89ab-4cde-8012-3456789abcde"
}
```

Run `terraform init` and `terraform plan`. If your goal is adoption without a
configuration change, look for **1 to import, 0 to add, 0 to change, 0 to
destroy**. Fix any unexpected differences before running `terraform apply`. A
key with `projects:read` is enough for this import-only plan and apply. Run
`terraform plan` again to check for a clean plan.

To look up a project by UUID without managing it, use the
[`opper_project` data source](https://registry.terraform.io/providers/opper-ai/opper/latest/docs/data-sources/project).

## State and credentials

For shared environments, use an encrypted, access-controlled remote state
backend with locking. Commit `.terraform.lock.hcl` so CI and local runs select the
same provider version. Restrict access to saved plan files as well as state.

The [runtime key resource](https://registry.terraform.io/providers/opper-ai/opper/latest/docs/resources/api_key)
manages project-owned keys. Terraform hides newly minted runtime secrets in
normal CLI output and stores them in state. Import recovers key metadata only.
Keep personal keys outside Terraform.

> [!WARNING]
>
> Deleting an Opper project permanently revokes all runtime keys bound to it,
> including keys created outside Terraform. Review destroy and replacement
> plans carefully. Use `prevent_destroy` to block Terraform from destroying a
> project while its resource block is still in your configuration.

## What you can manage

| Area | Terraform resources |
| - | - |
| Projects and project access | [Project](https://registry.terraform.io/providers/opper-ai/opper/latest/docs/resources/project), [project access policy](https://registry.terraform.io/providers/opper-ai/opper/latest/docs/resources/project_access) |
| Runtime keys and webhooks | [Runtime key and IP allowlist](https://registry.terraform.io/providers/opper-ai/opper/latest/docs/resources/api_key), [default webhook URL](https://registry.terraform.io/providers/opper-ai/opper/latest/docs/resources/project_webhook) |
| Rules and model lists | [Rule](https://registry.terraform.io/providers/opper-ai/opper/latest/docs/resources/rule), [organization model list](https://registry.terraform.io/providers/opper-ai/opper/latest/docs/resources/organization_model_list), [project model list](https://registry.terraform.io/providers/opper-ai/opper/latest/docs/resources/project_model_list) |
| Dynamic routing | [Route draft](https://registry.terraform.io/providers/opper-ai/opper/latest/docs/resources/dynamic_route), [live deployment](https://registry.terraform.io/providers/opper-ai/opper/latest/docs/resources/dynamic_route_deployment) |
| Custom models | [BYOK custom model](https://registry.terraform.io/providers/opper-ai/opper/latest/docs/resources/custom_model) |
| Roles and assignments | [Custom role](https://registry.terraform.io/providers/opper-ai/opper/latest/docs/resources/custom_role), [existing member's role assignment](https://registry.terraform.io/providers/opper-ai/opper/latest/docs/resources/member_role) |

For each resource, check the [provider reference](https://registry.terraform.io/providers/opper-ai/opper/latest/docs)
for its management-key scopes, import format, and plan requirements.
To manage a project's access policy after creation, import it separately as
an `opper_project_access` resource.

For a larger configuration, see the
[complete example](https://github.com/opper-ai/terraform-provider-opper/tree/v0.3.0/examples/complete).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.