Terraform Associate study materials
Terraform Associate study resources

Terraform Associate: Terraform configuration

Terraform Associate · Work through your exam, one topic at a time.

All guide sections

Terraform configuration

Language surface

HCL provides variable blocks (type, default, description, validation, sensitive, nullable), locals, output, expressions (conditionals, for expressions, splats, string templates) and built-in functions such as lookup, merge, cidrsubnet, try, can and coalesce.

Meta-arguments

count (integer), for_each (map or set of strings), depends_on, provider, and lifecycle { create_before_destroy, prevent_destroy, ignore_changes, replace_triggered_by }.

Traps that show up repeatedly

  • for_each cannot take a list - convert with toset() or reshape into a map.
  • count.index yields numeric addresses (aws_instance.web[0]). Deleting an item from the middle of a list shifts every later index and causes needless churn; use for_each for stable addressing.
  • depends_on takes a static list of references, not arbitrary expressions over resource attributes.
  • sensitive = true only masks CLI output; the value is still stored in plaintext in state.
  • Provisioners (local-exec, remote-exec) are a last resort; prefer provider-native features or terraform_data with triggers.
  • Variable precedence, lowest to highest: defaults → TF_VAR_ environment → terraform.tfvars → *.auto.tfvars (alphabetical) → -var/-var-file on the CLI (last flag wins).
  • ignore_changes = [tags["Owner"]] uses attribute paths and accepts all.

Rule of thumb

Ask whether the set of instances is identified by keys (use for_each) or is simply N identical copies (use count).