General
terraform get -update=true download and update root modules
terraform fmt format project code to HCL standards
terarform validate validate terraform syntax
terraform providers show information about providers requirements
terraform login & logout login & logout to terraform cloud
Init
terraform init initialize terraform in the current working directory
terraform init -upgrade upgrade modules and plugins at initialization
terraform init -migrate-state -force-copy update backend configuration
terraform init -backend-config=FILE use local backend configuration
terraform init -lock-timeout=120s change state lock timeout
Plan
terraform plan produce a plan with diff between project and state
terraform plan -out filename.tfplan output a plan file for reference during apply
terraform plan -destroy output a plan to show effect of terraform destroy
Apply
terraform apply apply the current state of terraform code
terraform apply filename.tfplan specify a previously generated plan to apply
terraform apply -auto-approve enable auto-approval or automation (for ci/cd)
State
terraform state list list all resources in terraform state
terraform state show ADDRESS show details about a specific resource
terraform state mv SOURCE DESTINATION move an existing resource in state under new name
terraform state import ADDRESS
import a manually created resource into state (resource block should exists)
terraform state pull > terraform.tfstate pull state and save to a local file
terraform taint ADDRESS taint a resource to force redeployment on apply
terraform untaint ADDRESS untaint a previously tainted resource
Outputs
terraform output list available outputs
terraform output OUTPUT_NAME output a specific value
Workspaces
terraform workspace list list the available workspaces
terraform workspace new WORKSPACE_NAME
create a new workspace
terraform workspace select WORKSPACE_NAME
select an existing workspace