SkillOpen
terraform-cli
Use Terraform CLI to define, plan, and provision infrastructure as code across any cloud provider. Use this instead of the Terraform MCP server.
Front matter
name: terraform-cli
description: Use Terraform CLI to define, plan, and provision infrastructure as code across any cloud provider. Use this instead of the Terraform MCP server.Terraform CLI
Infrastructure as code tool. Define cloud resources in HCL, plan changes, and apply them safely.
- Official repo: https://github.com/hashicorp/terraform
- Docs: https://developer.hashicorp.com/terraform/cli
Core Workflow
terraform init # Initialize working directory, download providers
terraform plan # Preview changes
terraform apply # Apply changes (with confirmation)
terraform apply -auto-approve # Apply without confirmation
terraform destroy # Destroy all managed resourcesCommon Commands
State Management
terraform state list # List all resources in state
terraform state show aws_instance.my_vm # Show resource details
terraform state mv old_name new_name # Rename resource
terraform state rm resource_name # Remove from state (not destroyed)
terraform state pull # Download remote statePlanning
terraform plan -out=plan.tfplan # Save plan to file
terraform apply plan.tfplan # Apply saved plan
terraform plan -target=aws_instance.my_vm # Plan specific resource
terraform plan -var="region=us-west-2" # Pass variable
terraform plan -var-file=prod.tfvars # Use variable fileWorkspace Management
terraform workspace list
terraform workspace new staging
terraform workspace select production
terraform workspace showOutput and Formatting
terraform output # Show all outputs
terraform output -json # JSON format
terraform output db_endpoint # Specific output
terraform fmt # Format HCL files
terraform validate # Validate configurationImport
terraform import aws_instance.my_vm i-1234567890abcdef0Agent Best Practices
- Always run
terraform planbeforeterraform applyto preview changes - Use
-out=plan.tfplanto save plans and apply them exactly - Use
-targetflag sparingly - only for debugging specific resources - Use
terraform output -jsonfor machine-readable output - Run
terraform fmtbefore committing to keep consistent formatting - Use
terraform validateto check syntax without accessing providers - Never store state files in git - use remote backends (S3, GCS, Terraform Cloud)
- Use
-auto-approveonly in automated pipelines, not for manual runs
Example Workflows
Initialize and deploy
terraform init
terraform plan -out=deploy.tfplan
terraform apply deploy.tfplanCheck current infrastructure
terraform state list
terraform output -json | jqSource: written by One Giant Leap.
Related entries
There are more like this in the members library
The Claude Code library holds 13,843 entries. Members can search all of them by meaning and read every one in full.