CertLumen

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

Define resource dependencies in configuration

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 orders work from references (implicit dependencies) and from depends_on (explicit ones). The lifecycle block changes how replacement and updates happen, and custom conditions (variable validation, preconditions, postconditions and check blocks) turn assumptions into enforced rules.

Points to remember

  • References create implicit dependencies; depends_on adds explicit ones for hidden relationships.
  • depends_on lists resources or modules (no attributes) and is allowed on resources, data sources, modules and outputs.
  • Terraform walks the graph in parallel, and destroys in reverse dependency order.
  • create_before_destroy builds the replacement first; prevent_destroy makes destroying plans fail.
  • ignore_changes skips listed attributes when planning updates; replace_triggered_by forces replacement.

Try a question

A resource is replaced by default by destroying the old object and then creating the new one. The engineer needs the new object to exist before the old one is removed. What should be set?

  1. Alifecycle { prevent_destroy = true } on the resource being replaced
  2. Blifecycle { create_before_destroy = true }
  3. Cdepends_on = [self]
  4. Dlifecycle { ignore_changes = all }
Show the answer

B. With create_before_destroy, Terraform builds the replacement first. The settings must allow both objects to exist at once, for example by using unique names.

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

In the course

The lesson Dependencies, lifecycle and custom conditions teaches this objective (about 45 minutes), and 17 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 →