Terraform & Infrastructure as Code›Modules · Cheat sheet & self-check
Learning Hub / Delivery & Infrastructure as Code / Terraform & Infrastructure as Code

Modules · wrap-up

Cheat sheet & self-check

20 questions across 7 lessons. Each answer links back to the lesson it came from.

Pick an answer to see if you got it, and why.

  1. Q1. What does 'declarative' mean in Terraform?

    Show answer

    B. You write 'there should be a bucket named X'. Terraform compares that with reality (via state) and plans the steps.

    From lesson 01 · IaC principles & Terraform basics
  2. Q2. What does terraform plan do?

    Show answer

    B. Plan is the safety step: read it every time, especially lines that destroy or replace resources.

    From lesson 01 · IaC principles & Terraform basics
  3. Q3. Why commit .terraform.lock.hcl to Git?

    Show answer

    B. The dependency lock file makes runs reproducible. Upgrade providers deliberately with 'terraform init -upgrade'.

    From lesson 01 · IaC principles & Terraform basics
  4. Q4. You rename resource aws_s3_bucket.old to aws_s3_bucket.logs in code. Without anything else, what does plan propose?

    Show answer

    B. Terraform sees one address disappear and a new one appear. A moved block tells it they're the same object.

    From lesson 02 · State management
  5. Q5. Why are import blocks better than running 'terraform import' by hand?

    Show answer

    B. Code-based import goes through the normal plan/review/apply workflow instead of a one-off command on someone's laptop.

    From lesson 02 · State management
  6. Q6. Does marking an output 'sensitive' keep the value out of state?

    Show answer

    B. State is plain JSON with every attribute. Encrypt it and restrict who can read it.

    From lesson 02 · State management
  7. Q7. What does a validation block on a variable do?

    Show answer

    B. Catching 'environment must be dev, staging or prod' at plan time beats discovering it halfway through an apply.

    From lesson 03 · Variables, outputs & data sources
  8. Q8. What's the difference between a resource and a data source?

    Show answer

    B. Use data sources to look up AMIs, VPCs or zones managed elsewhere, without taking ownership.

    From lesson 03 · Variables, outputs & data sources
  9. Q9. Why prefer for_each over count for a list of named things?

    Show answer

    B. With count, removing the first element renumbers everything after it. for_each addresses stay stable.

    From lesson 03 · Variables, outputs & data sources
  10. Q10. Why pin module versions (ref=v1.4.0 or version constraints)?

    Show answer

    B. Unpinned modules follow the latest code. Pinning lets each environment adopt new versions through a reviewed change.

    From lesson 04 · Modules
  11. Q11. What's a sign a module is too generic?

    Show answer

    B. Good modules encode opinions (secure defaults, naming, tagging). Thin wrappers over every argument add complexity without value.

    From lesson 04 · Modules
  12. Q12. Where should provider configuration usually live?

    Show answer

    B. Configuring providers inside reusable modules makes them hard to use with multiple regions/accounts and breaks features like count/for_each on modules.

    From lesson 04 · Modules
  13. Q13. Why are provisioners considered a last resort?

    Show answer

    B. Provisioners run arbitrary commands outside Terraform's model. Prefer declarative mechanisms (images, cloud-init, dedicated providers).

    From lesson 05 · Provisioners & bootstrap
  14. Q14. What is cloud-init?

    Show answer

    B. Almost every cloud and virtualization platform (AWS, OpenStack, libvirt, VMware, bare-metal provisioning) supports cloud-init.

    From lesson 05 · Provisioners & bootstrap
  15. Q15. Why bake software into images instead of installing it at boot?

    Show answer

    B. Boot-time installs fail when mirrors are slow or unreachable (think air-gapped sites). Images make boots predictable.

    From lesson 05 · Provisioners & bootstrap
  16. Q16. Why use a base cloud image with per-VM backing-file volumes?

    Show answer

    B. qcow2 copy-on-write layering: one base image, thin per-VM overlays. Recreating a VM takes seconds.

    From lesson 06 · Terraform for bare metal / libvirt
  17. Q17. How does a libvirt VM get its user, SSH key and hostname?

    Show answer

    B. The provider builds a small cloud-init ISO; the cloud image's cloud-init reads it on first boot.

    From lesson 06 · Terraform for bare metal / libvirt
  18. Q18. What does 'terraform test' with command = plan check?

    Show answer

    B. Plan-mode tests are fast and free: they catch wrong names, tags or counts. Apply-mode tests create real (temporary) resources.

    From lesson 07 · Production patterns
  19. Q19. Why run policy checks on the plan JSON rather than on the .tf files?

    Show answer

    B. Rules like 'no S3 bucket may be public' or 'never delete an EKS cluster' are reliable only on resolved values and planned actions.

    From lesson 07 · Production patterns
  20. Q20. What's the benefit of a scheduled drift-detection job?

    Show answer

    B. Drift found at 3 a.m. by a job beats drift found during an urgent change. Then decide: codify it or revert it.

    From lesson 07 · Production patterns