---
title: Terraformプロバイダー
url: https://platform.claude.com/docs/ja/cli-sdks-libraries/sdks/terraform
description: Anthropic Terraformプロバイダーをインストールし、サインインして、最初の構成をapplyします。
---

Anthropic Terraformプロバイダーは、Claude Platformのリソースをコードとして管理します。それらのリソースへの変更は、他のインフラストラクチャと同じレビュー、plan、applyのワークフローを通じて行われます。

<Note>
  Terraformプロバイダーはベータ版です。ベータ期間中、リソースタイプとその引数は変更される可能性があります。[ロックファイルをコミット](https://platform.claude.com/docs/ja/cli-sdks-libraries/sdks/terraform/operations#pin-the-providers-release)して、変更を取り入れるタイミングを選択してください。
</Note>

## 要件

* [Terraform 1.11以降](https://developer.hashicorp.com/terraform/install)
* [`ant` CLI](https://platform.claude.com/docs/ja/cli-sdks-libraries/cli/quickstart#installation)
* Managed Agentsリソースの場合は、[Claude Managed Agents](https://platform.claude.com/docs/ja/managed-agents/overview)にアクセスできる組織

## プロバイダーブロックを追加する

`terraform init`は[Terraform Registry](https://registry.terraform.io/providers/anthropics/anthropic/latest/docs)からプロバイダーをインストールします。

空のディレクトリに、`terraform`ブロックとプロバイダーブロックを含む`main.tf`を作成します。

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

variable "organization_id" {
  type = string
}

# この設定を1つの組織に固定します。すべてのplanで、認証情報が
# その組織に属することを検証し、属さない場合は処理を中止します。
provider "anthropic" {
  organization_id = var.organization_id
}
```

`anthropics/anthropic`は、このプロバイダーの唯一の公式ソースアドレスです。プロバイダーはAnthropicの認証情報にアクセスできる状態で実行されるため、他のアドレスからインストールしたプロバイダーはそれらを読み取れる可能性があります。

## 環境とエージェントを追加する

これらのブロックを`main.tf`に追加します。

この例は、プロバイダーのリポジトリにある[`managed-agents/quickstart`](https://github.com/anthropics/terraform-provider-anthropic/tree/main/examples/managed-agents/quickstart)の例に基づいています。この例では、[制限付きネットワーク](https://platform.claude.com/docs/ja/managed-agents/environments#networking)を持つ環境と、ウェブ検索とウェブフェッチを無効にしたエージェントを作成し、セッションに必要なIDの出力を定義します。

```hcl
# エージェントのツールが実行される場所：分離されたクラウドコンテナです。
# パッケージマネージャーを許可した制限付きネットワークにより、アクセス先は
# パッケージレジストリとコードホストのみに限定されます。
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
}
```

## サインインしてapplyする

ターミナルで、`ant auth login`を使用してサインインします。このコマンドはログインをプロファイル（名前付きの設定ファイル）に保存します。プロバイダーはそのプロファイルを使用します。シェルが`ANTHROPIC_API_KEY`または`ANTHROPIC_AUTH_TOKEN`をエクスポートしている場合は、`unset`を使用してその変数をシェルから削除してください。[検索順序](https://platform.claude.com/docs/ja/cli-sdks-libraries/sdks/terraform/behavior#credential-lookup-order)に示されているとおり、どちらの変数もログインを上書きします。

組織IDは、Claude Consoleの[組織設定](https://platform.claude.com/settings/organization)ページ、または`ant auth status`の出力で確認できます。

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

terraform init
terraform plan
terraform apply
```

## 変更がないことを確認する

apply後に、もう一度`terraform plan`を実行してください。`No changes`と表示されるはずです。自分で行っていない変更が提案された場合は、[バグとして報告してください](https://github.com/anthropics/terraform-provider-anthropic/issues)。

## クリーンアップ

[削除保護](https://platform.claude.com/docs/ja/cli-sdks-libraries/sdks/terraform/behavior#deletion-protection)（deletion protection）はデフォルトで有効になっているため、無効にするまで`terraform destroy`はエラーで停止します。作成したものを削除するには、次の手順を実行します。

1. 両方のリソースブロックに`deletion_protection = false`を追加し、`terraform apply`を実行します。
2. `terraform destroy`を実行します。これにより、環境が削除され、[エージェントがアーカイブされます](https://platform.claude.com/docs/ja/cli-sdks-libraries/sdks/terraform/behavior#managed-agents-resources)。

## その他のリソース

* [Terraformプロバイダーを認証する](https://platform.claude.com/docs/ja/cli-sdks-libraries/sdks/terraform/authentication)：パイプライン、ターミナル、および複数のID
* [例：チームのワークスペースとCI ID](https://platform.claude.com/docs/ja/cli-sdks-libraries/sdks/terraform/authentication#example-a-teams-workspace-and-ci-identity)：組織リソースと、それらに必要なサインイン
* [組織リソース](https://platform.claude.com/docs/ja/cli-sdks-libraries/sdks/terraform/behavior#organization-resources)：各リソースと、destroyがそれに対して行うこと
* [Managed Agentsリソース](https://platform.claude.com/docs/ja/cli-sdks-libraries/sdks/terraform/behavior#managed-agents-resources)：各リソースと、それをTerraformで示すManaged Agentsのページ
* [Terraformプロバイダーを運用する](https://platform.claude.com/docs/ja/cli-sdks-libraries/sdks/terraform/operations)：インポート、stateの安全な管理、ログなど、最初のapply後のタスク
* [Terraformプロバイダーの動作](https://platform.claude.com/docs/ja/cli-sdks-libraries/sdks/terraform/behavior)：認証情報、destroyの動作、およびstateに保存される内容
* [GitHub リポジトリ](https://github.com/anthropics/terraform-provider-anthropic)
* [Terraform Registry](https://registry.terraform.io/providers/anthropics/anthropic/latest/docs)
