terraform - build, change and destroy infrastructure as code
terraform [-chdir=DIR] <init|validate|plan|apply|destroy|fmt|console|output|show|state|import|workspace|test|graph|providers|version|force-unlock|get> [options]
Options you will use
init [-upgrade] [-reconfigure|-migrate-state] [-backend-config=...]- providers, modules, backend
plan [-out=FILE] [-var ...] [-var-file ...] [-target=ADDR] [-replace=ADDR] [-refresh-only] [-destroy] [-detailed-exitcode] [-lock-timeout=DUR]- show the changes
apply [FILE] [-auto-approve]- make the changes (a saved plan applies exactly that plan)
state list|show|mv|rm|pull|push|replace-provider- inspect and change state
workspace list|new|select|show|delete- CLI workspaces
test [-filter=FILE] [-verbose]- run *.tftest.hcl tests
-chdir=DIR- Switch to a different working directory before executing the given subcommand (must come BEFORE the subcommand).
-help- Show this help output, or the help for a specified subcommand.
-version- An alias for the "version" subcommand.
Examples
$ terraform plan -out=tfplan && terraform apply tfplanreview, then apply exactly that plan
$ terraform show -json tfplan | jq ...the plan as JSON, for gates
$ TF_LOG=DEBUG TF_LOG_PATH=tf.log terraform plandebug logging to a file
Taught in
- 12.3 Providers, versions and the lock file
- 12.8 Types, validation and custom conditions
- 12.11 Expressions: references, operators, for, splat and templates
- 12.18 Data sources, references and the dependency graph
- 12.24 The workflow, read like a reviewer
- 13.11 Locking: what it prevents, and how to handle a held lock
- 14.6 Code quality: fmt, validate, tflint
Try terraform in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.