CertLumen

HashiCorp Terraform Associate (004) · Section 4 · 24% of the exam

Understand and use complex types

One of the objectives of the HashiCorp Certified: Terraform Associate (004) exam, in the section “Terraform configuration”. Here is what it covers, the points to remember and a question to try.

What it covers

Terraform has primitive, collection and structural types, and an expression language with conditionals, for expressions, splats, dynamic blocks and built-in functions. This lesson shows how to declare precise types, transform data and generate repeated nested blocks without copying code.

Points to remember

  • Primitive types are string, number and bool; collections are list, set and map; structural types are tuple and object.
  • A set is unordered and unique; convert with tolist() to index it.
  • optional(type, default) marks object attributes the caller may omit (Terraform 1.3+).
  • for_each takes a map or a set of strings; toset() converts a list.
  • A conditional cond ? a : b needs matching result types; count = cond ? 1 : 0 creates a resource conditionally.

Try a question

A module should create an optional monitoring container only when var.enable_monitoring is true. Which approach is idiomatic?

  1. Acount = var.enable_monitoring ? 1 : 0 on the resource
  2. Benabled = var.enable_monitoring as a meta-argument on the resource
  3. Cdepends_on = [var.enable_monitoring]
  4. Dlifecycle { prevent_destroy = var.enable_monitoring }
Show the answer

A. A conditional expression that yields 1 or 0 for count is the standard way to create a resource conditionally.

Written for practice in the style of the exam: never a question from the real exam.

In the course

The lesson Complex types, expressions and functions teaches this objective (about 50 minutes), and 18 practice questions test it. The course has lessons, exam-style questions, timed practice exams and an AI tutor for every objective, and a pass prediction that tells you when you're ready to book.

More in this section

← Previous objective · All 37 objectives · Next objective →