Terraform provider
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.
Requirements
- Terraform 1.11 or later
- The
antCLI - For Managed Agents resources, an organization with access to Claude Managed Agents
Add the provider block
terraform init installs the provider from the Terraform Registry.
In an empty directory, create main.tf with a terraform block and a provider block:
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 example in the provider’s repository. It creates an environment with limited networking, an agent with web search and web fetch turned off, and outputs for the IDs that a session needs:
# 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 shows.
Find your organization ID on the Organization settings page in the Claude Console, or in the output of ant auth status.
ant auth login
export TF_VAR_organization_id="00000000-0000-0000-0000-000000000000"
terraform init
terraform plan
terraform applyCheck 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.
Clean up
Deletion protection is on by default, so terraform destroy stops with an error until you turn it off. To remove what you created:
- Add
deletion_protection = falseto both resource blocks, and runterraform apply. - Run
terraform destroy. This deletes the environment and archives the agent.
Additional resources
- Authenticate the Terraform provider: pipelines, terminals, and several identities
- Example: a team’s workspace and CI identity: organization resources, and the sign-in that they need
- Organization resources: each resource, and what destroy does to it
- Managed Agents resources: each resource, and the Managed Agents pages that show it in Terraform
- Operate the Terraform provider: tasks after the first apply, such as imports, safe state, and logs
- How the Terraform provider behaves: credentials, what destroy does, and what state holds
- GitHub repository
- Terraform Registry
Was this page helpful?