Bitzu

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

Single choice

What happens when an assertion in a check block fails?

  1. Terraform shows a warning and continues
  2. The apply is aborted with an error
  3. Changed resources are rolled back
  4. 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.

Select all that apply

Which statements about check blocks are true?

  1. It needs at least one assert block
  2. A nested data block is scoped to that check only
  3. It is evaluated as the last step of a plan or apply
  4. A failed assertion halts the run
  5. 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.

True or false

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.

Download on the App StoreGet it on Google Play

More Terraform Associate 004 topics in this module