Skip to content

Latest commit

 

History

History
134 lines (115 loc) · 2.39 KB

terraform-cheatsheet.md

File metadata and controls

134 lines (115 loc) · 2.39 KB

Terraform CheatSheet

Initial

Check your Terraform intstallation in your local computer:

terraform --version

Initialize a working directory which contains Terraform configuration files:

terraform init

Modifying Terraform code

Adjust the configuratation files in canonical format and style in current directory:

terraform fmt

Adjust the configuratation files in canonical format and style in current directory and subdirectories:

terraform fmt -recursive 

Runs checks that verify whether a configuration is syntactically valid and internally consistent:

terraform validate

Runs checks that verify whether a configuration is syntactically valid and internally consistent and shows in JSON format:

terraform validate -json

Execution Plan

Create an execution plan:

terraform plan

Create an execution plan in a seperated file:

terraform plan -out=tfplan

Deploy the execution Plan

Apply the pre-determined execution plan generated by terraform plan:

terraform apply

Apply the pre-determined execution plan without confirming:

terraform apply -auto-approve

Apply the pre-determined execution plan from the generated plan file:

terraform apply "tfplan"

Destroy all deployed resources

Destroy all resources based off of what's in state file:

terraform destroy

Destroy a specefic or targeted resource:

terraform destroy -target=azurerm_virtual_machine.test

State management

List of all resources incl. modules:

terraform state list

Shows the state or info about a resource:

terraform state show <resource-name>

Pull the remote state into the local state:

terraform state pull > terraform.tfstate

Refresh the state:

terraform refresh

Inspecting infrastucture

Generate an .svg format image from your deployed resources:

terraform graph | dot -Tsvg > graph.svg

Shows all outputs:

terraform output

Shows a specefic output:

terraform output <output-name>

Shows all outputs in json format:

terraform output -json

Workspace

Create a new workspace:

terraform workspace new <workspace-name>

Switch to a workspace:

terraform workspace select <workspace-name>

List all workspaces:

terraform workspace list

Reference

Terraform Developer CLI Docs