Category | Command | Description |
---|---|---|
Init & Setup | terraform init |
Initialize Terraform working directory |
terraform init -reconfigure |
Reinitialize and ignore previous backend configs | |
terraform init -upgrade |
Reinitialize and upgrade providers/modules | |
terraform get |
Download and update modules | |
Planning | terraform plan |
Show planned changes |
terraform plan -out=tfplan |
Save execution plan to a file | |
Apply/Destroy | terraform apply |
Apply changes with confirmation |
terraform apply tfplan |
Apply using a saved plan file | |
terraform apply -auto-approve |
Apply without manual approval | |
terraform destroy |
Destroy infrastructure with confirmation | |
terraform destroy -auto-approve |
Destroy without confirmation | |
terraform destroy -target=aws_instance.example |
Destroy specific resource | |
Validate & Format | terraform validate |
Validate configuration syntax |
terraform fmt |
Format Terraform files | |
terraform fmt -recursive |
Format files in all subdirectories | |
Output | terraform output |
Show output variables |
terraform output -json |
Show outputs in JSON format | |
State Management | terraform show |
Show full state or plan content |
terraform state list |
List all resources in the state file | |
terraform state show <resource> |
Show specific resource details | |
terraform state pull |
Download current state file | |
terraform state push |
Upload local state file (used with care) | |
terraform refresh |
Update state with real infrastructure | |
terraform taint <resource> |
Mark a resource for recreation | |
terraform untaint <resource> |
Remove taint from a resource | |
Workspace Management | terraform workspace list |
List all workspaces |
terraform workspace new <name> |
Create new workspace (e.g., dev, prod) | |
terraform workspace select <name> |
Switch to another workspace | |
terraform workspace delete <name> |
Delete a workspace | |
Debugging & Visuals | TF_LOG=DEBUG terraform plan |
Enable debug logging |
TF_LOG_PATH=log.txt terraform apply |
Save logs to a file | |
terraform graph | dot -Tpng > graph.png |
Visualize resource graph (Graphviz needed) | |
Terraform Cloud | terraform login |
Authenticate to Terraform Cloud |
terraform logout |
Remove local credentials | |
terraform state push |
Manually upload state file to remote |
No comments:
Post a Comment