Deleting a resource block normally tells Terraform to destroy the thing it describes. With the Anthropic Terraform provider, deleting the block for a Claude Managed Agents environment gets you an error instead, and that one choice tells you how the provider was built. It puts agents, sandbox environments, vaults and their credentials through the same plan and apply loop you already run for cloud infrastructure.
We used it to build a GitHub issue triage agent: a sandbox environment, the agent, a vault with a write-only GitHub token, and a short Python script that starts real sessions against whatever Terraform applied. Then we changed the prompt, edited the agent behind Terraform’s back, imported a resource, rotated the token and tore everything down, so you’ll see what each step really prints. Every command below was run against provider 0.1.0, the first public beta, with both Terraform and OpenTofu in December 2026.
Check which credential each resource needs
The credential decides what the provider can touch, and the wrong one fails late, at plan time, after you have written the configuration. A normal workspace API key manages every Claude Managed Agents resource, which is all this guide needs. Workspaces and their members need an Admin API key or an ant CLI login with the org:admin scope. Service accounts and federation rules refuse every API key and accept only an org:admin login or a federation profile whose rule grants that scope. The provider behavior reference spells this out per resource, along with what terraform destroy does to each one:
| Resources | Credential | What destroy does |
|---|---|---|
anthropic_beta_agent | Workspace API key or ant login | Archives the agent and its deployments, permanently |
anthropic_beta_environment | Workspace API key or ant login | Deletes the environment |
anthropic_beta_vault, anthropic_beta_vault_credential | Workspace API key or ant login | Deletes the vault or credential |
anthropic_skill, memory stores, deployments | Workspace API key or ant login | Deletes them; a deployment is archived |
anthropic_workspace, anthropic_workspace_member | Admin API key or org:admin login | Archives the workspace and its keys; removes the member |
| Service accounts, federation issuers and rules | org:admin login or federation profile, no API key | Archives them permanently |
Our lab account had a workspace key and no Admin key, so the organization rows above come from the docs and every Managed Agents row was applied for real. One lookup detail catches people who use the ant CLI: unless the provider block names a profile, an ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN exported in your shell wins over your login. Unset both if you meant to use the login.
Install the Anthropic Terraform provider
Both Terraform and OpenTofu install the provider from their registries with a normal init, so the only real requirement is a recent enough binary. Have these ready before you start:
- Terraform 1.11 or newer, or OpenTofu 1.11 or newer (the vault section uses write-only secrets)
- an API key for a workspace with Claude Managed Agents access
uvfor the session script andjqfor the state checks
If you do not have either binary yet, the Terraform and OpenTofu install guide covers both. Start with an empty project directory.
mkdir -p ~/issue-triage && cd ~/issue-triage
Create the file that pins the provider and configures it.
vim versions.tf
The ~> 0.1 constraint matters while the provider is in beta, because Anthropic says some backward-incompatible changes can ship in a minor release. It keeps you on 0.1.x until you choose to move:
terraform {
required_version = ">= 1.11"
required_providers {
anthropic = {
source = "anthropics/anthropic"
version = "~> 0.1"
}
}
}
provider "anthropic" {
organization_id = var.organization_id
}
Initialize the directory so Terraform downloads the provider.
terraform init
Terraform checks the download against Anthropic’s own signing key and labels the result self-signed, which means the key is the developer’s and HashiCorp vouches for nothing beyond that:
Initializing provider plugins...
- Finding anthropics/anthropic versions matching "~> 0.1"...
- Installing anthropics/anthropic v0.1.0...
- Installed anthropics/anthropic v0.1.0 (self-signed, key ID A229288ECF8B0305)
Partner and community providers are signed by their developers.
Running tofu init against the same files also works, but OpenTofu’s registry had no signing key for the provider on launch day, so it skipped the check:
- Installed anthropics/anthropic v0.1.0. Signature validation was skipped due to the registry not containing GPG keys for this provider
We ran the full walkthrough on both tools, and everything after init behaved the same: same plans, same organization error, same import, vault and destroy flow. The differences sit in how the binary reaches you, so pick one tool per directory and stay with it:
| Terraform | OpenTofu | |
|---|---|---|
| Registry address | registry.terraform.io/anthropics/anthropic | registry.opentofu.org/anthropics/anthropic |
| Signature check at launch | Passed, developer key A229288ECF8B0305 | Skipped, no GPG key in the registry |
Write-only secrets (_wo arguments) | 1.11 and newer | 1.11 and newer (we ran 1.13) |
A provider that holds organization credentials deserves a verified binary, so on OpenTofu we’d commit .terraform.lock.hcl and compare its hashes against a Terraform install until the OpenTofu registry carries the key. Anthropic states that anthropics/anthropic is the only official source address, and a provider from any other address can read your credentials.
Pin the provider to your organization
Every provider block on the Claude API requires organization_id, and the provider refuses to plan if your credential belongs to a different organization. That check is cheap insurance when one engineer holds keys for a staging org and a production org. Declare the variable:
vim variables.tf
Add the organization variable, which every later command reads from terraform.tfvars.
variable "organization_id" {
type = string
description = "Organization UUID from Console > Settings > Organization"
}
Export your API key, then ask the API which organization it belongs to. That saves a trip to the Console:
export ANTHROPIC_API_KEY="your-api-key-here"
curl -s https://api.anthropic.com/v1/organizations/me -H "x-api-key: $ANTHROPIC_API_KEY" -H "anthropic-version: 2023-06-01"
The id field is the value the provider wants:
{"id":"00000000-0000-0000-0000-000000000000","type":"organization","name":"Example Ltd"}
Put it in terraform.tfvars, replacing the zeros with your own ID:
echo 'organization_id = "00000000-0000-0000-0000-000000000000"' > terraform.tfvars
Every plan and apply then prints a warning that names the organization it will change. It reads as noise after the tenth run, but it is the line that tells you which org a CI job is about to touch.
Error: Organization check failed
We pointed the provider at a made-up UUID to see the failure. The plan stops before reading any resource, and the message names both organizations:
Error: Organization check failed
with provider["registry.terraform.io/anthropics/anthropic"],
on versions.tf line 13, in provider "anthropic":
13: organization_id = var.organization_id
the configured credentials belong to organization
00000000-0000-0000-0000-000000000000, but the provider is pinned to
organization_id = 11111111-2222-3333-4444-555555555555; refusing to plan
or apply. Use credentials for that organization or update
organization_id
Either the key or the ID is wrong, so change whichever one is. If you deliberately want to skip the check, set organization_id = "unchecked". The plan then runs, and the provider swaps the pin for a louder warning:
Warning: Organization check disabled
with provider["registry.terraform.io/anthropics/anthropic"],
on versions.tf line 13, in provider "anthropic":
13: organization_id = var.organization_id
organization_id = "unchecked" turns off the organization check, so this run
reads and changes whatever the credentials can reach. Set organization_id to
the organization's UUID to turn the check on.
We would not do that anywhere a plan runs unattended, because the run then changes whatever the credential can reach, in whichever organization the key belongs to.
Define the environment and the agent
A Managed Agents setup needs two resources before any session can run: an environment, which is the sandbox the agent’s tools execute in, and the agent itself, which holds the model, system prompt and tool list. Create the main configuration:
vim main.tf
This is the exact file we applied first. The environment uses limited networking, so the sandbox reaches package registries and the agent’s MCP servers and nothing else. Web search and web fetch are off because limited networking blocks them unless you list hosts in allowed_hosts:
resource "anthropic_beta_environment" "triage" {
name = "issue-triage"
description = "Sandbox for the issue triage agent."
config = {
cloud = {
networking = {
limited = {
allow_package_managers = true
allow_mcp_servers = true
}
}
}
}
}
resource "anthropic_beta_agent" "triage" {
name = "issue-triage"
description = "Labels and summarizes new GitHub issues."
model = {
id = "claude-sonnet-5-5"
effort = "medium"
}
system = <<-EOT
You triage GitHub issues. For each issue, reply with one line:
the issue number, a label (bug, feature, question or docs) and a
one-sentence reason. Never close or edit issues.
EOT
tools = [
{
agent_toolset_20260401 = {
configs = [
{ web_search = { enabled = false } },
{ web_fetch = { enabled = false } },
]
}
},
]
metadata = {
team = "platform"
managed_by = "terraform"
}
}
output "agent_id" {
value = anthropic_beta_agent.triage.id
}
output "agent_version" {
value = anthropic_beta_agent.triage.version
}
output "environment_id" {
value = anthropic_beta_environment.triage.id
}
Triage is short, repetitive work, so Claude Sonnet 5.5 at medium effort is a better fit than Opus. The outputs matter too: a session needs the agent ID and the environment ID, and exporting them from Terraform means no script ever hardcodes one. Review the plan before anything is created.
terraform plan
Two resources to create, and deletion_protection = true shows up on both even though the file never sets it:
# anthropic_beta_agent.triage will be created
+ deletion_protection = true
# anthropic_beta_environment.triage will be created
+ deletion_protection = true
Plan: 2 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ agent_id = (known after apply)
+ agent_version = (known after apply)
+ environment_id = (known after apply)
Apply the plan once it looks right. Both create calls finished in under a second in our runs, so there is no long wait here. Nothing runs yet, because an agent only does work when a session starts against it.
terraform apply
The agent starts at version 1, and the outputs carry the two IDs a session needs:
anthropic_beta_environment.triage: Creating...
anthropic_beta_agent.triage: Creating...
anthropic_beta_agent.triage: Creation complete after 0s [id=agent_017oeUc2skcjuhhf8u2QQV6A]
anthropic_beta_environment.triage: Creation complete after 0s [id=env_01A1dCqoBDKZ1Wrc2k4ALqfC]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
Outputs:
agent_id = "agent_017oeUc2skcjuhhf8u2QQV6A"
agent_version = 1
environment_id = "env_01A1dCqoBDKZ1Wrc2k4ALqfC"
Run terraform plan once more straight after the apply. It should say No changes. Your infrastructure matches the configuration., which it did for us on both tools. A plan that proposes changes you did not make right after an apply is a provider bug, and Anthropic asks for those to be reported on the provider’s GitHub repository.
Start a session against the agent
Terraform creates the agent but never runs it. Sessions are runtime objects, so your application starts them with an SDK or the ant CLI. This script reads the IDs from terraform output, opens a session, sends three sample issues and prints the agent’s reply until the session goes idle:
vim run_session.py
Paste in the script. It reads both IDs from Terraform, passes the vault when one exists and pins an agent version when AGENT_VERSION is set. Tool calls that wait for approval are allowed only when the tool name starts with get_, list_ or search_, so through this script only tools whose names start with those prefixes run, which on the GitHub MCP server are the read tools. Set TF=tofu if you run OpenTofu.
import json
import os
import subprocess
import sys
import anthropic
READ_ONLY = ("get_", "list_", "search_")
tf = os.environ.get("TF", "terraform")
out = json.loads(subprocess.check_output([tf, "output", "-json"]))
client = anthropic.Anthropic()
agent = {"type": "agent", "id": out["agent_id"]["value"]}
if os.environ.get("AGENT_VERSION"):
agent["version"] = int(os.environ["AGENT_VERSION"])
session = client.beta.sessions.create(
agent=agent,
environment_id=out["environment_id"]["value"],
vault_ids=[out["vault_id"]["value"]] if "vault_id" in out else [],
title="triage smoke test",
)
print("session:", session.id)
prompt = sys.argv[1] if len(sys.argv) > 1 else (
"Triage these issues:\n"
"#101 App crashes with KeyError 'region' when config.yaml has no region key\n"
"#102 Please add an ARM64 build to the release page\n"
"#103 README says --dry-run but the flag is --plan-only"
)
calls = {}
with client.beta.sessions.events.stream(session.id) as stream:
client.beta.sessions.events.send(
session.id,
events=[{"type": "user.message", "content": [{"type": "text", "text": prompt}]}],
)
for event in stream:
if event.type == "agent.message":
for block in event.content:
if block.type == "text":
print(block.text)
elif event.type in ("agent.tool_use", "agent.mcp_tool_use"):
calls[event.id] = event.name
print(f"[{event.type}] {event.name} {json.dumps(event.input)}")
elif event.type == "session.status_idle":
if event.stop_reason.type != "requires_action":
break
answers = []
for event_id in event.stop_reason.event_ids:
allow = calls.get(event_id, "").startswith(READ_ONLY)
print(f"[{'allow' if allow else 'deny'}] {calls.get(event_id)}")
answers.append({
"type": "user.tool_confirmation",
"tool_use_id": event_id,
"result": "allow" if allow else "deny",
})
client.beta.sessions.events.send(session.id, events=answers)
The stream opens before the message is sent so no early event is missed. Run it with uv, which pulls the Anthropic SDK into a throwaway environment.
uv run --with anthropic python run_session.py
The sandbox came up and the agent answered in about 8 seconds, with one line per issue as the system prompt asked:
session: sesn_01KAZNfkmnFvaTF6xiXByrpz
#101 bug: The app crashes with a KeyError when the optional `region` key is missing from config.yaml, so it needs a default or a clear error message.
#102 feature: This asks for a new ARM64 build artifact on the release page, which is a new capability and not a defect.
#103 docs: The README refers to `--dry-run` but the actual flag is `--plan-only`, so the README needs correcting.
All three labels are right, and nothing in the script names a model or a prompt. That split is the point of managing the agent in Terraform: the application only knows an agent ID, and the agent’s behavior lives in reviewed code.
Change the system prompt and publish a new version
Every change to an agent publishes a new version, and the provider updates it in place instead of replacing it, so the agent ID never changes. We added a priority field to the prompt (the context engineering guide covers why short, explicit output contracts like this one hold up). Open main.tf and replace the agent’s system argument with this version:
system = <<-EOT
You triage GitHub issues. For each issue, reply with one line:
the issue number, a label (bug, feature, question or docs), a
priority (P1, P2 or P3) and a one-sentence reason. P1 means users
are blocked. Never close or edit issues.
EOT
Plan the change, and the prompt shows up as a line diff:
terraform plan
Only the changed lines are marked, which makes a prompt change as reviewable in a pull request as any other config edit:
# anthropic_beta_agent.triage will be updated in-place
~ resource "anthropic_beta_agent" "triage" {
id = "agent_017oeUc2skcjuhhf8u2QQV6A"
name = "issue-triage"
~ system = <<-EOT
You triage GitHub issues. For each issue, reply with one line:
- the issue number, a label (bug, feature, question or docs) and a
- one-sentence reason. Never close or edit issues.
+ the issue number, a label (bug, feature, question or docs), a
+ priority (P1, P2 or P3) and a one-sentence reason. P1 means users
+ are blocked. Never close or edit issues.
EOT
~ updated_at = "2026-12-04T09:56:25.976130Z" -> (known after apply)
~ version = 1 -> (known after apply)
# (7 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
After terraform apply, check the version:
terraform output agent_version
It moved to 2, as expected.
2
Running the same script again picked up the new prompt immediately, because a session that names only the agent ID gets the latest version:
#101 bug P2: The app crashes with a KeyError when the optional-looking `region` key is missing from config.yaml. It needs a default value or a clear error message, and users can work around it by adding the key.
#102 feature P3: This asks for an ARM64 build on the release page. It's a new build target, not a defect, and users can build from source in the meantime.
#103 docs P3: The README documents `--dry-run`, but the actual flag is `--plan-only`. The README needs correcting, and nothing is broken.
That is convenient in a lab and risky in production, because an apply moves every new session that names only the agent ID to the new prompt at once. Sessions can name a version as well as an ID, and that is how you stage a prompt change. Scheduled deployments work the other way round: a deployment stays on the version it was created with, unless you set its version to anthropic_beta_agent.triage.version, which makes it follow every apply. Use a literal version number on anything you want held back.
We tested the pin on a fresh agent. A temporary prompt change told it to write its reasons in French and published version 2. A session started with AGENT_VERSION=1 kept the old prompt:
AGENT_VERSION=1 uv run --with anthropic python run_session.py
The pinned session answered in English, as version 1 says (the agent wrote en dashes, shown here as hyphens):
session: sesn_01NFcQF9WU1pLiQ5SD7wt6Sn
I haven't fetched these issues, so this triage is based only on their titles.
#101 bug P1 - The app crashes with a KeyError when `config.yaml` has no `region` key, so affected users can't run it at all.
#102 feature P3 - This asks for an ARM64 build on the release page, which is an enhancement and not a defect.
#103 docs P3 - The README names the flag `--dry-run` but the actual flag is `--plan-only`, so the docs need correcting.
The same script without AGENT_VERSION got version 2 and answered all three issues in French, so the pin, not chance, held the old behavior. Reverting the prompt published version 3, and the pinned session would have stayed on version 1 through all of it.
Catch agent changes made outside Terraform
Someone will edit the agent in the Console eventually. We simulated that through the API: the description changed to “Edited in the Console” and the model moved to Opus 5.5 at high effort, which published version 3. The next plan caught it:
terraform plan
Read both halves of the output, because the first half undersells the drift:
Note: Objects have changed outside of Terraform
Terraform detected the following changes made outside of Terraform since the
last "terraform apply" which may have affected this plan:
# anthropic_beta_agent.triage has changed
~ resource "anthropic_beta_agent" "triage" {
id = "agent_017oeUc2skcjuhhf8u2QQV6A"
name = "issue-triage"
~ version = 2 -> 3
# (9 unchanged attributes hidden)
}
Unless you have made equivalent changes to your configuration, or ignored the
relevant attributes using ignore_changes, the following plan may include
actions to undo or respond to these changes.
─────────────────────────────────────────────────────────────────────────────
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# anthropic_beta_agent.triage will be updated in-place
~ resource "anthropic_beta_agent" "triage" {
~ description = "Edited in the Console" -> "Labels and summarizes new GitHub issues."
id = "agent_017oeUc2skcjuhhf8u2QQV6A"
~ model = {
~ effort = "high" -> "medium"
~ id = "claude-opus-5-5" -> "claude-sonnet-5-5"
~ speed = "standard" -> (known after apply)
}
name = "issue-triage"
~ updated_at = "2026-12-04T09:56:55.667964Z" -> (known after apply)
~ version = 3 -> (known after apply)
# (6 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
The “changed outside” note in provider 0.1.0 shows only the version bump from 2 to 3, so a quick skim suggests nothing changed. The real edits show up in the planned update below it, where Terraform proposes to put Sonnet, medium effort and the original description back. A model swap to Opus is a cost change, so a scheduled terraform plan -detailed-exitcode in CI that alerts on exit code 2 is worth the five minutes to set up. Applying the revert published version 4, because versions only go up: you get a fourth version whose configuration matches the second, never a rollback to version 2. We later tested the exit code on a second agent: a clean plan exited 0, and the same plan after a Console-style edit exited 2.
Import an agent or environment you already have
Teams that built agents by hand before this provider existed can bring them under Terraform with an import block. To test it without a second set of resources, we dropped the environment from state and imported it back:
terraform state rm anthropic_beta_environment.triage
Terraform forgets the environment without touching it in the API:
Removed anthropic_beta_environment.triage
Successfully removed 1 resource instance(s).
Create an import file that maps the existing environment ID to the resource address. An import block shows up in the plan like any other change, so nobody imports the wrong ID without a reviewer seeing it first. It needs Terraform 1.5 or newer, which the 1.11 floor already covers.
vim import.tf
Use your own env_ ID from the Console or from the earlier output:
import {
to = anthropic_beta_environment.triage
id = "env_01A1dCqoBDKZ1Wrc2k4ALqfC"
}
The plan lists the full imported object, including the defaults the API filled in, such as an empty package list and the organization scope:
# anthropic_beta_environment.triage will be imported
resource "anthropic_beta_environment" "triage" {
config = {
cloud = {
networking = {
limited = {
allow_mcp_servers = true
allow_package_managers = true
allowed_hosts = []
}
}
packages = {
apt = []
cargo = []
gem = []
go = []
npm = []
pip = []
type = "packages"
}
}
}
created_at = "2026-12-04T09:56:26.016648Z"
deletion_protection = true
description = "Sandbox for the issue triage agent."
id = "env_01A1dCqoBDKZ1Wrc2k4ALqfC"
name = "issue-triage"
scope = "organization"
updated_at = "2026-12-04T09:56:26.016648Z"
}
Plan: 1 to import, 0 to add, 0 to change, 0 to destroy.
After terraform apply reported 1 imported, we deleted import.tf and the next plan said No changes, so the config and the imported object agreed field for field. Imported resources get deletion_protection = true as well, which means an import can never be the first step toward an accidental delete. For an agent, the import ID is its agent_ ID. We tested the CLI form on a second agent after dropping it from state:
terraform import anthropic_beta_agent.triage agent_01FDNYLQEMyZXbARCoewac6A
The import refreshes the agent from the API before writing it to state:
anthropic_beta_agent.triage: Importing from ID "agent_01FDNYLQEMyZXbARCoewac6A"...
anthropic_beta_agent.triage: Import prepared!
Prepared anthropic_beta_agent for import
anthropic_beta_agent.triage: Refreshing state... [id=agent_01FDNYLQEMyZXbARCoewac6A]
Import successful!
The plan after it said No changes, so the agent’s prompt, model, tools and MCP server all round-tripped through the API without a diff.
Keep MCP tokens out of state with a vault
A triage agent that reads real issues needs the GitHub MCP server and a token for it. Putting the token in the MCP server URL would store it in state, so the provider gives you vaults instead: the agent declares the MCP server, a vault credential holds the token, and the secret goes in through a write-only argument that Terraform never records. Add two variables to variables.tf:
vim variables.tf
Append these below the organization variable. ephemeral = true keeps the token out of saved plan files as well as state:
variable "github_token" {
type = string
sensitive = true
ephemeral = true
}
variable "github_token_version" {
type = number
default = 1
}
Create the vault and its credential in their own file. Keeping them apart from the agent means every line that touches the token sits in one place, so a reviewer knows which diff to read slowly. The output exports the vault ID because sessions, not the agent, decide which vault to use.
vim vault.tf
The API matches a credential to an MCP server by URL alone, so both resources read the same local:
locals {
github_mcp_url = "https://api.githubcopilot.com/mcp/"
}
resource "anthropic_beta_vault" "triage" {
display_name = "issue-triage"
}
resource "anthropic_beta_vault_credential" "github" {
vault_id = anthropic_beta_vault.triage.id
display_name = "GitHub read-only token"
auth = {
static_bearer = {
mcp_server_url = local.github_mcp_url
token_wo = var.github_token
token_wo_version = var.github_token_version
}
}
}
output "vault_id" {
value = anthropic_beta_vault.triage.id
}
Then open main.tf and give the agent the MCP server. Every server has to be referenced by an mcp_toolset entry or the API rejects it, and always_ask makes each GitHub tool call wait for approval. Replace the agent’s tools list with the block below.
mcp_servers = [
{ url = { name = "github", url = local.github_mcp_url } },
]
tools = [
{
mcp_toolset = {
mcp_server_name = "github"
default_config = { permission_policy = "always_ask" }
}
},
{
agent_toolset_20260401 = {
configs = [
{ web_search = { enabled = false } },
{ web_fetch = { enabled = false } },
]
}
},
]
Pass the token through the environment so it never lands in a file or your shell history from a -var flag. A fine-grained token with read access to issues is enough for triage:
read -rs TF_VAR_github_token && export TF_VAR_github_token
terraform plan
The plan hides the URL as sensitive and shows the token only as a write-only attribute:
# anthropic_beta_agent.triage will be updated in-place
# anthropic_beta_vault.triage will be created
# anthropic_beta_vault_credential.github will be created
+ mcp_server_url = (sensitive value)
+ token_wo = (sensitive, write-only attribute)
+ token_wo_version = 1
Plan: 2 to add, 1 to change, 0 to destroy.
Once you’ve run terraform apply, check what state kept for the credential:
terraform state pull | jq '.resources[] | select(.type == "anthropic_beta_vault_credential") | .instances[0].attributes.auth.static_bearer'
The token is null. We also grepped the whole state for the test token string and got zero matches:
{
"mcp_server_url": "https://api.githubcopilot.com/mcp/",
"token_wo": null,
"token_wo_version": 1
}
Because Terraform never stores the token, it cannot tell when you change it. We exported a different token and planned again: No changes. A rotation only reaches the API when token_wo_version changes, so bump the version in the same commit as the new secret:
terraform plan -var github_token_version=2
The version is the only visible change, and the credential is updated in place, not replaced:
# anthropic_beta_vault_credential.github will be updated in-place
~ resource "anthropic_beta_vault_credential" "github" {
~ auth = {
~ static_bearer = {
~ token_wo_version = 1 -> 2
# (2 unchanged attributes hidden)
}
}
id = "vcrd_013DWtradBZxCYq6p6WEnH3f"
~ updated_at = "2026-12-04T09:57:17.385782Z" -> (known after apply)
# (3 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
Apply it with the same -var github_token_version=2 flag, or better, change the default in variables.tf so the next person’s plan does not roll it back.
With a real token in the vault, the agent can read GitHub. We loaded a GitHub token with read -rs, applied, and asked the agent to triage the newest issues in the OpenTofu repository:
uv run --with anthropic python run_session.py "Triage the five most recent open issues in opentofu/opentofu."
Each list_issues call paused for approval under always_ask, and the script allowed both because they are reads. The session took 16 seconds, and again the agent’s en dashes are shown as hyphens:
session: sesn_012NWq8dZknMye1hhFRq4NdA
[agent.mcp_tool_use] list_issues {"direction": "DESC", "fields": ["number", "title", "body", "labels", "created_at"], "orderBy": "CREATED_AT", "owner": "opentofu", "perPage": 5, "repo": "opentofu", "state": "OPEN"}
[allow] list_issues
[agent.mcp_tool_use] list_issues {"direction": "DESC", "fields": ["number", "title", "labels", "created_at"], "orderBy": "CREATED_AT", "owner": "opentofu", "perPage": 5, "repo": "opentofu", "state": "OPEN"}
[allow] list_issues
4908 bug P2 - S3 remote-state reads fail intermittently when `TF_LOG=DEBUG` is set, because the pinned aws-sdk-go-base version corrupts requests and responses. Unsetting debug logging avoids it, and the upstream fix is already released.
4900 feature P3 - This asks for an opt-in cap on live provider plugin processes so large `for_each` provider setups fit in memory. Sharding into several root modules works as a workaround, and the reporter is running a patched build.
4889 bug P2 - `apply -target` panics (a crash) when a root output with a condition reads a multi-instance module call. It needs a narrow configuration, and a normal apply or a different targeting scheme avoids it.
4879 bug P2 - `tofu test` exits 0 and reports success when cleanup can't destroy a run's resources. This hides leaked infrastructure and wrongly passes CI, but it doesn't block users from running tests.
4873 feature P3 - This proposes enabling Immutable Releases in GitHub for the project's own releases. It is a project-hardening improvement and doesn't affect users' ability to use OpenTofu.
Those are five real OpenTofu issues, labelled and prioritized with a reason each, and none of it needed the token outside the vault. It never appeared in the agent or the plan, state records the write-only field as null as the earlier check showed, and the session got it only because run_session.py passed vault_ids. Our test token had wide scopes, including repository deletion, which is why the approval gate in your own code matters more than the prompt’s “Never close or edit issues”. A session that names no vault still runs, but the GitHub tools then have no credential.
Destroy protected agents and environments
Deletion protection defaults to on for agents, environments and vaults, and terraform destroy stops on all three before touching anything:
terraform destroy
The agent’s error is the most useful one, because it explains what you’d lose and both ways out:
Error: Agent is protected from deletion
with anthropic_beta_agent.triage,
on main.tf line 17, in resource "anthropic_beta_agent" "triage":
17: resource "anthropic_beta_agent" "triage" {
This plan destroys the agent, which archives it, and its deletion_protection
is on. Archiving an agent cannot be undone, and it archives every deployment
of the agent, which cannot be undone either. A new agent has a new id and
needs new deployments. Deployments of an agent that lists this one as a
subagent fail their next run.
To let Terraform archive it, set deletion_protection = false, apply that
change, and run the destroy again. To stop managing the agent without
archiving it, remove it from state instead: a `removed` block with `lifecycle
{ destroy = false }`, or `terraform state rm`.
Error: Environment is protected from deletion
We also deleted the environment’s resource block from main.tf, along with the environment_id output that references it (leave the output in and you get a reference error instead). With most providers that is a quiet way to destroy something. Here the plan failed with Error: Environment is protected from deletion, and we put the block back before going on. The provider reads the protection flag from state, not from your config, so removing the block does not remove the guard. That’s stricter than lifecycle { prevent_destroy = true }, which disappears along with the block that declares it.
Tearing down for real takes two applies, and the order matters because the provider reads the flag from state. Keep TF_VAR_github_token exported for both, because the variable has no default and a fresh shell stops to prompt for it:
- Add
deletion_protection = falseto the agent, environment and vault blocks. - Run
terraform applyso state records the change. - Run
terraform destroy.
One apply cannot both turn protection off and destroy, so there is no shortcut. Our first apply flipped the three flags. It also reset the token version to its default of 1 and resent the token to the API, because we didn’t pass -var again. The destroy then removed all four resources in about a second:
anthropic_beta_agent.triage: Destruction complete after 1s
anthropic_beta_vault_credential.github: Destruction complete after 1s
anthropic_beta_vault.triage: Destroying... [id=vlt_011ChgVCREJDE37ou6pVA5x4]
anthropic_beta_environment.triage: Destruction complete after 1s
anthropic_beta_vault.triage: Destruction complete after 0s
Destroy complete! Resources: 4 destroyed.
“Destroyed” means different things per resource. The environment was gone: in an earlier practice run, a GET on a destroyed environment’s ID returned not_found_error. The agent still answers, now archived:
curl -s "https://api.anthropic.com/v1/agents/agent_017oeUc2skcjuhhf8u2QQV6A" -H "x-api-key: $ANTHROPIC_API_KEY" -H "anthropic-version: 2023-06-01" -H "anthropic-beta: managed-agents-2026-04-01" | jq '{id, archived_at, version}'
Archived agents drop out of the agent list but keep their ID and history:
{
"id": "agent_017oeUc2skcjuhhf8u2QQV6A",
"archived_at": "2026-12-04T09:58:39.583670Z",
"version": 5
}
Version 5 came from the MCP server change in the vault section. Flipping deletion_protection published no new version, since that flag lives in Terraform state and never reaches the API.
Stop managing a resource without deleting it
When Terraform should let go of a resource that keeps serving traffic, delete its block and add a removed block instead. Deletion protection doesn’t get in the way, because nothing is destroyed. We tested it on the environment, after deleting its resource block and the environment_id output:
vim removed.tf
The block names the old address and tells Terraform to keep the object:
removed {
from = anthropic_beta_environment.triage
lifecycle {
destroy = false
}
}
The plan marks the environment as no longer managed and destroys nothing:
# anthropic_beta_environment.triage will no longer be managed by Terraform, but will not be destroyed
# (destroy = false is set in the configuration)
. resource "anthropic_beta_environment" "triage" {
id = "env_01PkwaxxGsYHEhowbcmnvYo6"
name = "issue-triage"
# (6 unchanged attributes hidden)
}
Plan: 0 to add, 0 to change, 0 to destroy.
After the apply, a GET on the environment still returned it with archived_at set to null, and an import block brought it back under Terraform for the final teardown.
Lock down state before your team shares it
Everything you configure lands in state as plain text, and for agents that includes things you would rather not leak: system prompts, custom tool schemas, memory documents and every MCP server URL. Treat a Managed Agents state file the way you’d treat one holding database hostnames:
- a remote backend with encryption and locking, never a laptop
terraform.tfstate - secrets only through
_woarguments fed byephemeralvariables - tokens in vault credentials, never inside MCP server URLs
- the provider pinned to
~> 0.1with.terraform.lock.hclcommitted - one workspace-scoped key per workspace, or workload identity federation in CI
Plans leak too. A pull request comment that posts terraform plan output shows the full system prompt diff to anyone who can read the repository, which is fine for a private infra repo and wrong for a public one. If you already run plans from GitHub Actions for infrastructure, give the agent configuration its own state and its own credential, so a compromised pipeline for one stack cannot rewrite the prompts of another. The provider is a better place for agent definitions than a folder of curl calls, and drift detection alone justifies it. Just do not let a 0.1 beta be the first thing in your stack that can archive production agents without a human reading the plan. If you want Claude writing the Terraform rather than being managed by it, that is a different workflow, covered in our Claude Code Terraform guide and the wider look at AI coding agents for DevOps work.