Skill 4.7.2

Preconditions and postconditions

Key Concepts

Inside a resource or data block's lifecycle block, a precondition is evaluated before Terraform plans or applies the object, to check assumptions, such as that a looked-up image uses the expected architecture. A postcondition is evaluated after the object is planned or applied, and can use self to check the result, such as that an instance received a public DNS name.

Output blocks accept preconditions, which check a value before it is exposed, but not postconditions. A failed precondition or postcondition is an error that stops the run, and resources that depend on the failed object are not changed. Conditions document assumptions and give much clearer errors than failures deep inside a provider.