Domain 4 of 8 · Chapter 7 of 8

Custom condition validation

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 shared shape of a custom condition
  • Variable validation
  • Preconditions and postconditions
  • Check blocks and assertions
  • How this appears on the exam

Terraform custom-condition mechanisms

AspectVariable validationPrecondition / postconditionCheck block
Declared inThe variable blockA lifecycle block, or an outputA top-level check block
RunsBefore the planPrecondition before, postcondition after create/updateLast, after plan or apply
On failureError, halts the runError, halts the run and blocks dependentsWarning, run continues
The self objectNot availableAvailable in a postconditionNot available
Introducedv0.13v1.2v1.5

Decision tree

Validating a module input value?Variable validationYesNoShould a violation only warn?Check block (assert)YesNoVerify before the object is built?PreconditionYesNoPostcondition (self)

Cheat sheet

  • Validation block syntax
  • Validation fails on false
  • Where pre/postconditions live
  • Pre vs post timing and self
  • Failed conditions block operations
  • Check block syntax
  • Checks are non-blocking

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

References

  1. Custom Conditions - Configuration Language
  2. Checks - Configuration Language
  3. Input Variables - Configuration Language
  4. Terraform 1.9 enhances input variable validations Blog