Terraform Associate 004 ยท Dependencies, validation and sensitive data
Check blocks
check block with assertions, scoped data source, warnings rather than errors, difference from conditions (4g).
Key points
- A check block validates infrastructure outside the normal resource lifecycle.
- It needs at least one assert (condition plus error_message) and may hold a scoped data block used only by that check.
- Terraform runs checks as the last step of a plan or apply.
- A failed assertion is a warning, never an error, so unlike preconditions and postconditions it does not block anything.
Source: https://developer.hashicorp.com/terraform/language/block/check
Practice questions
What happens when an assertion in a check block fails?
- Terraform shows a warning and continues
- The apply is aborted with an error
- Changed resources are rolled back
- The state file is locked
Show answer
Answer: A. Terraform shows a warning and continues
A check reports a warning and the operation continues; it is the only validation that does not block operations.
Which statements about check blocks are true?
- It needs at least one assert block
- A nested data block is scoped to that check only
- It is evaluated as the last step of a plan or apply
- A failed assertion halts the run
- The nested data block is available to all resources
Show answer
Answer: A. It needs at least one assert block, B. A nested data block is scoped to that check only, C. It is evaluated as the last step of a plan or apply
A check needs at least one assert, its scoped data block exists only for that check, and checks run at the end of plan or apply. A failure does not halt.
A failed check assertion stops terraform apply, just like a failed precondition.
Show answer
Answer: False
False. A check only produces a warning and Terraform continues; preconditions are the ones that halt.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
