Terraform Module Ops
A navigation and safety layer for an existing Terraform codebase — read this
before editing .tf files or running apply/destroy.
1. Locate roots and build a module map
- Find the Terraform root(s) (directories containing
*.tf+ abackendblock) — checkCLAUDE.md/READMEfor the conventional path first (commonlyinfrastructure/terraform/or repo root). - For each
modules/<name>/*.tfand each root-level*.tffile, list the resource/data blocks it declares. Build a quick table: module/file → resources it owns. This lets you answer "where does X live" without re-grepping every time. - Note the provider versions and required Terraform version (
required_providers,required_versionin the rootversions.tf/backend.tf).
2. Identify the state backend
- Read the
backendblock: backend type (e.g.azurerm,s3), state storage location, and state key/path. - Note how many resources are in remote state if easily checked
(
terraform state list | wc -lrequires backend access — only run if the user has credentials configured).
3. Safe local operations (no credentials needed)
cd <tf-root>
terraform fmt -check -recursive -diff # formatting only
terraform init -backend=false -input=false
terraform validate -no-color
If init fails with "Backend initialization required", CI/local convention
is usually to temporarily rename backend.tf:
mv backend.tf backend.tf.bak
terraform init -backend=false -input=false
terraform validate -no-color
mv backend.tf.bak backend.tf
terraform plan/apply require provider credentials (e.g. ARM_* env
vars) — only run these if the user has them configured, and prefer the
terraform-plan-review skill for reviewing the output.
4. Check for known drift before planning a change
Look for a project doc describing known out-of-band/drifted resources (e.g.
a "Known drift" section in a .kiro/skills/*.md, docs/, or README).
If such resources exist:
- A full
terraform applymay try to recreate or destroy them — do not run a full apply if drift is documented; use-target=<resource_address>for the specific resource being changed, or resolve drift first viaimport {}blocks (seeterraform-plan-review).
5. NEVER do without explicit user approval
terraform applywithout-target, when known drift exists.terraform destroy(destroys live infrastructure).- Editing
.tfstatedirectly. - Reading or printing
*.tfvars(commonly contains secrets).
6. CI mapping
If the project has a CI pipeline, identify the terraform job sequence
(typically lint:terraform-fmt → terraform:test → terraform:validate → terraform:plan → terraform:apply (manual gate)) so you know which stage a
local check corresponds to — see ci-preflight for reproducing those stages.