terraform-specialist
Terraform configuration writing, module development, state management, and multi-cloud infrastructure provisioning. Use when asked to write Terraform code, create a reusable Terraform module, manage T
SKILL.md.claude/skills/terraform-specialist/SKILL.md
GitHubTerraform Specialist
Activation criteria
- User language explicitly matches trigger phrases such as
write Terraform,Terraform module,terraform plan error. - The requested work fits this skill's lane: Terraform HCL writing, module development, state management, workspace strategy, import.
- The task stays inside this skill's boundary and avoids adjacent areas called out as out of scope: Cloud service selection (use cloud specialist for that context); application code.
First actions
Glob('**/*.tf', '**/*.tfvars', '**/terraform.lock.hcl', '**/.terraform.lock.hcl')— find existing Terraform codeReadmain.tf, variables.tf, and backend configuration to understand current structure- Identify: provider(s), backend type (local, S3, Terraform Cloud), workspace strategy, Terraform version
Decision rules
- Backend: never use local state for anything beyond local dev/testing — use remote backend (S3 + DynamoDB lock, or Terraform Cloud)
- Modules: write reusable modules for any resource pattern used more than once; one module per logical unit
- Variables: all variables need
descriptionandtype; sensitive vars getsensitive = true - For importing existing resources: use
terraform importand generate the config; verify withterraform planshowing no changes - If cloud-specific service knowledge is needed: use this skill for Terraform HCL; route service questions to aws/azure/gcp-specialist
Steps
Step 1: Read existing code
Understand provider versions, module structure, variable patterns, and naming conventions in use.
Step 2: Write Terraform code
File structure: main.tf (resources), variables.tf (input vars), outputs.tf (output values), versions.tf (required_providers block).
Step 3: Validate
terraform fmt -recursive
terraform validate
terraform plan
All three must pass cleanly before handing back.
Output contract
- File structure:
main.tf,variables.tf,outputs.tf,versions.tfminimum - All resources: use consistent naming convention (
<env>-<service>-<type>, e.g.,prod-api-sg) - All sensitive outputs: marked
sensitive = true terraform planshows only the intended changes - no unexpected destroys
Constraints
- NEVER commit
.tfstatefiles or.terraform/directories - NEVER use
terraform apply -auto-approvein production environments without a review step - NEVER hardcode credentials in
.tffiles - use provider-level auth (IAM roles, env vars, Vault) - Scope boundary: cloud service selection and architecture belongs to cloud specialist skills; this skill handles HCL and Terraform mechanics
Examples
Example 1: New AWS infrastructure module
User says: "Write a Terraform module for an ECS service with ALB and auto-scaling" Actions:
- Glob for existing Terraform modules to match conventions
- Write module with: ECS cluster, task definition, service, ALB, target group, security groups, auto-scaling policy
- Write variables.tf with all configurable parameters; outputs.tf with service URL and ARN
Result: Complete Terraform module directory passing
terraform validate
Troubleshooting
"Error: Error acquiring the state lock"
Cause: Previous run crashed holding DynamoDB lock
Fix: terraform force-unlock <LOCK_ID> - verify no other apply is running first
Plan shows unexpected resource destroy
Cause: Resource name changed, moved to a module, or provider upgrade changed resource behavior
Fix: Use terraform state mv to rename in state; or use moved {} block (Terraform 1.1+)
Reference
references/legacy-agent.md: module patterns, state management strategies, workspace management, provider configuration, import workflows, Terraform Cloud/Enterprise patterns