Terraform workflow
Skill agenticdevops/devops-execution-engine/skills/terraform-workflow
Terraform infrastructure as code workflows and best practicesFrom its SKILL.md
npx -y skills add agenticdevops/devops-execution-engine --skill terraform-workflowAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
5.5 KB, ~1.2k tokens by cl100k_base, as published. Nobody here has run it
Terraform Workflow
Infrastructure as Code practices with Terraform.
When to Use This Skill
Use this skill when:
- Managing infrastructure with Terraform
- Reviewing terraform plans
- Debugging state issues
- Following IaC best practices
Basic Workflow
Initialize
# Initialize working directory
terraform init
# Upgrade providers
terraform init -upgrade
# Reconfigure backend
terraform init -reconfigure
Plan
# Preview changes
terraform plan
# Save plan to file
terraform plan -out=tfplan
# Plan for specific target
terraform plan -target=aws_instance.example
# Plan destroy
terraform plan -destroy
Apply
# Apply changes (with approval)
terraform apply
# Apply saved plan (no approval needed)
terraform apply tfplan
# Auto-approve (use with caution!)
terraform apply -auto-approve
# Apply specific target
terraform apply -target=aws_instance.example
Destroy
# Plan destruction first
terraform plan -destroy
# Destroy with approval
terraform destroy
# Destroy specific resource
terraform destroy -target=aws_instance.example
State Management
View State
# List resources in state
terraform state list
# Show specific resource
terraform state show aws_instance.example
# Full state (sensitive!)
terraform show
State Operations
# Move resource (rename)
terraform state mv aws_instance.old aws_instance.new
# Remove from state (resource still exists)
terraform state rm aws_instance.example
# Import existing resource
terraform import aws_instance.example i-1234567890abcdef0
# Pull remote state locally
terraform state pull > terraform.tfstate.backup
State Locking
# Force unlock (use carefully!)
terraform force-unlock LOCK_ID
Workspaces
# List workspaces
terraform workspace list
# Create workspace
terraform workspace new staging
# Switch workspace
terraform workspace select production
# Current workspace
terraform workspace show
Validation & Formatting
# Validate configuration
terraform validate
# Format code
terraform fmt
# Format check (CI/CD)
terraform fmt -check
# Recursive format
terraform fmt -recursive
Output & Variables
View Outputs
# All outputs
terraform output
# Specific output
terraform output instance_ip
# JSON format
terraform output -json
Variable Files
# Use var file
terraform plan -var-file=production.tfvars
# Override variable
terraform plan -var="instance_type=t3.large"
Debugging
Verbose Logging
# Enable debug logging
export TF_LOG=DEBUG
terraform plan
# Log to file
export TF_LOG_PATH=terraform.log
terraform plan
# Disable logging
unset TF_LOG TF_LOG_PATH
Common Issues
| Issue | Cause | Fix |
|---|---|---|
| State lock | Concurrent access | terraform force-unlock |
| Provider error | Version mismatch | terraform init -upgrade |
| Resource drift | Manual changes | terraform refresh then plan |
| Cycle error | Circular dependency | Break dependency with depends_on |
Refresh State
# Update state with real infrastructure
terraform refresh
# Or use plan with refresh
terraform plan -refresh-only
Safe Practices
Plan Review Checklist
- Check the summary: How many add/change/destroy?
- Review destroys: Any unexpected deletions?
- Check sensitive changes: IAM, security groups, encryption
- Validate resource names: Especially for stateful resources
- Look for force replacements:
# forces replacement
Safe Apply Workflow
# 1. Always plan first
terraform plan -out=tfplan
# 2. Review plan carefully
terraform show tfplan
# 3. Apply saved plan
terraform apply tfplan
# 4. Verify changes
terraform show
Prevent Accidental Destroys
# In your terraform config
resource "aws_instance" "critical" {
# ...
lifecycle {
prevent_destroy = true
}
}
Module Management
# Get modules
terraform get
# Update modules
terraform get -update
# Show module tree
terraform providers
CI/CD Integration
GitHub Actions Example
- name: Terraform Plan
run: |
terraform init
terraform plan -out=tfplan -no-color
- name: Terraform Apply
if: github.ref == 'refs/heads/main'
run: terraform apply -auto-approve tfplan
Plan Output for PR
# Generate plan for PR comment
terraform plan -no-color > plan.txt 2>&1
Cost Estimation
# With Infracost
infracost breakdown --path .
# Cost diff
infracost diff --path .
Security Scanning
# With tfsec
tfsec .
# With checkov
checkov -d .
# With trivy
trivy config .
Quick Reference
# Full workflow
terraform init && terraform plan -out=tfplan && terraform apply tfplan
# Check what would be destroyed
terraform plan -destroy | grep "will be destroyed"
# List all resources
terraform state list
# Import resource
terraform import aws_instance.name i-1234567890
# Taint for recreation
terraform taint aws_instance.example
terraform untaint aws_instance.example
Related Skills
- aws-ops: For AWS resource verification
- git-workflow: For IaC version control
- cost-optimization: For infrastructure costs
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.
Gives 0 of the 12 instructions most automation workflows skills give in ~1.2k tokens
Counted across 745 of the 1,008 authors here whose files we hold, read 2026-08-07
- Write conventional commit messagesin 36 of 745, across 35 files
- Delete branches after mergein 30 of 745, across 21 files
- Make atomic commitsin 25 of 745, across 15 files
- Write minimal code to pass testsin 22 of 745, across 10 files
- Re-snapshot after navigation or DOM changesin 21 of 745, across 13 files
- Use try-catch for error handlingin 20 of 745, across 8 files
- Run tests before committingin 20 of 745, across 12 files
- Write tests before implementationin 20 of 745, across 8 files
- Configure branch protection rulesin 19 of 745, across 5 files
- Explain the why in commit messagesin 19 of 745, across 9 files
- Refactor code while tests remain greenin 19 of 745, across 6 files
- Interact with elements using refsin 19 of 745, across 11 files
Said here and by no other author read
- initialize working directory
- save plan to file
- apply saved plan
- validate configuration
- format code recursively
- list resources in state
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.