Article

Run Claude Terraform on GitHub Actions without API keys

For teams deploying Claude agents, check GitHub identity setup, workspace pins, imports and state protection before the first Terraform apply.

Editorial illustration for Run Claude Terraform on GitHub Actions without API keys: a document and lock represent artifact protection. Not documentary evidence.

Anthropic released its first official Terraform public beta on December 3, 2026, giving platform teams a way to manage Claude infrastructure through reviewed configuration files. To run it on GitHub Actions without a stored API key, use a named federation profile, restrict which workflows can authenticate, and check the intended organization and workspace in the provider block. Import existing resources before asking Terraform to manage them.

The provider configures workspaces, service identities and persistent Claude Managed Agents resources; it is not a tool for asking Claude to write Terraform. This checklist covers the direct Claude API, not an interchangeable setup for Amazon Bedrock or other cloud platforms. Teams managing OpenAI alongside Claude can use the separate OpenAI Terraform governance guide; its provider-specific instructions do not transfer here.

Create the workspace and deployment identity first

Follow the current quickstart requirements: Terraform 1.11 or later, the ant command-line tool, and an organization with Managed Agents access if you will manage agent resources. The v0.1.0 README allows Terraform 1.0+ for basic use, but write-only secrets need 1.11+. Use 1.11+ for this path; confirm access in the actual organization rather than assuming a Claude chat subscription provides it.

Bootstrap with an organization administrator before configuring the routine deployment job. Anthropic documents ant auth login --profile admin --scope org:admin for this step. Its workspace and CI identity example creates the workspace, service account, workspace membership, GitHub issuer and federation rule. The later deployment identity uses workspace:developer, not organization-administrator privileges. An Admin API key is not a substitute for the org:admin token required by the service-account and federation endpoints.

Use two configurations when the workspace is new. Authentication happens before planning, so one apply cannot both create a workspace and authenticate into it to manage its agents. Keep the administrator configuration separate and omit workspace_id from its organization-level provider block. If the GitHub issuer or other resources already exist, import them instead of creating another copy.

Give the GitHub job a narrowly matched identity

Workload Identity Federation exchanges GitHub’s short-lived proof of a workflow’s identity for an Anthropic access token. For a trusted push-to-main deployment, the version-pinned federation example matches the numeric repository_id and repository_owner_id, plus ref = "refs/heads/main" and event_name = "push". A branch check alone does not identify the event. Match your actual authorized trigger; do not loosen the rule simply to make a different run pass.

  • Grant the trusted job id-token: write to request its GitHub identity token, and contents: read for repository access. These permissions do not themselves grant Anthropic administrative access.

  • Request the token with audience https://api.anthropic.com and write the returned JWT to a private, job-local file. Anthropic’s GitHub Actions guide shows both the runner request URL and the JavaScript core.getIDToken method.

  • Do not run untrusted pull-request code with the deployment identity. Keep the federation rule scoped to the intended workspace and keep the token file out of logs, caches and uploaded artifacts.

For Terraform, do not stop at the generic federation environment-variable example. Anthropic’s Terraform authentication guide says an apply connects for planning and again for applying. Anthropic accepts a GitHub identity token only once by default; a federation profile saves the resulting Anthropic access token so those connections can reuse it.

Save a profile named ci at <ANTHROPIC_CONFIG_DIR>/configs/ci.json, or ~/.config/anthropic/configs/ci.json on Linux without an override. This documented profile structure is an illustrative configuration fragment, not a complete workflow. Replace every placeholder and use an actual absolute token-file path; JSON does not expand shell variables.

{
  "version": "1.0",
  "authentication": {
    "type": "oidc_federation",
    "federation_rule_id": "fdrl_REPLACE",
    "service_account_id": "svac_REPLACE",
    "identity_token": {
      "source": "file",
      "path": "/absolute/job-local/path/github-oidc.jwt"
    }
  },
  "organization_id": "REPLACE_WITH_ORGANIZATION_UUID",
  "workspace_id": "wrkspc_REPLACE",
  "base_url": "https://api.anthropic.com"
}

