Core Workflow Commands
terraform init
terraform init The command is the essential first step in any Terraform workflow. It prepares your working directory, which contains your Terraform configuration files (.tf files), for all subsequent operations like plan, apply, and destroy. Think of it as setting the stage for Terraform to understand and manage your infrastructure.
terraform fmt
terraform fmt is a command that automatically reformats your Terraform configuration files to a standard, canonical format. This ensures consistency and readability across your codebase, especially when working in a team.terraform plan
terraform plan a command that creates an execution plan, which is a preview of the changes Terraform will make to your infrastructure. It's a crucial dry run step that allows you to verify the expected outcome before applying any changes.
terraform apply
terraform apply is the command you run to apply the changes outlined in your Terraform configuration and make them a reality in your infrastructure. It's the action that creates, updates, or deletes resources to match your code.
terraform destroy
terraform destroy is the command used to remove all the infrastructure that is currently managed by your Terraform configuration. It's the opposite of terraform apply and is a destructive operation that should be used with caution. 💣
terraform plan -out myplan
terraform plan -out=myplan is a command that creates a Terraform execution plan and saves it to a file named "myplan." This file is a binary representation of the changes Terraform intends to make to your infrastructure.
This is a critical step in a controlled and predictable Terraform workflow. Instead of just viewing the plan on the screen, saving it allows you to ensure that the exact plan you reviewed is the one that gets executed.
terraform show myplan
terraform show myplan is a command used to display the contents of a saved Terraform plan file, like "myplan," in a human-readable format.
It's how you inspect and review a plan that was previously created using terraform plan -out=myplan.