Recall first: read each stage's one-line summary and try to remember its commands. Then open the stage to check yourself.
17 stages81 commands
brew tap hashicorp/tap && brew install hashicorp/tap/terraformInstall Terraform on macOS from HashiCorp's tap
terraform versionCheck the installed version (the course needs 1.11 or newer)
terraform initDownload the providers into .terraform/
terraform planPreview every create, change and destroy without touching anything
terraform applyShow the plan again and apply it after you type yes
Watch for terraform.tfstate can hold secrets in plain text. Never commit it.
Open the lesson: Infrastructure as code, and where Terraform fits →terraform consoleEvaluate expressions interactively with the project's variables and state
[for s in ["web", "api", "db"] : "${s}-prod"]In the console, build a list with a for expression
cidrsubnet("10.0.0.0/16", 8, 2)In the console, carve the /24 subnet number 2 (10.0.2.0/24) from a /16
merge({ team = "shop" }, { env = "prod" })In the console, combine common tags with specific ones
Watch for Both results of a conditional (cond ? a : b) must have the same type.
Open the lesson: HCL: the Terraform language →terraform providersShow which providers the configuration requires and their constraints
terraform init -upgradeMove to the newest provider versions the constraints allow
Watch for Never put access keys in a provider block; they end up in Git history and in state.
Open the lesson: Providers and version pinning →terraform initFirst time, and after changing providers, modules or the backend
terraform init -upgradeUpgrade providers and modules within the constraints and update the lock file
terraform init -reconfigureUse changed backend settings and ignore the old ones
terraform init -migrate-stateCopy existing state to a new backend, for example local to S3
terraform init -backend-config=prod.hclPass backend settings per environment
terraform providers lock -platform=linux_amd64 -platform=darwin_arm64 -platform=windows_amd64Add lock file hashes for teammates on other operating systems
du -sh .terraformSee how big the provider cache is
Watch for Choosing -reconfigure when you meant -migrate-state can leave an empty state. Back up first.
Open the lesson: terraform init and the lock file →terraform plan -var='users=["ravi","meera"]' -no-colorSee how count and for_each react when the first user is removed
terraform destroy -auto-approve -var-file=dev.tfvarsWatch prevent_destroy stop the whole destroy
terraform validateCatch duplicate resource names after a copy-paste
Watch for Removing the first item from a count list replaces every later item and destroys the last index.
Open the lesson: Resources: count, for_each and lifecycle →terraform plan -var-file=dev.tfvarsPlan with one environment's values
terraform plan -var="env=test"Pass one value on the command line (here, to see validation fail)
terraform outputPrint every output after apply
terraform output -json server_filesPrint one output as JSON for scripts
terraform output -raw urlPrint a plain string output, for example in a deploy step
Watch for Keep secrets out of tfvars files; pass them as TF_VAR_ variables from the CI secret store.
Open the lesson: Variables, locals and outputs →terraform fmtRewrite files in the official style and list the ones changed
terraform fmt -check -recursiveChange nothing and exit non-zero if any file needs formatting (for CI)
terraform fmt -diffShow what formatting changed
terraform init -backend=false -input=falseInstall providers for validate without touching the real state
terraform validateCheck syntax, argument names, references and types
tflint --initDownload the TFLint rule plugins set in .tflint.hcl
tflint --format=compactLint the configuration, one finding per line
Watch for validate passes instance_type = "t3.mirco"; only TFLint's AWS ruleset knows it isn't real.
Open the lesson: fmt, validate and TFLint →terraform state listList every resource address in state
terraform state show local_file.webPrint what Terraform recorded for one resource
terraform init -migrate-stateCopy existing local state to the new remote backend
terraform force-unlock 8da76c6d-c1c4-4393-d885-86b285980ed6Release a stale lock by its ID, only when nothing is running
terraform plan -generate-config-out=generated.tfDraft resource code for an import block
terraform state rm random_integer.app_portMake Terraform forget a resource and leave the real object running
terraform state pull > backup.tfstateBack up state before any risky change
Watch for Never use -lock=false on shared state, and never edit the JSON by hand.
Open the lesson: State: Terraform's memory →terraform plan -out=tfplanSave the plan to a file
terraform show tfplanPrint a saved plan again for review
terraform apply tfplanApply exactly the saved plan, with no prompt
terraform plan -refresh-onlyShow only the drift
terraform apply -refresh-onlyAccept drift into state without changing anything real
terraform apply -auto-approve -replace=random_pet.serverForce a fresh object even though the code didn't change
terraform plan -destroyPreview a teardown
terraform destroyDestroy everything in the configuration after you type yes
Watch for -target applies a partial plan. Use it only to recover, then run a full plan straight after.
Open the lesson: Plan, apply and destroy →terraform initInstall modules after adding a module block or changing its source or version
terraform state listSee resource addresses that include the module name
terraform outputRead the values the root module exposes from its modules
terraform init -upgradeFetch a new module version after changing it
Watch for "Module not installed" means you added a module block without re-running terraform init.
Open the lesson: Modules: reusable infrastructure →terraform apply -auto-approve && cat out/nginx.confRender the template and check the generated Nginx config
Watch for Blank lines in rendered output usually mean a ~ is missing from a %{ } directive.
Open the lesson: Data sources, templates and provisioners →terraform workspace showPrint the current workspace
terraform workspace new devCreate a workspace and switch to it
terraform workspace listList workspaces; * marks the current one
terraform workspace select devSwitch to an existing workspace
terraform workspace delete prodDelete a workspace (refused while its state has resources)
Watch for Workspaces share one backend and credentials, and it's easy to apply in the wrong one.
Open the lesson: Environments: workspaces or folders →terraform plan -detailed-exitcodeExit 0 for no changes, 1 for an error, 2 for changes
terraform init -input=falseInitialise without waiting for a prompt nobody will answer
terraform plan -input=false -no-color -out=tfplanMake the plan the approver reads and the apply job uses
terraform show -no-color tfplan > plan.txtWrite a readable plan, with sensitive values redacted, for review
terraform apply -input=false tfplanApply the reviewed plan, nothing else
Watch for Plan files contain secrets. Keep artifact retention short and never post the binary plan publicly.
Open the lesson: Terraform in CI/CD →terraform testRun every .tftest.hcl file and destroy what apply runs created
Watch for Integration tests cost money and time. Run them on a schedule, in a separate test account.
Open the lesson: Testing Terraform code →terraform state list | wc -lCount the resources in a state
infracost breakdown --path .Show the monthly cost of the whole configuration
infracost diff --path . --compare-to base.jsonShow the cost change versus the main branch
Watch for terraform_remote_state downloads the whole state, so readers can see every secret in it.
Open the lesson: Scaling Terraform: split state, Terragrunt, Infracost →read -rs TF_VAR_db_password && export TF_VAR_db_passwordEnter a secret without echoing it or saving it to shell history
terraform output -raw db_passwordProof that a sensitive output still prints in clear
trivy config --quiet --severity HIGH,CRITICAL .Scan Terraform files for insecure settings before apply
checkov -d .Scan with Checkov instead of Trivy
terraform show -json tfplan > plan.jsonExport the plan as JSON for policy tools
conftest test plan.jsonCheck the plan against OPA Rego policies
Watch for A suppressed finding without a reason is a finding. Review suppressions like code.
Open the lesson: Terraform security: secrets, scanning and policy →terraform fmt -check -recursiveCheck formatting across the modules and environments
tflint --recursive --format=compactLint every folder in the project
terraform testRun the module tests against a mocked AWS provider
terraform init -reconfigureSwitch to the local backend from the offline override file
terraform plan -var-file=dev.tfvars -var="ami_id=ami-0123456789abcdef0" -out=dev.tfplanPlan dev offline with no data source calls
terraform apply dev.tfplanTrack B only, apply the saved dev plan to AWS
curl "$(terraform output -raw url)"Check the load balancer answers
terraform destroy -var-file=dev.tfvarsTear dev down the same day, then verify nothing is left
Watch for The ALB, NAT gateway and instances bill by the hour even when idle; a leftover Elastic IP is billed too.
Open the lesson: Capstone: AWS infrastructure with Terraform →