General CLI Commands

Install modules, backend and plugins

$ terraform init

Create Plan & Dry run

$ terraform plan

$ terraform plan -out plan.out

Execute Plan

$ terraform apply

$ terraform apply -auto-approve

Taint resource (mark for recreation)

$ terraform taint

$ terraform untaint

Synchronize state with remote resources

$ terraform refresh

Import resource

$ terraform import <address> <id>

Pull Remote State

$ terraform state pull

Reconstruct resource state (useful if you changed your tf state)

$ terraform state push

Destroy all resources

$ terraform destroy

$ terraform plan -destroy # dry run

Debug

Dump drift

$ terraform show >before

$ terraform refresh

$ terraform show >after

$ diff -u before after

Test interpolations

$ terraform console

Check dependencies

$ terraform graph > dot -Tpng > graph.png

Validate Syntax

$ terraform validate

Format code

$ terraform fmt <file> # reformat .tf file

$ terraform fmt --check <file> # check for correct formatting

Workspaces

List workspaces

$ terraform workspace list

Create workspace

$ terraform workspace new dev

Switch to workspace

$ terraform workspace select dev

Get current workspace

$ terraform workspace show

Sources

http://terraform.io/

https://github.com/scraly/terraform-cheat-sheet/blob/master/terraform-cheat-sheet.pdf

https://lzone.de/cheat-sheet/Terraform

Leave a Comment

Your email address will not be published. Required fields are marked *