Generate and save a plan
Generates an execution plan to a file.
terraform plan -out=tfplan
15 commands from the cloud runbook. Fill in a placeholder once and every command uses it.
Generates an execution plan to a file.
terraform plan -out=tfplan
Applies changes automatically.
Caution. Applies without showing a plan for approval. Use it only in CI, ideally on a reviewed saved plan: terraform apply tfplan.
terraform apply -auto-approve
Brings existing cloud resource under TF state.
terraform import <resource_address> <cloud-resource-id>
Terraform 1.5 and later also support import blocks in configuration, which show up in the plan.
Removes a resource from state tracking without destroying the actual cloud resource.
terraform state rm <resource_address>
Terraform stops managing the resource; it keeps running. Back up the state first.
Manually removes a lock on the state file if a previous pipeline crashed.
Caution. Only when you are sure no other run holds the lock. Two runs writing the same state can corrupt it.
terraform force-unlock <lock-id>
Initializes terraform and upgrades all providers to their latest allowed versions.
terraform init -upgrade
Shows all available state workspaces.
terraform workspace list
Validates the syntax and internal consistency of terraform files.
terraform validate
Rewrites all .tf files to a canonical format.
terraform fmt -recursive
Displays the output values from your terraform state.
terraform output -json
Shows all resources currently tracked by terraform.
terraform state list
Displays attributes of a single resource in the state.
terraform state show <resource_address>
Generates a visual dependency graph of resources in DOT format.
terraform graph | dot -Tpng > graph.png
Needs Graphviz for the dot command.
Plans the destroy and re-create of one resource. Replaces the deprecated terraform taint.
terraform apply -replace=<resource_address>
Creates and switches to a new terraform workspace.
terraform workspace new <workspace-name>