Domain 4 of 8 · Chapter 6 of 8

Resource dependencies

Unlock the complete study guide + 1,040 practice questions across 16 full exams.

Bundled into the existing HashiCorp Certified: Terraform Associate premium course — no separate purchase.

14-day money-back guarantee — no questions asked.

Included in this chapter:

  • The dependency graph and implicit dependencies
  • Explicit dependencies with depends_on
  • Replacement order and the lifecycle block
  • How this appears on the exam

The four lifecycle meta-argument settings

Settingcreate_before_destroyprevent_destroyreplace_triggered_byignore_changes
What it changesNew object created before the old one is destroyedAny plan that would destroy the object is rejectedForces replacement when referenced items changeSuppresses in-place update proposals
When it actsDuring a forced replacementAt plan time, on any destroy of this objectAt plan time, when a referenced item changesAt plan time, on updates only (never on create)
Value it takestrue or falsetrue or falseList of managed-resource referencesList of attribute references, or the keyword all
Typical useZero-downtime replacementGuard a stateful data storeRebuild on an unreferenced changeIgnore out-of-band drift

Decision tree

Order between resources?Resource referencesthe other's value?Replacement or update behavior?YesNoYesNono downtimenever destroyon ref changeignore driftImplicit referencedepends_oncreate_before_destroyprevent_destroyreplace_triggered_byignore_changes

Cheat sheet

  • Implicit dependencies preferred
  • Graph ordering direction
  • depends_on accepts references only
  • When to use depends_on
  • Default replacement order
  • create_before_destroy
  • prevent_destroy and replace_triggered_by
  • lifecycle ignore_changes suppresses out-of-band update proposals

Unlock with Premium — includes all practice exams and the complete study guide.

References

  1. Create Resource Dependencies (tutorial)
  2. Terraform Internals: Resource Graph
  3. The depends_on Meta-Argument
  4. The lifecycle Meta-Argument