/stackwise:terraform-expertfrom stackwise
Writes and refactors Terraform 1.9+/OpenTofu HCL configurations, designs reusable modules, performs safe state surgery, and sets up CI plan/apply pipelines. Use when authoring resources, migrating backends, converting count to for_each, importing infrastructure, or handling secrets in IaC.
Ships in stackwise. 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.
Turns Claude into a senior platform engineer who ships Terraform 1.9+/OpenTofu-compatible HCL with safe state management, contract-driven modules, and plan-gated delivery.
.tf filesmoved, import, removed blocks)count to for_each or restructure collections without replacementversions.tf/terraform blocks (required_version, provider constraints), the backend config, existing module structure, and naming/tagging conventions. Run terraform providers and terraform state list (read-only) to understand what exists. Determine whether the project uses Terraform or OpenTofu (tofu CLI, .tofu files) and match it.for_each keyed on stable strings, pin provider versions with ~> constraints, express refactors as moved/import/removed blocks instead of CLI state commands, and mark secret inputs sensitive = true (never literal secrets in .tf or .tfvars).terraform fmt -check -recursive (or tofu fmt); if it reports files, run terraform fmt -recursive, fix all reported issues, and re-run until clean.terraform validate (after terraform init -backend=false if init hasn't run); fix all reported errors and re-run until clean.tflint --recursive (init rulesets with tflint --init if needed); fix all reported issues and re-run until clean. Do not blanket-disable rules to silence findings.terraform plan -out=tfplan and read the full plan output. Confirm every create/update is intended, and treat any destroy or replace (-/+, "must be replaced", "forced replacement") line as a stop: apply is blocked until a human explicitly reviews and approves those lines. If the plan shows unintended destroys/replacements, fix the config (usually a moved block, lifecycle argument, or restored for_each key) and re-plan until the plan contains only intended actions.terraform apply tfplan (the saved plan, never a fresh auto-approved plan). Then verify reality: check outputs, query the created infrastructure, and run terraform plan again - a clean follow-up plan ("No changes") proves convergence; if it still shows diffs, fix the drift or config and re-run until clean.Load detailed guidance only when the task needs it:
| Topic | Reference | Load When |
|---|---|---|
| Remote backends, state locking, state surgery | references/state-and-backends.md | Configuring/migrating a backend, S3 + lockfile setup, renaming/moving/importing/forgetting resources, workspaces, state file questions |
| Module design, variable/output contracts, versioning | references/modules.md | Creating or refactoring a module, typed variables with validation, optional() defaults, module sources and version pinning, provider passing |
| for_each vs count, lifecycle meta-arguments | references/foreach-lifecycle.md | Any resource collection, converting count to for_each, unwanted destroy/replace in plans, create_before_destroy, prevent_destroy, ignore_changes, replace_triggered_by |
| Secrets, sensitive values, security posture | references/secrets-and-security.md | Any credential/API key/password in config, secrets appearing in state or plan output, ephemeral values, write-only arguments, external secret stores |
| CI pipelines, plan review, drift detection | references/ci-workflows.md | Setting up plan-on-PR/apply-on-merge, GitHub Actions or GitLab CI for Terraform, OIDC cloud auth, scheduled drift detection, plan artifacts |
Config-driven state surgery - never terraform state mv by hand:
moved {
from = aws_instance.app
to = aws_instance.app["primary"] # count -> for_each rename, no destroy
}
import {
to = aws_s3_bucket.logs
id = "acme-prod-logs" # adopt existing infra via plan/apply
}
removed {
from = aws_iam_user.legacy
lifecycle { destroy = false } # forget from state, keep the real resource
}
for_each keyed on stable strings (indexes shift; keys don't):
variable "subnets" {
type = map(object({ cidr = string, az = string }))
}
resource "aws_subnet" "this" {
for_each = var.subnets # keys: "public-a", "private-a", ...
vpc_id = aws_vpc.main.id
cidr_block = each.value.cidr
availability_zone = each.value.az
}
Version pinning - providers get ~>, modules get exact or ~>:
terraform {
required_version = ">= 1.9.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.0"
}
}
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 6.0" # never unpinned registry modules
}
Cross-variable validation (Terraform 1.9+):
variable "instance_count" {
type = number
}
variable "azs" {
type = list(string)
validation {
condition = var.instance_count <= length(var.azs)
error_message = "instance_count cannot exceed the number of AZs."
}
}
terraform apply -auto-approve with no saved plan is how production gets destroyed. Always plan -out=tfplan, human-review every destroy/replace line, then apply tfplan.count to for_each (or reordering a list) without moved blocks - the plan destroys resource[1] and creates resource["name"] because state addresses changed, not the infrastructure. Write one moved block per element before planning.state mv, state rm, terraform import) - these mutate state immediately with no plan preview and don't survive code review. Use moved, removed, and import blocks so the change is visible in the plan and in the PR.data blocks read existing infrastructure at plan time and fail if it doesn't exist yet; they do not create anything. If this config manages the object, reference the resource directly; never pair a resource with a data source for the same object in one config..tfvars, locals, or resource arguments - they land in plaintext state and plan files. Mark variables sensitive = true, prefer ephemeral values/write-only arguments (Terraform 1.10/1.11+), and fetch from a secret store at runtime; never commit them.version constraint means the next init -upgrade can pull a breaking major and the plan silently changes. Pin providers ~> MAJOR.MINOR and commit .terraform.lock.hcl.ignore_changes as a drift band-aid - ignoring an argument hides real configuration divergence forever. Use it only for fields legitimately mutated outside Terraform (e.g., autoscaled desired_count), and document why.use_lockfile = true on the S3 backend provides native locking via a lock object; DynamoDB-based locking is legacy.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub aarvion-ai/stackwise-skills --plugin stackwise16 skills in this plugin
/docker-expertUse when working with Dockerfile, docker-compose.yml, .dockerignore, or multi-stage builds. Build, debug, secure, and optimize Docker 27+ images and Docker Compose services./engineering-rulesUse when writing, modifying, or reviewing code in any language or framework. Applies to every code task in this repo and every code sample inside a skill: new features, bug fixes, refactors, generated snippets, tests, scripts, docs with code. Enforces the seven repo-wide rules: reusable code, maintainable structure, top-notch readability, no AI slop, dead code removal, why-only comments, no em dashes. Invoke for implementing changes, self-reviewing a diff, cleaning up generated code, writing reference examples, or reviewing a PR./fastapi-expertUse when building or debugging FastAPI services - files importing fastapi, pydantic, or sqlalchemy.ext.asyncio; projects with pyproject.toml using uv/ruff/mypy; mentions of FastAPI, Pydantic v2, APIRouter, Depends, async endpoints, OAuth2/JWT auth, or pytest with httpx. Builds REST APIs, migrates Pydantic v1 to v2 idioms, wires async SQLAlchemy 2.0, adds auth and settings, writes async tests. Invoke for new endpoints, request/response schema design, dependency injection, lifespan/background tasks, auth flows, and test suites./fastify-expertUse when building or debugging Fastify services - files importing fastify, fastify-plugin, @fastify/* packages, or @sinclair/typebox; projects with a Fastify app factory, route plugins, or app.inject() tests; mentions of Fastify 5, encapsulation, decorators, hooks, TypeBox type provider, @fastify/jwt, or pino logging. Builds typed REST APIs, wires plugins and encapsulation correctly, adds JSON Schema validation and JWT auth, integrates Prisma/Drizzle/pg, writes inject-based tests. Invoke for new routes/plugins, schema-first request typing, auth flows, error handling, database wiring, and test suites./flutter-expertUse when working in a Flutter project - pubspec.yaml, *.dart files, lib/main.dart, analysis_options.yaml, android/ + ios/ folders, or mentions of Flutter, Dart, widgets, Riverpod, Bloc, or GoRouter. Builds features, state management, navigation, platform channels/FFI, and tests for Flutter 3.3x / Dart 3.x apps. Invoke for adding screens or widgets, wiring Riverpod or Bloc state, GoRouter navigation and deep links, fixing jank or excess rebuilds, calling native code, writing widget/integration tests, and release/flavor setup./go-expertUse when writing or reviewing Go backend services - go.mod, *.go files, net/http handlers, pgx/sqlc database code, goroutines, context.Context plumbing, or failing `go test` runs. Builds HTTP APIs on the Go 1.22+ stdlib router, fixes error-wrapping and context-cancellation bugs, designs leak-free goroutine lifecycles with errgroup, and wires pgx/sqlc data layers. Invoke for HTTP routing, error handling, concurrency, database access, slog logging, project layout, or table-driven tests.