| 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.
Core Workflow
terraform init
terraform plan
terraform apply
terraform apply -auto-approve
terraform destroy
Common Commands
State Management
terraform state list
terraform state show aws_instance.my_vm
terraform state mv old_name new_name
terraform state rm resource_name
terraform state pull
Planning
terraform plan -out=plan.tfplan
terraform apply plan.tfplan
terraform plan -target=aws_instance.my_vm
terraform plan -var="region=us-west-2"
terraform plan -var-file=prod.tfvars
Workspace Management
terraform workspace list
terraform workspace new staging
terraform workspace select production
terraform workspace show
Output and Formatting
terraform output
terraform output -json
terraform output db_endpoint
terraform fmt
terraform validate
Import
terraform import aws_instance.my_vm i-1234567890abcdef0
Agent Best Practices
- Always run
terraform plan before terraform apply to preview changes
- Use
-out=plan.tfplan to save plans and apply them exactly
- Use
-target flag sparingly - only for debugging specific resources
- Use
terraform output -json for machine-readable output
- Run
terraform fmt before committing to keep consistent formatting
- Use
terraform validate to check syntax without accessing providers
- Never store state files in git - use remote backends (S3, GCS, Terraform Cloud)
- Use
-auto-approve only in automated pipelines, not for manual runs
Example Workflows
Initialize and deploy
terraform init
terraform plan -out=deploy.tfplan
terraform apply deploy.tfplan
Check current infrastructure
terraform state list
terraform output -json | jq