One read of Claude Developer Platformapi-20261203T193723Z
18 pages moved out of 997 read.
What this read moved
1-18 of 18build-with-claude/message-threads Changed · +13 / -1 lines
### How long a thread lasts
cli-sdks-libraries/sdks/terraform New page · 144 lines, new page
## Requirements ## Add the provider block ## Add an environment and an agent ## Sign in and apply ## Check for no changes ## Clean up ## Additional resources
A whole new page. There's nothing to diff it against, so here is what it says.
---
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)
cli-sdks-libraries/sdks/terraform/authentication New page · 257 lines, new page
## Run Terraform from a pipeline ## Run Terraform at a terminal ## Pin the provider to one credential ## Organization credentials ### Example: a team’s workspace and CI identity ### Manage organization and workspace resources together ## Use a workspace that Terraform creates ## Multiple identities ## Pin a federation rule to its workload ## Cloud platforms ### Claude Platform on AWS ### Claude Models on Google Cloud (Anthropic managed) ### Claude Managed Agents on Amazon Bedrock
A whole new page. There's nothing to diff it against, so here is what it says.
---
title: Authenticate the Terraform provider
url: https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication
description: Give the Terraform provider a credential in a pipeline or at a terminal, and use more than one identity.
---
Before you set up a credential, check [Credentials for each resource](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#credentials-for-each-resource) for the scope that your resources need. Use [Workload Identity Federation](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation) for pipelines and other automation. Use an `ant auth login` profile when you run Terraform yourself at a terminal. Provider blocks and credentials on this page are for the Claude API except for those in the [Cloud platforms](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication#cloud-platforms) section.
## Run Terraform from a pipeline
1. [Set up federation](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation#set-up-federation) to create a service account, an issuer, and a rule. To create all three with Terraform instead, first sign in with `ant auth login --profile admin --scope org:admin`. Then apply [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) once at a terminal.
2. In the job, save the workload’s identity token to a file. The guide for your [identity provider](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation#identity-providers) shows where the token comes from.
3. Write a [federation profile](https://platform.claude.com/docs/en/manage-claude/wif-reference#federation-profile-example) that names your rule, service account, organization, and token file. If the rule covers all workspaces or more than one, the profile file’s `workspace_id` setting names the workspace to use. Save it as `configs/<name>.json` in the [configuration directory](https://platform.claude.com/docs/en/manage-claude/wif-reference#configuration-directory).
4. Set `ANTHROPIC_PROFILE` to `<name>`.
If your job or shell exports `ANTHROPIC_API_KEY` or `ANTHROPIC_AUTH_TOKEN`, remove that variable from the job or shell. Unless the provider block sets `profile`, a variable that’s set wins over a profile, and the provider prints no warning.
Use a profile rather than the [federation environment variables](https://platform.claude.com/docs/en/manage-claude/wif-reference#environment-variables), or `terraform apply` fails on GitHub Actions. `terraform apply` connects twice, once to plan and once to apply. By default, the API accepts a GitHub Actions identity token only one time (see [JWT verification](https://platform.claude.com/docs/en/manage-claude/wif-reference#jwt-verification)), so the second connection needs the access token that a profile saves.
## Run Terraform at a terminal
At a terminal, run [`ant auth login`](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/authentication#interactive-login). Each login makes its profile the active one, so the provider finds it with no variable to set. A variable earlier in the [lookup order](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#credential-lookup-order), such as `ANTHROPIC_API_KEY`, wins over a login, so unset it.
If you can use neither federation nor a login, see [Authentication](https://platform.claude.com/docs/en/manage-claude/authentication) for other ways to authenticate.
## Pin the provider to one credential
For the order in which the provider looks for a credential, see [Credential lookup order](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#credential-lookup-order).
To make a configuration always use one profile, set `profile` in the provider block. The block then ignores every other credential in the environment.
Don’t write a key or token in the provider block, because anything you write there also ends up in plan files.
## Organization credentials
On the Claude API, a [Workload Identity Federation profile](https://platform.claude.com/docs/en/manage-claude/wif-reference#profile-configuration-file) can manage the [organization resources](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#organization-resources), within the limits in [Permissions and constraints](https://platform.claude.com/docs/en/manage-claude/wif-admin-api#permissions-and-constraints). The profile’s federation rule must grant the `org:admin` scope, and must target a service account whose `organization_role` is `admin`. `developer`, the default, isn’t enough. Create the `org:admin` rule in the Claude Console, as [Bootstrap a workload to manage WIF](https://platform.claude.com/docs/en/manage-claude/wif-admin-api#bootstrap-a-workload-to-manage-wif) describes.
At a terminal, an organization admin can sign in with `ant auth login --profile admin --scope org:admin` (see [Admin access](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/authentication#admin-access)). That makes `admin` the active profile. To switch back, run `ant profile activate default`.
Don’t keep a long-lived organization admin credential on a shared runner. Provisioners, external data sources, and other providers in the same configuration can read credentials from the environment.
### Example: a team’s workspace and CI identity
This example is based on [`organization/federated-ci`](https://github.com/anthropics/terraform-provider-anthropic/tree/main/examples/organization/federated-ci) in the provider’s repository. It sets up a team: a workspace, a service account with the developer role there, a federation issuer, and a federation rule. The issuer and rule let the team’s GitHub Actions workflows act as the service account, with no stored credential.
Declare and set the variables `github_repository_id` and `github_repository_owner_id` as strings that hold the numeric IDs of the team’s GitHub repository and its owner. To find both IDs, run `gh api repos/example-org/research-agents --jq '.id, .owner.id'`, replacing `example-org/research-agents` with your repository’s full name. The command prints the repository’s ID, then its owner’s.
The example’s resource blocks use the default provider block, so sign in with `ant auth login --profile admin --scope org:admin` before you apply. You need the aliased block from [Manage organization and workspace resources together](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication#manage-organization-and-workspace-resources-together) only if your configuration also manages [Managed Agents resources](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#managed-agents-resources) in a workspace that already exists. For a workspace that Terraform creates, see [Use a workspace that Terraform creates](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication#use-a-workspace-that-terraform-creates).
If your organization already has an issuer for GitHub Actions, don’t create one. Bring it under Terraform as [Import existing resources](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/operations#import-existing-resources) describes, and set `name` to the name that it has. If that issuer backs a rule with the `org:admin` scope, make any later change to the issuer in the Claude Console.
Add these resource blocks to the configuration from [Add the provider block](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform#add-the-provider-block):
```hcl
resource "anthropic_workspace" "research" {
name = "research"
}
resource "anthropic_service_account" "ci" {
name = "research-ci"
description = "Deploys the research team's agents from CI."
# A rename replaces the account, and the API won't archive the old one while
# the federation rule later in this example still targets it.
lifecycle {
create_before_destroy = true
}
}
resource "anthropic_workspace_service_account" "ci" {
workspace_id = anthropic_workspace.research.id
service_account_id = anthropic_service_account.ci.id
workspace_role = "workspace_developer"
}
# GitHub's OIDC issuer. Its signing keys come from OIDC discovery.
resource "anthropic_federation_issuer" "github" {
name = "github-actions"
issuer_url = "https://token.actions.githubusercontent.com"
}
# This rule applies when a push to the repository's main branch starts a
# workflow run. The run exchanges its OIDC token for a short-lived access
# token that acts as the service account in the workspace. The rule matches
# claims, not the token's subject, because GitHub Actions writes the subject
# in more than one format.
resource "anthropic_federation_rule" "deploy" {
name = "research-deploy"
issuer_id = anthropic_federation_issuer.github.id
match = {
claims = {
repository_id = var.github_repository_id
repository_owner_id = var.github_repository_owner_id
ref = "refs/heads/main"
event_name = "push"
}
}
oauth_scope = "workspace:developer"
target = {
service_account = { service_account_id = anthropic_service_account.ci.id }
}
workspace_id = anthropic_workspace.research.id
}
# The workflow authenticates with this rule.
output "federation_rule_id" {
value = anthropic_federation_rule.deploy.id
}
```
A service account is only an identity. What it can do comes from its workspace memberships and from the federation rules that target it. A token gets only what both the rule’s `oauth_scope` and the service account’s `organization_role` allow. `organization_role` is an optional argument that sets the account’s role in the organization. The example doesn’t set it, so the account gets the default, `developer`. For details, see [Permission boundaries](https://platform.claude.com/docs/en/manage-claude/wif-reference#permission-boundaries).
To run Terraform from the team’s workflow, follow the steps in [Run Terraform from a pipeline](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication#run-terraform-from-a-pipeline). The rule’s scope is `workspace:developer`, so that workflow can manage resources inside the workspace, but not organization resources such as those in this example.
### Manage organization and workspace resources together
Give each provider block only the access it needs. [Credentials for each resource](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#credentials-for-each-resource) shows which credential each resource accepts. To manage organization resources and [Managed Agents resources](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#managed-agents-resources) in one configuration, use two provider blocks:
* The default provider block from [Add the provider block](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform#add-the-provider-block) has no alias. Every resource without a `provider` line uses this block. At a terminal, this block uses the active profile, so make that a workspace login. Run `ant profile activate default`. If you have no profile named `default`, run `ant auth login --profile default` instead.
* A second block has an alias, and its `profile` argument names the organization-level profile. This block can’t set `workspace_id`. Each organization resource or data source names this block in its `provider` line.
This example shows the second block, and a resource that uses it:
```hcl
# The profile from `ant auth login --profile admin --scope org:admin`.
provider "anthropic" {
alias = "admin"
organization_id = var.organization_id
profile = "admin"
}
resource "anthropic_workspace" "research" {
provider = anthropic.admin
name = "research"
}
```
The default block’s Managed Agents resources go in the workspace its credential acts in, which must exist before you plan. For a workspace that Terraform creates, see [Use a workspace that Terraform creates](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication#use-a-workspace-that-terraform-creates).
## Use a workspace that Terraform creates
To manage [Managed Agents resources](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#managed-agents-resources) in a workspace that Terraform creates, use two configurations. One `terraform apply` can’t both create the workspace and manage those resources, because the provider authenticates before it plans, and the credential determines the workspace. The first configuration creates the workspace and a federation rule for it, as [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) does. The second runs with a credential for that workspace.
Set `workspace_id` in the second configuration’s provider block, so that the provider stops if the credential acts in another workspace.
## Multiple identities
To work as more than one identity in a single configuration, give each extra identity its own aliased provider block. A resource then selects a block with `provider`, and a module with `providers`:
```hcl
# Identity 1: whatever the environment provides, such as a federation
# profile in ANTHROPIC_PROFILE or the active `ant auth login` profile.
provider "anthropic" {
organization_id = var.organization_id
}
# Identity 2: the `ant auth login --profile research` profile and
# nothing else, in a different organization.
provider "anthropic" {
alias = "research"
organization_id = var.research_organization_id
profile = "research"
}
module "research" {
source = "./modules/research"
providers = { anthropic = anthropic.research }
}
```
The [`managed-agents/multiple-identities`](https://github.com/anthropics/terraform-provider-anthropic/tree/main/examples/managed-agents/multiple-identities) example in the provider’s repository shows the full pattern, including a module used twice.
After `ant auth login --profile research`, the first block also uses the research profile, unless an environment variable comes earlier in the [lookup order](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#credential-lookup-order). That profile belongs to a different organization, so the provider stops with an error before any plan or apply. To switch back, run `ant profile activate default`.
## Pin a federation rule to its workload
* Match on `claims` that identify the workload, such as the repository, its owner, the branch or environment, and the event that started the run. Prefer claims that hold IDs over names, because someone can reuse a name after a rename or a deletion.
* Some issuers serve many customers, such as the issuer of a hosted CI service. There, every rule must name your own organization, project, or repository on that platform. Otherwise, the rule would accept tokens from every customer of that issuer.
* The API rejects that kind of rule on certain shared issuers, such as GitHub Actions and GitLab.com. Don’t rely on that check for other issuers. On GitHub Actions, use the `repository_id` claim to identify your repository.
* Use a `subject_prefix` if your issuer always writes the subject in the same format. The prefix should name your organization or project, and the branch or environment. Without a trailing `*`, a `subject_prefix` must equal the whole subject.
* Set `audience` only if your workloads mint tokens with a custom audience.
* Prefer `workspace_id` over `applies_to_all_workspaces`, unless the rule must apply to every workspace in the organization.
* Let an issuer find its signing keys through OIDC discovery. Avoid setting inline keys in the issuer’s `jwks` attribute. Inline keys rotate only when you change the configuration.
For how each match field works, see [Rule matching semantics](https://platform.claude.com/docs/en/manage-claude/wif-reference#rule-matching-semantics).
Through the API, a rule’s `oauth_scope` can only be `workspace:developer` or `workspace:inference`. Manage rules with any other scope, such as `org:admin`, in the Claude Console. See [Permissions and constraints](https://platform.claude.com/docs/en/manage-claude/wif-admin-api#permissions-and-constraints).
Set a rule’s `issuer_id` and `target.service_account.service_account_id` by reference, as in `issuer_id = anthropic_federation_issuer.github.id`, not as literal strings. That way, Terraform destroys the rule before the issuer or the service account. The API can’t archive an issuer or a service account while a rule that isn’t archived refers to it.
## Cloud platforms
To manage resources on a cloud platform, set `platform` in the provider block. The [Terraform Registry](https://registry.terraform.io/providers/anthropics/anthropic/latest/docs) lists every argument. For each platform’s resources, see [Resources on each cloud platform](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#resources-on-each-cloud-platform).
### Claude Platform on AWS
Create your first workspace in the AWS Console. To find its ID, see [Obtain your workspace ID](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#obtain-your-workspace-id). Set `aws_region` to the [workspace’s AWS region](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#workspace-scoping).
All of these arguments are required:
```hcl
provider "anthropic" {
platform = "aws"
aws_region = "us-west-2"
aws_account_id = "123456789012"
workspace_id = "wrkspc_01AbCdEf23GhIj"
}
```
The provider signs requests with AWS credentials from the [default AWS credential provider chain](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#sig-v4-authentication), or from the profile in `aws_profile`. It stops unless they belong to the account in `aws_account_id`. The credentials also need the permissions in [IAM policies](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws#iam-policies).
`anthropic_workspace` creates a workspace in the block’s `aws_region`. To use that workspace, apply the resource in one configuration. Then put the workspace’s ID in the provider block of a second configuration.
### Claude Models on Google Cloud (Anthropic managed)
Use the Default Workspace, or [create another workspace](https://platform.claude.com/docs/en/build-with-claude/claude-models-on-google-cloud/anthropic-managed#workspaces) in the Claude Console. To find a workspace’s ID, see [Find your workspace ID](https://platform.claude.com/docs/en/build-with-claude/claude-models-on-google-cloud/anthropic-managed#find-your-workspace-id).
All of these arguments are required:
```hcl
provider "anthropic" {
platform = "google_cloud"
google_cloud_project = "my-project-id"
workspace_id = "wrkspc_01AbCdEf23GhIj"
}
```
The provider authenticates with [Application Default Credentials](https://platform.claude.com/docs/en/build-with-claude/claude-models-on-google-cloud/anthropic-managed#authentication). The account behind them needs an [IAM role](https://platform.claude.com/docs/en/build-with-claude/claude-models-on-google-cloud/anthropic-managed#iam-roles) on the project. `anthropic_external_key` needs `roles/claude.admin`.
### Claude Managed Agents on Amazon Bedrock
To set up your AWS account, see [Claude Managed Agents for Amazon Bedrock](https://platform.claude.com/docs/en/managed-agents/amazon-bedrock#set-up-your-aws-account). Set `aws_region` to one of the [AWS regions where Claude Managed Agents is available](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock#claude-managed-agents-regions).
All of these arguments are required except `workspace_id`:
```hcl
provider "anthropic" {
platform = "bedrock"
aws_region = "us-east-1"
aws_account_id = "123456789012"
workspace_id = "proj_01AbCdEf23GhIj"
}
```
`workspace_id` names the Amazon Bedrock project: `default`, or an ID that starts with `proj_`. It defaults to `default`, and the provider doesn’t check that the project exists. The provider doesn’t create IAM roles or Amazon Bedrock projects.
The provider signs requests with AWS credentials from the default AWS credential provider chain, or from the profile in `aws_profile`. It stops unless they belong to the account in `aws_account_id`. Unset `AWS_BEARER_TOKEN_BEDROCK`: Claude Managed Agents doesn’t accept an Amazon Bedrock API key, so the provider stops if it’s set.
If your AWS account doesn’t have Claude Managed Agents in `aws_region`, a run that reads or deletes a resource stops with `Cannot tell whether the resource exists`. The same happens if the project doesn’t exist. Either way, the resource stays in state. Check `aws_region` and `workspace_id`, and run the command again. Run `terraform state rm` only if the resource is gone.
These arguments aren’t available on this platform:
* `organization_id`
* `profile`
* `api_key`
* `auth_token`
* `base_url`
cli-sdks-libraries/sdks/terraform/behavior New page · 308 lines, new page
## Credential lookup order ## Organization pin ## Workspace pin ## Resources and what `terraform destroy` does ### Organization resources ### Managed Agents resources ## Credentials for each resource ## Resources on each cloud platform ### Claude Platform on AWS ### Claude Models on Google Cloud (Anthropic managed) ### Claude Managed Agents on Amazon Bedrock ## Deletion protection ### Forced replacements ### Service account name clash ## Agent versions ## Multiagent settings ### Entries that name an agent ## Skill files ### Skill versions ## Deployments ### Deployment versions ### Paused deployments ## Changes made outside Terraform ### Federation rules ### Skill versions published elsewhere ### Memory documents that agents edit ### Deleted or archived objects ## State and plan output ### Write-only arguments ### Vault credentials ## Error messages ## Semantic versioning
A whole new page. There's nothing to diff it against, so here is what it says.
---
title: How the Terraform provider behaves
url: https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior
description: "Facts to look up about the Anthropic Terraform provider: where it finds credentials, what destroy does, and what state holds."
---
## Credential lookup order
The provider uses the first credential it finds, in this order:
1. `profile`, `api_key`, or `auth_token` in the provider block.
2. The `ANTHROPIC_API_KEY` environment variable.
3. The `ANTHROPIC_AUTH_TOKEN` environment variable.
4. The profile named by `ANTHROPIC_PROFILE`.
5. The [federation environment variables](https://platform.claude.com/docs/en/manage-claude/wif-reference#environment-variables).
6. The active profile.
## Organization pin
On the Claude API, every provider block requires `organization_id`. The cloud platforms use other arguments, as [Cloud platforms](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication#cloud-platforms) describes. Find the ID on the [Organization settings](https://platform.claude.com/settings/organization) page in the Claude Console, or in the output of `ant auth status`.
Before it plans or applies anything, the provider confirms that its credentials belong to that organization, and stops if they don’t:
```text wrap
the configured credentials belong to organization 11111111-..., but the
provider is pinned to organization_id = 00000000-...; refusing to plan or
apply. Use credentials for that organization or update organization_id
```
The provider reads its `organization_id` and `workspace_id` arguments only from the provider block. The `ANTHROPIC_ORGANIZATION_ID` and `ANTHROPIC_WORKSPACE_ID` [federation environment variables](https://platform.claude.com/docs/en/manage-claude/wif-reference#environment-variables), and a profile file’s settings of the same names, belong to the credential. A profile’s `workspace_id`, for example, names the workspace to sign in to.
## Workspace pin
`workspace_id` is optional on the Claude API, and checks the workspace as well:
```hcl
provider "anthropic" {
organization_id = "00000000-0000-0000-0000-000000000000"
workspace_id = "wrkspc_00000000000000000000000"
}
```
Find the ID under [Workspaces in the Claude Console](https://platform.claude.com/settings/workspaces).
The credential determines which workspace the provider acts in, and `workspace_id` only checks it. If the credential acts in a different workspace, the provider stops with an error.
Which workspace a credential acts in depends on its type and its [OAuth scopes](https://platform.claude.com/docs/en/manage-claude/wif-reference#oauth-scopes):
| Credential | Workspace that it acts in |
| ----- | ----- |
| Federation profile, unless its only scope is `org:admin` | Its rule’s workspace. If the rule covers all workspaces or more than one, the workspace in the profile file’s own `workspace_id` setting, not the provider block’s. |
| Login, unless its only scope is `org:admin` | The workspace that you picked when you signed in. Otherwise, the organization’s default workspace. To use another workspace, see [Switch between workspaces](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/authentication#switch-between-workspaces). |
| Workspace-scoped [Developer API key](https://platform.claude.com/docs/en/manage-claude/api-keys#key-types) | The workspace it’s scoped to. |
| Federation or login token whose only scope is `org:admin` | None. |
| Admin API key | None. |
The last two rows are organization-level credentials. A block that uses one can’t set `workspace_id`. Some [personal keys and service account keys](https://platform.claude.com/docs/en/manage-claude/api-keys#key-types) are scoped to the organization, not to one workspace. The provider treats such a key as an organization-level credential.
A login with only `org:admin` isn’t tied to a workspace. A federation token with only that scope is tied to one, but you can’t pin it with `workspace_id`. For such a token to manage [organization webhooks](https://platform.claude.com/docs/en/manage-claude/organization-webhooks#before-you-begin), that workspace must be your organization’s [default workspace](https://platform.claude.com/docs/en/manage-claude/workspaces#how-workspaces-work). The table’s first row says how a federation token gets its workspace.
## Resources and what `terraform destroy` does
For each resource’s arguments and attributes, see its reference page on the [Terraform Registry](https://registry.terraform.io/providers/anthropics/anthropic/latest/docs). The provider has more resource types than these docs cover, and the Registry lists them all. Some resources have [deletion protection](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#deletion-protection), which is on by default. While it’s on, `terraform destroy` stops with an error instead of doing what the following tables say.
### Organization resources
The organization resources manage your organization’s [workspaces](https://platform.claude.com/docs/en/manage-claude/workspaces) and their members, its [service accounts and federation rules](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation), its [encryption keys](https://platform.claude.com/docs/en/manage-claude/cmek), and its [OpenTelemetry destinations](https://platform.claude.com/docs/en/manage-claude/opentelemetry/api). They call the [Admin API](https://platform.claude.com/docs/en/manage-claude/admin-api). For the rest of the Admin API, such as Developer API keys, invites, and usage reports, call it directly. For a full example, see [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).
| Resource | `terraform destroy` |
| ----- | ----- |
| `anthropic_workspace` | Archives the workspace and its Developer API keys permanently. |
| `anthropic_workspace_member` | Removes the user from the workspace. |
| `anthropic_service_account` | Archives the service account permanently. |
| `anthropic_workspace_service_account` | Removes the service account from the workspace. In the [default workspace](https://platform.claude.com/docs/en/manage-claude/workspaces#how-workspaces-work), destroy only sets the account’s role back to `workspace_user`. |
| `anthropic_federation_issuer` | Archives the issuer permanently. |
| `anthropic_federation_rule` | Archives the rule permanently. |
| `anthropic_federation_rule_workspace` | Disables the rule in that workspace. A rule with `applies_to_all_workspaces` set to `true` stays enabled there, as [Federation rules](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#federation-rules) describes. |
| `anthropic_external_key` | Deletes the key configuration, but only while no workspace, archived or not, uses the key. Attaching the key to a workspace is one-way. To stop managing the key, use a `removed` block with `lifecycle { destroy = false }`. |
| `anthropic_beta_telemetry_destination` | Deletes the destination. |
Use `anthropic_workspace_member` for people with an organization role such as user or developer. Organization admins and billing members already hold a role in every workspace. The API rejects adding them to a workspace or removing them from one.
### Managed Agents resources
These resources set up Claude Managed Agents in the workspace that the provider acts in. You create them once, and they last across sessions. For the concepts, see the [Claude Managed Agents overview](https://platform.claude.com/docs/en/managed-agents/overview).
| Resource | `terraform destroy` | Pages that show it in Terraform |
| ----- | ----- | ----- |
| `anthropic_beta_agent` | Archives the agent permanently, and its deployments with it. | [Define your agent](https://platform.claude.com/docs/en/managed-agents/agent-setup), [Tools](https://platform.claude.com/docs/en/managed-agents/tools), [MCP connector](https://platform.claude.com/docs/en/managed-agents/mcp-connector), [Multiagent orchestration](https://platform.claude.com/docs/en/managed-agents/multiagent-orchestration) |
| `anthropic_beta_environment` | Deletes the environment. | [Cloud environment setup](https://platform.claude.com/docs/en/managed-agents/environments) |
| `anthropic_beta_vault` | Deletes the vault. | [Authenticate with vaults](https://platform.claude.com/docs/en/managed-agents/vaults) |
| `anthropic_beta_vault_credential` | Deletes the credential. | [Authenticate with vaults](https://platform.claude.com/docs/en/managed-agents/vaults) |
| `anthropic_skill` | Deletes the skill and all of its versions. | [Skills](https://platform.claude.com/docs/en/managed-agents/skills) |
| `anthropic_beta_memory_store` | Deletes the store. | [Using agent memory](https://platform.claude.com/docs/en/managed-agents/memory) |
| `anthropic_beta_memory` | Deletes the document. | [Using agent memory](https://platform.claude.com/docs/en/managed-agents/memory) |
| `anthropic_beta_deployment` | Archives the deployment permanently, which ends its schedule. | [Scheduled deployments](https://platform.claude.com/docs/en/managed-agents/scheduled-deployments) |
Each `beta_` type calls a beta API. The provider sends that API’s [beta header](https://platform.claude.com/docs/en/api/beta-headers) on every call.
## Credentials for each resource
This table shows which credentials the resources on this page accept on the Claude API.
| Resources | Federation profile | Login | Workspace-scoped [Developer API key](https://platform.claude.com/docs/en/manage-claude/api-keys#key-types) | [Admin API key](https://platform.claude.com/docs/en/manage-claude/admin-api-keys) |
| ----- | ----- | ----- | ----- | ----- |
| [Managed Agents resources](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#managed-agents-resources) | [Rule with `workspace:developer`](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication#run-terraform-from-a-pipeline). No other scope works. | With the default scopes, as [Run Terraform at a terminal](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication#run-terraform-at-a-terminal) describes.<br />`--scope org:admin` replaces them. | Yes | No |
| [Organization resources](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#organization-resources): workspaces, workspace members, external keys, OpenTelemetry destinations, and organization user data sources | [Rule with `org:admin`](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication#organization-credentials) | [`--scope org:admin`](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication#organization-credentials) | No | Yes |
| [Organization resources](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#organization-resources): service accounts, workspace service accounts, federation issuers, federation rules, and federation rule workspaces | [Rule with `org:admin`](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication#organization-credentials) | [`--scope org:admin`](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication#organization-credentials) | No | No. These endpoints need an `org:admin` token. |
In this table, a token from the [federation environment variables](https://platform.claude.com/docs/en/manage-claude/wif-reference#environment-variables) counts as a federation profile. A token in `ANTHROPIC_AUTH_TOKEN` or the block’s `auth_token` counts as the credential that it came from.
A login acts with your own role. To create, change, or destroy agents, deployments, vaults, vault credentials, or environments, you need at least a developer role. That role can be in the organization or in the workspace that the login acts in, where Workspace Limited Developer also counts. With a lower role, such as user or billing, you can read these resources, but the API refuses those changes. A login needs no developer role for memory stores and memories. For skills, it needs at least a developer role, even to read them. A [personal key](https://platform.claude.com/docs/en/manage-claude/api-keys#key-types) scoped to a workspace is limited by your role too, including on skills and on reading environments.
Some changes need the Claude Console even with `org:admin`, such as managing a federation rule that grants that scope. For the list, see [Permissions and constraints](https://platform.claude.com/docs/en/manage-claude/wif-admin-api#permissions-and-constraints).
If your federation profile or login lacks `org:admin`, the API returns “not found” for service accounts, workspace service accounts, and federation resources. You get the same answer if your login holds `org:admin` but the person it belongs to is no longer an organization admin. An API key gets a clear refusal instead.
If Terraform already manages any of these resources, it can’t tell whether they still exist. `terraform plan`, `terraform apply`, and `terraform destroy` stop with an error such as “Cannot tell whether the resource exists” and keep the resources in state.
To fix the error, give the provider block that manages the resources a credential with `org:admin`, and then run the command again. The credential’s user or service account needs the admin organization role. For instructions, see [Organization credentials](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication#organization-credentials).
A [personal or service account key](https://platform.claude.com/docs/en/manage-claude/api-keys#key-types) scoped to the organization can’t manage Managed Agents resources through the provider. It also can’t manage service accounts, workspace service accounts, or federation resources. To manage workspaces, workspace members, external keys, and OpenTelemetry destinations, its user or service account needs the admin organization role.
## Resources on each cloud platform
On Claude Models on Google Cloud (Anthropic managed) and Claude Platform on AWS, the provider block’s `workspace_id` names the workspace that the provider acts in, in place of `organization_id`. That workspace must exist before you run `terraform plan`. Your cloud’s IAM, not `workspace_id`, determines what your cloud credentials can reach.
### Claude Platform on AWS
Of the resources in the tables under [Resources and what `terraform destroy` does](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#resources-and-what-terraform-destroy-does), you can use these on this platform, and any data sources they have:
* `anthropic_workspace`
* `anthropic_external_key`
* `anthropic_beta_telemetry_destination`
* `anthropic_beta_agent`
* `anthropic_beta_environment`
* `anthropic_beta_vault`
* `anthropic_beta_vault_credential`
* `anthropic_skill`
* `anthropic_beta_memory_store`
* `anthropic_beta_memory`
You can also use these:
* `anthropic_beta_skill`
* `anthropic_compliance_settings`
* The `anthropic_models` data source
### Claude Models on Google Cloud (Anthropic managed)
Of the resources in the tables under [Resources and what `terraform destroy` does](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#resources-and-what-terraform-destroy-does), you can use these on this platform, and any data sources they have:
* `anthropic_external_key`
* `anthropic_beta_agent`
* `anthropic_beta_environment`
* `anthropic_beta_vault`
* `anthropic_beta_vault_credential`
* `anthropic_skill`
* `anthropic_beta_memory_store`
* `anthropic_beta_memory`
* `anthropic_beta_deployment`
You can also use these:
* `anthropic_beta_skill`
* `anthropic_compliance_settings`
* The `anthropic_models` data source
* The `anthropic_rate_limits` data source
* The `anthropic_workspace_rate_limits` data source
* The `anthropic_workspaces` data source
### Claude Managed Agents on Amazon Bedrock
On this platform, you can use these resources and their data sources:
* `anthropic_beta_bedrock_agent`
* `anthropic_beta_bedrock_memory_store`
* `anthropic_beta_bedrock_memory`
Here, `workspace_id` names an Amazon Bedrock project, as [Claude Managed Agents on Amazon Bedrock](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/authentication#claude-managed-agents-on-amazon-bedrock) describes. `terraform destroy` archives an agent permanently and deletes a memory store or a memory. Agents and memory stores have [deletion protection](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#deletion-protection).
## Deletion protection
While `deletion_protection` is on, the provider stops with an error instead of destroying or replacing a resource. If `terraform destroy` or a deleted resource block would destroy a protected resource, the plan fails and nothing is destroyed. Resources such as `anthropic_workspace`, `anthropic_service_account`, `anthropic_federation_rule`, and `anthropic_skill` have this argument, and each one’s page on the [Terraform Registry](https://registry.terraform.io/providers/anthropics/anthropic/latest/docs) shows it. It defaults to `true`, including for a resource that you import or that an earlier provider build created.
The provider reads the setting from state, so one apply can’t both turn protection off and destroy the resource. For the same reason, and unlike `lifecycle { prevent_destroy = true }`, protection still holds after you delete the resource block. For the steps, see [Destroy or replace a protected resource](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/operations#destroy-or-replace-a-protected-resource).
### Forced replacements
Some changes to your configuration replace a resource. While protection is on, a plan that includes such a change fails.
Terraform doesn’t tell the provider when it forces a replacement through `-replace`, `replace_triggered_by`, or a tainted resource. While protection is on, the apply fails even if the plan ran without errors. Before the apply stops, it can destroy resources that depend on the protected resource. To turn protection off first, see [Destroy or replace a protected resource](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/operations#destroy-or-replace-a-protected-resource).
### Service account name clash
In a forced replacement of a service account that has `create_before_destroy`, Terraform creates the new account before it archives the old one. Two service accounts that aren’t archived can’t share a name, so creating the new account fails. Give the new account a different `name` in the apply that replaces the old one. To rename an account, see [Rename a service account](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/operations#rename-a-service-account).
## Agent versions
Every change to an agent publishes a new version. The `version` attribute starts at 1 and increases with each apply that changes the agent. A session that names only the agent’s ID uses the latest version. A session that also names a version stays on that version.
## Multiagent settings
An agent’s `multiagent` argument takes an object whose one key is a dated type name: `multiagent = { multiagent_20261001 = { ... } }`. With the `multiagent_20261001` type, an agent can hand work to subagents, start workflow runs, and consult an advisor model. The type’s settings, `subagents`, `workflows`, and `advisor`, go inside the `multiagent_20261001` object. See [Multiagent orchestration](https://platform.claude.com/docs/en/managed-agents/multiagent-orchestration) for what each setting does.
`subagents.enabled.predefined_agents` lists the agents that the agent can delegate to, and `workflows.enabled.predefined_agents` lists the agents that a workflow can use. Both settings take the same shape: `subagents = { enabled = { predefined_agents = [...] } }`.
To turn a setting off, write `disabled = {}` inside it, as in `workflows = { disabled = {} }`. If you remove `subagents`, `workflows`, or `advisor` from your Terraform configuration, the agent keeps the value that it has.
### Entries that name an agent
An entry that names an agent takes the shape `{ agent = { id = ..., version = ... } }`. Each entry in either list determines which version of its agent runs:
* An entry such as `{ agent = { id = anthropic_beta_agent.researcher.id, version = anthropic_beta_agent.researcher.version } }` tracks the researcher, so an apply that changes the researcher also updates the list.
* An entry with only an `id` gets the agent’s latest version when you first apply the entry. It gets the latest version again whenever the entry’s position in the list changes, as when you add or remove an entry above it. It stays on its version when the agent gets a new one.
* An entry with a literal `version` stays pinned to that version.
A `{ self = {} }` entry lets the agent delegate to copies of itself.
## Skill files
`anthropic_skill` publishes a folder of files as a skill. Each `file` block sets `path`, the file’s path in the skill, and exactly one of these:
* `source`, the path of a file on disk. Binary files work.
* `content`, text written in the configuration.
Every `file` block’s `path` starts with the same top-level folder, and `SKILL.md` sits directly inside it, as in `my-skill/SKILL.md`. The folder’s name must match the `name` in the `SKILL.md` frontmatter.
Changing `display_name` or the `name` in `SKILL.md` replaces the skill, which deletes all of its versions. Turn off [deletion protection](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#deletion-protection) before you make either change.
### Skill versions
Each apply that changes a file publishes a new version, and `latest_version_id` shows the newest one. An agent that lists the skill in its `skills` argument without a `version` uses the latest version.
## Deployments
### Deployment versions
`agent` names the agent and, optionally, its version, as in `agent = { agent = { id = anthropic_beta_agent.reporter.id, version = anthropic_beta_agent.reporter.version } }`. With `version` set this way, an apply that changes the agent also moves the deployment to the new version. Without `version`, the deployment stays on its version when the agent gets a new one.
### Paused deployments
A run of an `anthropic_beta_deployment` can fail in a way that retrying won’t fix, such as when its environment or vault was archived or deleted. The API then pauses the deployment, and Terraform doesn’t resume it. The read-only `status` shows `paused`, with the reason in `paused_reason`. Fix the cause, and then unpause the deployment, as [Managing deployment lifecycle](https://platform.claude.com/docs/en/managed-agents/scheduled-deployments#managing-deployment-lifecycle) describes.
## Changes made outside Terraform
### Federation rules
A rule’s own `workspace_id` enables the rule in one workspace. Each `anthropic_federation_rule_workspace` enables the rule in one more workspace.
While `applies_to_all_workspaces` is `true`, a rule is enabled in every workspace, whatever its `workspace_ids` list holds. Creating or destroying an `anthropic_federation_rule_workspace` then only edits that list, and so do the changes in the following table.
To limit the rule to specific workspaces, set `applies_to_all_workspaces` to `false` and set the rule’s own `workspace_id` in the same apply. The rule is then enabled only in the workspaces on its `workspace_ids` list, which can hold more than the one that you set.
| Change that someone makes outside Terraform | What Terraform does |
| ----- | ----- |
| Someone disables the rule in the workspace that an `anthropic_federation_rule_workspace` names. | The next `terraform plan` shows the change. The next `terraform apply` enables the rule in that workspace again. |
| Someone enables the rule in another workspace. | Terraform does nothing, so the rule stays enabled in that workspace. A plain `terraform plan` reports no changes. `terraform plan -refresh-only` shows the added workspace in the rule’s `workspace_ids` attribute. The next `terraform apply` saves the new list in state, so no later plan shows the change. |
The [Compliance API](https://platform.claude.com/docs/en/manage-claude/compliance-api) records each of these changes and who made it.
### Skill versions published elsewhere
If someone publishes a version of the skill outside Terraform, the next plan shows a “Skill changed outside Terraform” warning. The plan can’t show what changed in the skill’s files. Terraform proposes to publish your declared files as a new version, and the next apply does that. See [Skills](https://platform.claude.com/docs/en/managed-agents/skills).
### Memory documents that agents edit
Because agents edit documents during sessions, a configuration that also manages a document’s content can overwrite their edits. For documents that agents own, add `lifecycle { ignore_changes = [content] }` to their `anthropic_beta_memory` resources. See [Using agent memory](https://platform.claude.com/docs/en/managed-agents/memory).
### Deleted or archived objects
If someone deletes or archives an object outside Terraform, the next plan warns that the object is gone and proposes to create it again. For service accounts, workspace service accounts, and federation resources, a federation profile or login without `org:admin` gets an error instead. See [Credentials for each resource](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#credentials-for-each-resource).
## State and plan output
Terraform stores everything you configure in plain text in its state, and plan output shows the same values, including in pull-request comments and CI logs. Marking a value as sensitive hides it from plan output, but Terraform still stores it in state.
For organization resources, state holds:
* The layout of your workspaces and service accounts
* Your federation issuers and rules
* The identifiers of your encryption keys
* Your OpenTelemetry destinations’ endpoint URLs and header names
* Members’ names, emails, and roles, if you use the `anthropic_organization_user` or `anthropic_organization_users` data source
It holds no secrets, but it shows which people and which service accounts can act in your organization.
For Managed Agents resources, state holds agent system prompts, custom tool schemas, memory content, and skill files written as `content`. For a skill file given as `source`, state stores only its hash. Vault credential secrets and a deployment’s GitHub repository token are the exceptions: they’re write-only arguments.
### Write-only arguments
The secret arguments of an `anthropic_beta_vault_credential`, such as `token_wo` and `secret_value_wo`, are write-only. Terraform sends a write-only value to the API but never stores it in state or plans. Declare the variables that supply these arguments with `ephemeral = true`, as [Keep state and plans safe](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/operations#keep-state-and-plans-safe) explains.
Terraform can’t detect when a write-only value changes, and the API never returns secrets.
Each write-only argument has a companion `_wo_version` argument, such as `token_wo_version`. To send a new value, for example after you rotate a secret, change its `_wo_version`.
### Vault credentials
The API matches a vault credential to an agent’s MCP server by URL alone, so the credential’s `mcp_server_url` must be the same URL as the agent’s `mcp_servers` entry. Where a service supports OAuth, prefer an `mcp_oauth` credential with a refresh token over a long-lived static token.
Cut at 300 lines. The page has the rest.
cli-sdks-libraries/sdks/terraform/operations New page · 109 lines, new page
## Pin the provider’s release ## Use the provider in a module ## Destroy or replace a protected resource ## Refactor without archiving ## Rename a service account ## Attach an encryption key to a workspace ## Import existing resources ## Recover after a failed create ## Keep state and plans safe ## Start a session from Terraform outputs ## Catch changes made outside Terraform ## Turn on logs
A whole new page. There's nothing to diff it against, so here is what it says.
---
title: Operate the Terraform provider
url: https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/operations
description: "Tasks for after the first apply: import existing resources, keep state and plans safe, and turn on logs."
---
## Pin the provider’s release
`terraform init` selects the newest release and records it in `.terraform.lock.hcl`. Commit that file, so that every machine uses the same release until you run `terraform init -upgrade`.
## Use the provider in a module
Any module that uses the provider’s resources or data sources needs `source = "anthropics/anthropic"` in its own `required_providers` block. Without it, Terraform searches for `hashicorp/anthropic`, and `terraform init` fails.
## Destroy or replace a protected resource
To destroy or replace a protected resource, first set `deletion_protection = false` and apply that change on its own.
Then destroy or replace the resource. After a replacement, set `deletion_protection = true` again, and apply. [Deletion protection](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#deletion-protection) explains why turning protection off needs its own apply.
## Refactor without archiving
Change a resource’s address with `moved` blocks, and stop managing one with a `removed` block with `lifecycle { destroy = false }`. Add `lifecycle { prevent_destroy = true }` to anything that a mistaken plan must never archive.
## Rename a service account
A rename replaces a service account. To rename one that a federation rule targets:
1. Add `lifecycle { create_before_destroy = true }` to the service account.
2. Turn off [deletion protection](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#deletion-protection) on the service account, and apply that change on its own.
3. Change the account’s name, and apply.
4. Set `deletion_protection = true` again, and apply.
With `create_before_destroy`, Terraform creates the new account and updates the rule before it archives the old account.
## Attach an encryption key to a workspace
Once you attach a key to a workspace, you can’t detach or replace it.
[Grant Anthropic access to the key](https://platform.claude.com/docs/en/manage-claude/cmek#set-it-up) before you attach it to a workspace. How you attach it depends on the platform that your provider block uses, not on where the key lives:
* On the Claude API, apply the `anthropic_external_key` resource on its own and [validate the key](https://platform.claude.com/docs/en/manage-claude/cmek-admin-api#create-validate-attach). Then set `external_key_id` on the `anthropic_workspace`.
* On Claude Platform on AWS, declare the `anthropic_external_key` resource, and set `external_key_id` on an `anthropic_workspace`. Attaching checks the key, as [Set up CMEK on Claude Platform on AWS](https://platform.claude.com/docs/en/manage-claude/cmek-claude-platform-on-aws#register-the-key-with-anthropic) describes.
* On Claude Models on Google Cloud (Anthropic managed), apply the `anthropic_external_key` resource. Then verify the key and attach it in the Claude Console, as [Set up CMEK with Google Cloud KMS](https://platform.claude.com/docs/en/manage-claude/cmek-google-cloud-kms#register-the-key-with-anthropic) describes.
Once any workspace uses an `anthropic_external_key`, you can’t change that resource’s `provider_config`. To use a different key, create a new workspace with it, as [Change keys or stop using CMEK](https://platform.claude.com/docs/en/manage-claude/cmek-key-lifecycle#change-keys) describes.
## Import existing resources
You can import every resource that [How the Terraform provider behaves](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#resources-and-what-terraform-destroy-does) lists. Each resource’s reference page on the [Terraform Registry](https://registry.terraform.io/providers/anthropics/anthropic/latest/docs) shows its import ID. Add an `import` block, and then generate the resource block:
```hcl
import {
to = anthropic_workspace.research
id = "wrkspc_01AbCdEf23GhIj"
}
```
```bash
terraform plan -generate-config-out=generated.tf
```
The generated configuration is missing some values inside the resources that you import:
* Secrets, which can’t be imported. They go in the write-only arguments of vault credentials and of a deployment’s GitHub repository. Those arguments’ names end in `_wo`.
* Skill files, which can’t be imported. They go in each skill’s `file` blocks.
* URLs, which are sensitive, so the generated configuration leaves them `null`. They go in each agent’s `mcp_servers`, and in vault credentials’ `mcp_server_url` and `token_endpoint`.
Add these values in `generated.tf`.
An imported `anthropic_beta_telemetry_destination` keeps the request headers it sends to your observability platform, such as the platform’s API key. The generated configuration doesn’t have `headers_wo`, because the API never returns the header values. To manage them in Terraform, set `headers_wo` and a new `headers_wo_version` in the same apply.
Then run `terraform plan` to check the result, and run `terraform apply` to finish the import.
## Recover after a failed create
After a server error or a dropped connection, the provider doesn’t retry most creates, to avoid duplicates. After either one, or an interrupted apply, the object might exist but be missing from Terraform state.
Check for the object, and if it exists, import it as [Import existing resources](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/operations#import-existing-resources) describes. If you don’t import it, the next apply can create a duplicate or fail.
## Keep state and plans safe
* Store state in an encrypted, versioned, access-logged, access-controlled remote backend with locking, readable only by the pipeline that applies it. For example, use S3 with a KMS key and least-privilege IAM, GCS with a customer-managed key, or HCP Terraform.
* Never commit `.tfstate` files, and treat saved plans, and any state or plan artifacts in CI, as secrets.
* Declare the variables that supply write-only arguments with `ephemeral = true`, because a saved plan records the value of every variable that isn’t ephemeral.
HashiCorp’s [Manage sensitive data](https://developer.hashicorp.com/terraform/language/manage-sensitive-data) guide covers the rest.
## Start a session from Terraform outputs
Sessions aren’t resources. To start sessions on a schedule, use a [scheduled deployment](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#deployments) instead.
A session needs the agent’s `id` and the `environment_id`. It can also name the agent’s `version`, the `vault_ids`, and any memory stores to mount as `resources`. Output those values from your configuration.
The [`managed-agents/coding-agent`](https://github.com/anthropics/terraform-provider-anthropic/tree/main/examples/managed-agents/coding-agent) example renders the whole request body as a `session_request` output. Run `terraform output -raw session_request` to print a body that you can pass to the SDK’s method for creating a session. See [Start a session](https://platform.claude.com/docs/en/managed-agents/sessions).
## Catch changes made outside Terraform
Run `terraform plan` on a schedule to catch drift. Also run `terraform plan -refresh-only` on the same schedule. That command shows [a federation rule that someone enabled in another workspace](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform/behavior#federation-rules), but only if no `terraform apply` has run since the change.
## Turn on logs
To log every request and response, set `TF_LOG_PROVIDER=DEBUG`:
```bash
TF_LOG_PROVIDER=DEBUG terraform apply 2> provider.log
```
The log redacts API keys, tokens, and every field that the schema marks as sensitive.
manage-claude/opentelemetry/api Changed · +25 / -0 lines
managed-agents/environments Changed · +51 / -0 lines
managed-agents/mcp-connector Changed · +51 / -0 lines
managed-agents/memory Changed · +20 / -0 lines
managed-agents/migration Changed · +11 / -0 lines
models/fable-5-2/migration-guide Changed · +20 / -6 lines
models/haiku-5-5/migration-guide Changed · +18 / -4 lines
models/opus-5-5/migration-guide Changed · +20 / -6 lines
models/sonnet-5-5/migration-guide Changed · +20 / -6 lines
release-notes/overview Changed · +4 / -0 lines
### December 3, 2026