Anthropic's Terraform provider: manage Claude agents and workspaces as code, and the gotchas to know first
Anthropic shipped a Terraform provider in beta on December 3. It manages Managed Agents agents, environments, vaults, skills, memory, and scheduled deployments, plus workspaces and federation rules. Pin the source to anthropics/anthropic, commit the lock file, and plan for deletion protection and system prompts stored in state.
On this page
This guide is built from Anthropic's getting-started page, its behavior reference, the authentication page, and the operations page. We read the docs and the examples in them; we have not applied the provider against a live organization.
What shipped
The December 3 entry in Anthropic's platform release notes says the provider is in beta and manages "Claude Platform resources as code." It installs from the Terraform Registry under the source address anthropics/anthropic. The source code is in anthropics/terraform-provider-anthropic, which also holds the worked examples the docs point to.
Requirements are short: Terraform 1.11 or later, the ant CLI for signing in, and access to Claude Managed Agents if you want the agent resources. Anthropic calls out the source address for a reason. The docs say a provider "runs with access to your Anthropic credentials," so a lookalike under another namespace could read them.
Because it is beta, resource types and arguments can change, and the docs say some backward-incompatible changes can land in a minor version. Commit .terraform.lock.hcl so every machine stays on the same release until you run terraform init -upgrade on purpose.
What it manages, and what destroy does
The resources fall into two groups. Organization resources call the Admin API and cover workspaces, members, service accounts, Workload Identity Federation (WIF) issuers and rules, customer-managed encryption keys, and OpenTelemetry destinations. Managed Agents resources live inside one workspace. The part worth reading twice is what terraform destroy does to each one, because several are permanent.
| Resource | What it is | terraform destroy |
|---|---|---|
anthropic_beta_agent | Model, system prompt, tools, MCP servers, multiagent settings | Archives the agent permanently, with its deployments |
anthropic_beta_environment | Where tools run, including networking rules | Deletes it |
anthropic_beta_vault, anthropic_beta_vault_credential | Secrets for MCP servers | Deletes them |
anthropic_skill | A folder of files published as a skill | Deletes the skill and every version |
anthropic_beta_memory_store, anthropic_beta_memory | Agent memory and its documents | Deletes them |
anthropic_beta_deployment | A scheduled agent run | Archives it permanently, ending the schedule |
anthropic_workspace | A workspace | Archives it and its Developer API keys permanently |
anthropic_service_account, anthropic_federation_rule | CI identities with no stored secret | Archives them permanently |
Sessions are not resources. To run an agent on a schedule, use anthropic_beta_deployment; to start a session yourself, output the agent ID, version, and environment ID and pass them to the SDK. The coding-agent example renders a whole session request body as an output you can print with terraform output -raw session_request.
Developer API keys, invites, and usage reports are not in the provider. For those, the docs say to call the Admin API directly.
A first apply
The minimal configuration is a provider block pinned to your organization, an environment, and an agent. This is trimmed from Anthropic's quickstart example:
terraform {
required_providers {
anthropic = {
source = "anthropics/anthropic"
}
}
}
variable "organization_id" {
type = string
}
provider "anthropic" {
organization_id = var.organization_id
}
resource "anthropic_beta_environment" "sandbox" {
name = "quickstart"
config = {
cloud = {
networking = {
limited = { allow_package_managers = true }
}
}
}
}
resource "anthropic_beta_agent" "assistant" {
name = "quickstart-assistant"
model = { id = "claude-opus-5-5" }
system = "You are a concise, careful assistant."
tools = [{
agent_toolset_20260401 = {
configs = [
{ web_search = { enabled = false } },
{ web_fetch = { enabled = false } },
]
}
}]
}Web search and web fetch are off because limited networking applies to them too. With no allowed_hosts, the docs say they would return nothing, so leaving them on only wastes turns. Then sign in and apply:
ant auth login
export TF_VAR_organization_id="<your org UUID>"
terraform init
terraform plan
terraform apply
terraform plan # should say "No changes"Anthropic asks you to run that second plan and file a bug if it shows changes you didn't make. Every change to an agent publishes a new server-side version, and the version attribute counts up from 1. A session that names only the agent ID gets the latest version; one that also names a version stays put.
How it finds credentials
The provider takes the first credential it finds, in this order:
profile,api_key, orauth_tokenin the provider blockANTHROPIC_API_KEYANTHROPIC_AUTH_TOKEN- The profile named by
ANTHROPIC_PROFILE - The WIF environment variables
- The active
antprofile
The trap is the second and third steps. If your shell or CI job exports ANTHROPIC_API_KEY for some other tool, it beats your login or federation profile, and the docs say the provider prints no warning. Either unset it or set profile in the provider block, which makes the block ignore everything else in the environment. Don't put a key in the block itself, because it ends up in plan files.
The organization_id pin is a safety check. Before any plan, the provider confirms the credential belongs to that organization and refuses to continue if it doesn't. An optional workspace_id does the same for the workspace, but it only checks: the credential decides which workspace you act in.
| Resources | WIF profile | ant login | Workspace API key | Admin API key |
|---|---|---|---|---|
| Managed Agents | Rule with workspace:developer | Default scopes | Yes | No |
| Workspaces, members, keys, telemetry | Rule with org:admin | --scope org:admin | No | Yes |
| Service accounts and federation | Rule with org:admin | --scope org:admin | No | No |
A login acts with your own role. Creating or changing agents, environments, vaults, or deployments needs at least a developer role; with a user or billing role you can read them but the API refuses changes. Skills need a developer role even to read.
Running it from CI
For pipelines, Anthropic says to use Workload Identity Federation: the job swaps its OIDC token for a short-lived access token that acts as a service account, so nothing long-lived sits in your CI secrets. The team workspace example creates a workspace, a service account with workspace_developer, a GitHub Actions issuer, and a rule that matches on repository_id, repository_owner_id, ref, and event_name.
Three details from the docs will save a failed run:
- Use a profile file on GitHub Actions, not the WIF environment variables.
terraform applyconnects twice, and by default the API accepts a GitHub Actions identity token only once. The profile saves the access token for the second connection. - Match on IDs, not names. A repository name can be reused after a rename or delete;
repository_idcan't. On shared issuers, a rule that doesn't name your own repo or org would accept every customer's tokens. - The API can only create rules with
workspace:developerorworkspace:inference. Anorg:adminrule has to be made in the Claude Console, so a CI rule that Terraform creates can manage agents but not workspaces.
That last point leads to a structural limit. One apply can't create a workspace and then put agents in it, because the provider authenticates before it plans and the credential picks the workspace. Anthropic's answer is two configurations: an admin one that creates the workspace and its federation rule, and a team one that runs with a credential for that workspace.
Deletion protection, state, and drift
Deletion protection is on by default. Agents, environments, skills, workspaces, service accounts, and federation rules are among the resources with deletion_protection, defaulting to true, including for imported resources. The provider reads it from state, so one apply can't both turn it off and destroy the resource. It also survives deleting the resource block, which lifecycle { prevent_destroy = true } does not.
The sharp edge is forced replacement. Renaming a skill's display_name or the name in its SKILL.md replaces it, deleting every version. If you force a replacement with -replace, replace_triggered_by, or a tainted resource, Terraform doesn't tell the provider, so the plan passes and the apply fails, possibly after destroying things that depend on the protected resource. Turn protection off in its own apply first.
State holds your prompts. For Managed Agents, state stores system prompts, custom tool schemas, memory content, and skill files given as inline content. Files given as source store only a hash.
Vault secrets are write-only (token_wo, secret_value_wo) and never reach state; bump the matching _wo_version to rotate. Treat saved plans and CI plan artifacts as secrets, and declare the variables that feed write-only arguments with ephemeral = true.
Agents edit memory. If Terraform owns a memory document's content, the next apply overwrites whatever agents wrote during sessions. For documents agents own, add lifecycle { ignore_changes = [content] }.
Failed creates aren't retried. After a server error or dropped connection, the provider skips the retry to avoid duplicates, so the object may exist without being in state. Check, then import it, or the next apply can create a second copy. Run terraform plan and terraform plan -refresh-only on a schedule to catch drift such as a federation rule someone enabled in another workspace.
Coverage on AWS, Google Cloud, and Bedrock
Set platform in the provider block to target a cloud. Coverage differs, and the Bedrock subset is small:
| Platform | Provider block | Agent resources | Notable gaps |
|---|---|---|---|
| Claude API | organization_id | All | None |
| Claude Platform on AWS | platform = "aws", region, account, workspace | Agents, environments, vaults, skills, memory | No deployments, service accounts, or federation |
| Claude Models on Google Cloud | platform = "google_cloud", project, workspace | All, including deployments | No workspace or federation resources |
| Managed Agents on Bedrock | platform = "bedrock", region, account, project | anthropic_beta_bedrock_agent, memory stores, memories | No environments, vaults, skills, or deployments |
On Bedrock, workspace_id names a Bedrock project (default or a proj_ ID), and the provider doesn't create IAM roles or projects. It refuses to run if AWS_BEARER_TOKEN_BEDROCK is set, because Managed Agents doesn't accept Bedrock API keys. That matches what we covered in our Bedrock Managed Agents guide: fewer features there, and you own the IAM setup.
Verdict
If you run more than one Managed Agents agent, or more than one team shares an organization, this is the right way to manage them. Agent definitions get code review, versions are tracked, and the CI identity needs no stored key. The design choices, such as default deletion protection, the organization pin, and write-only secrets, lean toward not losing things.
Wait, or keep it to a sandbox workspace, if you can't tolerate beta churn in resource schemas, or if your agents live mostly on Bedrock, where only agents and memory are covered. Either way, do three things on day one: pin anthropics/anthropic and commit the lock file, unset ANTHROPIC_API_KEY in the job, and put state in an encrypted remote backend, because it holds every system prompt you manage.
Sources
Researched and drafted by an AI agent from the linked sources. How posts are made.