The profile configuration is non-secret, but its separate credentials/ci.json cache contains a secret access token. Keep that cache within the job rather than transferring it as a build artifact. A new job, an expired token or a long approval delay may require a fresh GitHub assertion; the saved assertion is not a permanent renewal credential. The profile file reference distinguishes configuration from cached credentials.

Make the provider check the target workspace

Set profile = "ci" explicitly in the provider block. Selecting only ANTHROPIC_PROFILE is weaker: an inherited ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN takes precedence. Remove obsolete credential variables from the job. The provider reference also forbids combining profile with provider-block api_key, auth_token or base_url.

Use this fragment in the workspace configuration after bootstrap, with the two ID variables supplied. The exact 0.1.0 pin is a conservative pilot choice, not a universal requirement. Commit .terraform.lock.hcl and review upgrades deliberately: the provider is beta and configuration-breaking changes remain possible.

terraform {
  required_version = ">= 1.11.0"
  required_providers {
    anthropic = {
      source  = "anthropics/anthropic"
      version = "= 0.1.0"
    }
  }
}

variable "organization_id" {
  type = string
}

variable "workspace_id" {
  type = string
}

provider "anthropic" {
  organization_id = var.organization_id
  workspace_id    = var.workspace_id
  profile         = "ci"
}

On the direct API, the workspace pin checks rather than selects the workspace. The credential determines where changes happen. If the check fails, fix the profile or credential instead of removing the check. Organization and workspace IDs inside the profile do not replace the provider-block checks.

With the approved state backend configured, run terraform init and terraform plan. The plan previews intended changes; inspect every creation, update, replacement and deletion before approving an apply. These fragments do not configure backend authentication, install the tools or define the agent resources.

Import existing objects before the first apply

Use each resource’s documented import ID. For an existing workspace, add an import block in the administrator configuration and run terraform plan -generate-config-out=generated.tf. Anthropic’s import instructions explain the omissions: secrets and skill files cannot be imported, and sensitive URLs are generated as null. Restore the appropriate write-only inputs, files and URLs from your authoritative configuration, then review another plan before completing the import.

Import is therefore a transfer of management, not a complete backup. The same distinction matters after an interrupted apply or a dropped connection during creation. The provider avoids retrying most creates; the remote object may exist even though state does not record it. Check for the object and import it if present before reapplying, or the next attempt can create a duplicate or fail.

Protect state even when there is no permanent API key

Keyless authentication does not make Terraform’s records harmless. Prompts, tool schemas, memory content and inline skill files can remain in state or saved plans. Follow Anthropic’s state-handling guidance: use an encrypted, versioned, access-controlled and access-logged remote backend with locking; never commit state files; and restrict access to saved plans and CI artifacts.

For variables feeding write-only _wo arguments, use ephemeral = true. sensitive = true alone hides displayed values but does not remove them from storage, as HashiCorp’s sensitive-data guide explains. Follow the resource’s companion _wo_version requirement when rotating a write-only value.

Do not treat deletion protection as a rollback system. It is on by default for supported types, including imports, and disabling it needs a separate apply. Anthropic warns that forced replacements can destroy dependent resources before failing. Some resources are permanently archived rather than reversibly switched off.

Nor is a normal no-change plan a full access audit. If someone enables a federation rule in another workspace, refresh-only planning can reveal that addition before a later apply absorbs it into state. Review terraform plan -refresh-only as well as the normal plan when checking for changes made outside Terraform.

Budget for sessions separately from provisioning

The provider’s Apache-2.0 source licence (with file-level exceptions) does not make hosted Claude usage free. Anthropic’s current direct-API pricing lists Managed Agents runtime at $0.08 per running session-hour, alongside token use and applicable tool charges. Idle, rescheduling and terminated time do not accrue runtime charges. These rates do not apply to Amazon Bedrock, where AWS bills sessions.

An illustrative runtime-only budget: 100 sessions running for six minutes each total 10 session-hours, or $0.80 at that rate. This excludes tokens, tools, CI and backend costs, discounts and taxes; it is not a workload quote. For the separate reporting decision, see Claude usage and cost analytics tradeoffs.

A successful apply establishes configuration, not a successful agent task. Sessions are not Terraform resources: use the resulting agent and environment IDs to run a separately approved session check. Start with a bounded workload and spending limit, and verify tool access and the intended result before expanding the deployment.