Terraform 1 cheatsheet

Terraform 1: Variables, targets and outputs

7 common Terraform 1 tasks.

Set a variable

Pass a value for an input variable.

terraform apply -var="region=eu-west-1"

Use a variable file

Load variable values from a file.

terraform apply -var-file="prod.tfvars"

Apply a single resource

Limit the run to one resource and what it depends on.

terraform apply -target=aws_instance.web

Caution: Targeting is for exceptional situations. It can leave other resources out of sync.

Force a resource to be recreated

Destroy and recreate a resource. This replaces the old taint command.

terraform apply -replace=aws_instance.web

Caution: Recreating a resource can cause downtime and data loss.

Show outputs

Print all of the configuration's output values.

terraform output

Read one output as a plain value

Print a single output without quotes, handy in scripts.

terraform output -raw db_endpoint

Open an expression console

Try expressions and inspect values interactively.

terraform console

Was this page helpful?