$ command-helper

Terraform

Everyday plan/apply, workspaces, working with state, imports and targeted runs.

Requires Google sign-in

Everyday workflow

Initialize providers and backend
terraform init
Format and validate
terraform fmt -recursive && terraform validate
Show planned changes
terraform plan
Save a plan and apply exactly it
terraform plan -out=tfplan && terraform apply tfplan
Plan with a variables file
terraform plan -var-file=<env>.tfvars
Show outputs
terraform output
Destroy everything (with confirmation)
terraform destroy

Workspaces

List workspaces
terraform workspace list
Create and switch to a workspace
terraform workspace new <workspace>
Switch workspace
terraform workspace select <workspace>

State

List resources in state
terraform state list
Show a resource from state
terraform state show '<resource>'
Rename or move a resource in stateadvanced
terraform state mv '<resource>' '<new_resource>'

In Terraform 1.1+ prefer a moved {} block in code.

Forget a resource without destroying itadvanced
terraform state rm '<resource>'
Import an existing resourceadvanced
terraform import '<resource>' <cloud_id>
Release a stuck state lockadvanced
terraform force-unlock <lock_id>

Targeted and advanced runs

Plan a single resourceadvanced
terraform plan -target='<resource>'
Recreate a resourceadvanced
terraform apply -replace='<resource>'
Sync state with reality without changing infraadvanced
terraform apply -refresh-only
Upgrade providers within constraintsadvanced
terraform init -upgrade
Detailed logsadvanced
TF_LOG=DEBUG terraform plan