Terraform

How do modules handle inputs, outputs, locals and validation effectively?

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

  • Define typed variables with defaults and validation blocks to guard against invalid CIDRs, AZ counts, or empty strings.

  • Use locals to transform data or derive names, and combine with for_each/count for deterministic resource creation.

  • Document outputs in outputs.tf, mark sensitive ones, and keep outputs minimal to reduce coupling.

  • Surface module metadata (like version or tags) through outputs for downstream modules or automation.