Claude Platform Docs
SDK、CLI 與程式庫Terraform 供應商

Terraform 提供者

安裝 Anthropic Terraform 提供者、登入,並套用第一個設定。

Anthropic Terraform「provider」(提供者)以程式碼管理 Claude Platform 資源。對這些資源的變更會與您的其他基礎架構經過相同的審查、計畫與套用工作流程。

需求

新增提供者區塊

terraform init 會從 Terraform Registry 安裝提供者。

在空目錄中,建立包含一個 terraform 區塊和一個提供者區塊的 main.tf:

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

variable "organization_id" {
  type = string
}

# 將此設定固定於單一組織。每個 plan 都會驗證
# 憑證是否屬於該組織,否則將拒絕繼續執行。
provider "anthropic" {
  organization_id = var.organization_id
}

anthropics/anthropic 是此提供者唯一的官方來源位址。提供者執行時可存取您的 Anthropic 憑證,而從任何其他位址安裝的提供者可能會讀取這些憑證。

新增環境與代理

將這些區塊加入 main.tf。

這個範例是以提供者儲存庫中 managed-agents/quickstart 範例為基礎。它會建立一個具有受限網路的環境、一個關閉網頁搜尋與網頁擷取的代理,以及工作階段所需 ID 的輸出:

# 代理程式工具的執行位置:一個隔離的雲端容器。受限網路(允許
# 套件管理器)使其只能連線至套件登錄庫
# 與程式碼託管服務。
resource "anthropic_beta_environment" "sandbox" {
  name        = "quickstart"
  description = "Cloud sandbox for the quickstart agent."

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

# 代理程式結合了模型、系統提示與工具。每次變更
# 都會在伺服器端發布新版本,並匯出 `version` 以供
# 版本固定。
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."

  # 環境的受限網路同樣適用於網頁搜尋與網頁
  # 擷取。若未設定 `allowed_hosts`,它們不會傳回任何頁面或
  # 搜尋結果,因此已將其關閉。
  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
}

登入並套用

在終端機中,使用 ant auth login 登入。此命令會將您的登入儲存在設定檔中,設定檔是一個具名的組態檔。提供者會使用該設定檔。如果您的 shell 匯出了 ANTHROPIC_API_KEY 或 ANTHROPIC_AUTH_TOKEN,請使用 unset 從您的 shell 中移除該變數。任一變數都會覆寫登入,如查找順序所示。

請在 Claude Console 的組織設定頁面或 ant auth status 的輸出中找到您的組織 ID。

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

terraform init
terraform plan
terraform apply

確認沒有變更

套用之後,請再執行一次 terraform plan。它應該會回報 No changes。如果它提出了您未進行的變更,請將其回報為錯誤。

清理

「Deletion protection」(刪除保護)預設為開啟,因此在您將其關閉之前,terraform destroy 會以錯誤停止。若要移除您所建立的內容:

  1. 將 deletion_protection = false 加入兩個資源區塊,然後執行 terraform apply。
  2. 執行 terraform destroy。這會刪除環境並封存代理。

其他資源

這個頁面有幫助嗎?