---
title: Terraform provider
url: https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform
description: Install the Anthropic Terraform provider, sign in, and apply a first configuration.
---

The Anthropic Terraform provider manages Claude Platform resources as code. Changes to them go through the same review, plan, and apply workflow as your other infrastructure.

<Note>
  The Terraform provider is in beta. Resource types and their arguments can change during the beta. [Commit your lock file](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/operations#pin-the-providers-release) to choose when you adopt the changes.
</Note>

## Requirements

* [Terraform 1.11 or later](https://developer.hashicorp.com/terraform/install)
* The [`ant` CLI](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/quickstart#installation)
* For Managed Agents resources, an organization with access to [Claude Managed Agents](https://platform.claude.com/docs/en/managed-agents/overview)

## Add the provider block

`terraform init` installs the provider from the [Terraform Registry](https://registry.terraform.io/providers/anthropics/anthropic/latest/docs).

In an empty directory, create `main.tf` with a `terraform` block and a provider block:

```hcl
terraform {
  required_providers {
    anthropic = {
      source = "anthropics/anthropic"
    }
  }
}

variable "organization_id" {
  type = string
}

# Pins this configuration to one organization. Every plan verifies
# that the credentials belong to it, and refuses to proceed otherwise.
provider "anthropic" {
  organization_id = var.organization_id
}
```

`anthropics/anthropic` is the only official source address for this provider. A provider runs with access to your Anthropic credentials, and one installed from any other address could read them.

## Add an environment and an agent

Add these blocks to `main.tf`.

This example is based on the [`managed-agents/quickstart`](https://github.com/anthropics/terraform-provider-anthropic/tree/main/examples/managed-agents/quickstart) example in the provider’s repository. It creates an environment with [limited networking](https://platform.claude.com/docs/en/managed-agents/environments#networking), an agent with web search and web fetch turned off, and outputs for the IDs that a session needs:

```hcl
# Where the agent's tools run: an isolated cloud container. Limited
# networking with package managers allowed lets it reach package
# registries and code hosts only.
resource "anthropic_beta_environment" "sandbox" {
  name        = "quickstart"
  description = "Cloud sandbox for the quickstart agent."

  config = {
    cloud = {
      networking = {
        limited = {
          allow_package_managers = true
        }
      }
    }
  }
}

# An agent bundles a model, a system prompt, and tools. Every change
# publishes a new server-side version, and `version` is exported for
# pinning.
resource "anthropic_beta_agent" "assistant" {
  name        = "quickstart-assistant"
  description = "General-purpose assistant with the built-in toolset."

  model = {
    id = "claude-opus-5-5"
  }

  system = "You are a concise, careful assistant."

  # The environment's limited networking applies to web search and web
  # fetch too. With no `allowed_hosts`, they would return no pages or
  # search results, so they're turned off.
  tools = [
    {
      agent_toolset_20260401 = {
        configs = [
          { web_search = { enabled = false } },
          { web_fetch = { enabled = false } },
        ]
      }
    },
  ]
}

output "agent_id" {
  value = anthropic_beta_agent.assistant.id
}

output "environment_id" {
  value = anthropic_beta_environment.sandbox.id
}
```

## Sign in and apply

At a terminal, sign in with `ant auth login`. This command saves your login in a profile, which is a named configuration file. The provider uses that profile. If your shell exports `ANTHROPIC_API_KEY` or `ANTHROPIC_AUTH_TOKEN`, remove that variable from your shell with `unset`. Either variable overrides a login, as the [lookup order](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#credential-lookup-order) shows.

Find your organization ID on the [Organization settings](https://platform.claude.com/settings/organization) page in the Claude Console, or in the output of `ant auth status`.

```bash
ant auth login
export TF_VAR_organization_id="00000000-0000-0000-0000-000000000000"

terraform init
terraform plan
terraform apply
```

## Check for no changes

After the apply, run `terraform plan` once more. It should report `No changes`. If it proposes changes that you didn’t make, [report it as a bug](https://github.com/anthropics/terraform-provider-anthropic/issues).

## Clean up

[Deletion protection](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#deletion-protection) is on by default, so `terraform destroy` stops with an error until you turn it off. To remove what you created:

1. Add `deletion_protection = false` to both resource blocks, and run `terraform apply`.
2. Run `terraform destroy`. This deletes the environment and [archives the agent](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#managed-agents-resources).

## Additional resources

* [Authenticate the Terraform provider](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication): pipelines, terminals, and several identities
* [Example: a team’s workspace and CI identity](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication#example-a-teams-workspace-and-ci-identity): organization resources, and the sign-in that they need
* [Organization resources](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#organization-resources): each resource, and what destroy does to it
* [Managed Agents resources](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#managed-agents-resources): each resource, and the Managed Agents pages that show it in Terraform
* [Operate the Terraform provider](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/operations): tasks after the first apply, such as imports, safe state, and logs
* [How the Terraform provider behaves](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior): credentials, what destroy does, and what state holds
* [GitHub repository](https://github.com/anthropics/terraform-provider-anthropic)
* [Terraform Registry](https://registry.terraform.io/providers/anthropics/anthropic/latest/docs)
