/terraform:terraformfrom terraform
Writes, reviews and runs Terraform, OpenTofu and Terragrunt changes safely, plan-only by default. Use when editing .tf or terragrunt.hcl files, reviewing a plan or pasted plan output (adds, changes, destroy/replace), running plan or apply (also via mise, make or task wrappers), refactoring with moved/import blocks, testing modules, scanning for misconfigurations, or diagnosing a pasted tofu or terragrunt error.
Ships in terraform. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Not for Kubernetes manifests (the kubernetes skill), Helm charts (helm), or AWS service questions (aws-well-architected, aws-resource-query).
This skill was checked against Terraform 1.16 docs (developer.hashicorp.com/terraform), OpenTofu 1.13 docs (opentofu.org/docs), and Terragrunt 1.1 docs (docs.terragrunt.com). The CLI is terraform or tofu; commands below work with both unless a section says otherwise. Find which one the repo uses (a .terraform.lock.hcl from either, CI scripts, a .tofu file, an encryption block) and keep using it. Many repos run it through a wrapper (mise run tofu, make, task, or Terragrunt). Read the wrapper's definition and use it, since it sets the working directory, workspace, and credentials.
init, validate, fmt -check, and plan freely in a repo the user owns and works in. They are not inert: init downloads modules and providers, plan runs provider code and every data "external" program (re-run on each refresh), and wrappers (mise run tofu, make, task) run repo-defined code. In an unfamiliar or freshly cloned repo, first read the wrapper and grep for data "external" and local-exec (the latter runs at apply), and check module and provider sources.apply (including apply -refresh-only, which writes state), destroy, state rm, state mv, state push, state replace-provider, taint, untaint, workspace delete, force-unlock, import (the CLI command), or terraform test with command = apply runs, without an explicit instruction naming the target workspace. These change real infrastructure or state, and state edits are hard to undo. workspace delete -force orphans resources the state still tracks, and state push -force overwrites the remote state.plan -out=tfplan and show the user the diff. Apply only that saved file, so what was reviewed is what runs. A plan file holds sensitive values in plaintext, so add tfplan* and *.tfplan.json to .gitignore, keep them out of commits, and delete them after apply or scan..tfvars contents into replies. They hold secrets in plain text (see the secrets section).-lock=false only for a stated emergency, and say so. Prefer -lock-timeout when another run holds the lock.-target as a scoped last resort (see "Running plans and applies"). It plans a partial graph and hides drift.terraform version, terraform providers, and the terraform {} block.terraform fmt -check -recursive and terraform validate.terraform plan -out=tfplan -detailed-exitcode. Exit 0 means no changes, 1 an error, 2 changes present.Wrapper commands change the spelling, not the rules. Check the wrapper's task definition for how it forwards arguments.
tofu plan -out=<root>.tfplan -lock-timeout=5m
tofu show <root>.tfplan
tofu apply <root>.tfplan -lock-timeout=5m
rm <root>.tfplan
Passing a plan file is the approval, so -auto-approve is ignored. Apply accepts no planning options such as -target or -var with a saved plan, because the file already holds those decisions, so set them at plan time. Ephemeral variables must be passed again on apply. If another apply changed the state after the plan was made, re-plan instead of forcing it.-lock-timeout=<duration> to plan and apply so a run waits for the lock instead of failing at once. It does not clear a stuck lock. Read the holder from the lock error (ID, who, created) before considering force-unlock, which needs explicit instruction.-target as a last resort. Use -target=module.<name> or a resource address when a shared root holds unrelated work in flight, or to apply a dependency the rest needs first. Say so in the report, because drift outside the target is not shown. Follow with an untargeted plan that shows no changes. Never use it to hide an unexpected diff.-auto-approve without a saved plan applies whatever the fresh plan contains. Do not use it on shared roots without instruction.run forms and two recurring errors.destroy and replace (shown as -/+) has a reason the user can state. Replacement of stateful resources (databases, disks, buckets) is a stop sign.moved block, not a new resource (see references/refactoring.md).terraform plan -refresh-only to separate drift from config changes.for_each key shifted.(sensitive value). Check the plan does not force replacement because of them.Follow the standard module structure: main.tf, variables.tf, outputs.tf, versions.tf, a README, modules/ for nested modules, and examples/ for usage.
description. Add a type, and a validation block where a bad value would produce a confusing failure later.providers, and never configure providers inside a reusable module.tags variable merged with defaults, or the provider's default_tags, rather than per-resource literals.Use for_each for any collection where items have identity (subnets, users, buckets). count addresses instances by position, so removing the second of three subnets renumbers the third and plans a destroy and recreate of it. for_each keys instances by map key or set member, so removals touch only that instance.
resource "aws_subnet" "private" {
for_each = var.private_subnets # map: name => { cidr, az }
vpc_id = aws_vpc.main.id
cidr_block = each.value.cidr
availability_zone = each.value.az
}
for_each keys.count for a conditional single resource (count = var.enabled ? 1 : 0) or truly identical copies. OpenTofu 1.11 adds lifecycle { enabled = ... } for the conditional case.count resource to for_each changes every address. Add one moved block per instance in the same change.terraform {
required_version = ">= 1.10, < 2.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.0"
}
}
}
required_version and a version range for every provider. ~> allows only the rightmost component to rise, so patch and minor updates arrive without a breaking major..terraform.lock.hcl. It pins exact provider versions and checksums and makes review of upgrades possible. Upgrade deliberately with init -upgrade and read the diff.providers lock -platform=linux_amd64 -platform=darwin_arm64 so the lock file holds checksums for each.source to a tag or version (version = "~> 5.0" for registry modules, ?ref=v1.2.3 for git). A floating branch makes plans irreproducible.Read references/state-and-backends.md for backend choice, locking, encryption, workspaces, and state surgery. The rules that always apply:
backend block. Supply them through environment variables or a credential file, because values passed via -backend-config or hardcoded are written into .terraform/ and plan files.Terraform stores all resource attributes in state, including passwords and keys the provider returns, and sensitive = true only hides them from CLI output.
*_wo) arguments omit values from state and plan files. They need Terraform 1.10 and 1.11 respectively; check that the provider resource offers a _wo argument before relying on it.references/opentofu.md)..tfvars with secrets. Supply them via TF_VAR_<name> or the CI secret store.Read references/terragrunt.md when the repo has terragrunt.hcl or root.hcl, or the error output mentions Terragrunt, a dependency, or .terragrunt-cache. It covers the CLI forms, dependency outputs and mocks, and the causes of There is no variable named "dependency" and Provider produced inconsistent final plan ... user_data.
Read references/refactoring.md before renaming resources, moving them into modules, importing existing infrastructure, or dropping resources from management. Use declarative blocks (import, moved, removed) in code instead of CLI state commands, so the change is reviewed in a plan and reproducible in every environment.
terraform test (1.6+) runs .tftest.hcl files. A run block defaults to command = apply, which creates real infrastructure. Use command = plan or mock providers (1.7+) for unit-style checks, and say which one you ran.references/terratest.md when the repo tests modules with Go Terratest or the user asks for it.trivy config . reads Terraform sources and saved plans (tfsec is deprecated; its checks live in Trivy). A plan converted with terraform show -json holds plaintext secrets, so delete it after the scan. Scan results are findings for the user, not an instruction to suppress rules.references/security-scanning.md for a security audit, Checkov, OPA/Rego policies on plan JSON, suppression syntax, or a CI scan gate. Pin scanner versions and actions by commit SHA, and avoid options that upload code to a hosted service unless the user opted in.terraform plan -refresh-only shows differences between state and real infrastructure without proposing config changes. Decide per difference whether to revert it (normal plan and apply) or accept it (update the config, or apply -refresh-only after approval). Run it on a schedule in CI with -detailed-exitcode and alert on exit 2.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub adminhead/claude-plugins --plugin terraform