Copyright (c) 2026 MindMesh Academy. All rights reserved. This content is proprietary and may not be reproduced or distributed without permission.

4.5.1. Custom Conditions and Checks

💡 First Principle: Custom conditions let you encode your assumptions directly in configuration so Terraform fails fast with a clear message instead of letting a bad value cause a confusing provider error later — moving the failure earlier and making it self-explanatory.

004 expects familiarity with four mechanisms, distinguished by scope and timing:

MechanismWhere it livesWhen it checksBlocks apply?
Variable validationInside a variable blockWhen the variable's value is setYes
preconditionlifecycle block (resource/data/output)Before the object's actionYes
postconditionlifecycle block (resource/data)After the object is read/createdYes
check blockTop-level check blockDuring plan/apply, continuouslyNo (warns only)

Variable validation enforces input rules (condition + error_message). Pre/postconditions guard a resource's assumptions and guarantees — e.g., a precondition that an AMI is in the right region, a postcondition that an instance got a public IP. Check blocks are different: they assert ongoing health (optionally using scoped data sources) and report problems as warnings without failing the run, which makes them ideal for monitoring assumptions rather than gating changes.

⚠️ Exam Trap: The standout distinction: a failing check produces a warning and does not stop the apply, while a failing validation, precondition, or postcondition errors and halts. If a question asks which custom condition reports issues without blocking, the answer is the check block.

Reflection Question: Why would you use a check block (non-blocking) rather than a postcondition (blocking) to assert that a web endpoint returns HTTP 200?

Alvin Varughese
Written byAlvin Varughese
Founder18 professional certifications