Check blocks and failure behavior
Report a failed observation without blocking a normal run
A check is a named configuration-level observation. It is useful when a warning should prompt investigation but must not prevent the normal plan or apply. This local fixture models a readiness count without querying any service.
variable "ready_replicas" { type = number default = 1}
resource "terraform_data" "report" { input = var.ready_replicas}
check "capacity_report" { assert { condition = terraform_data.report.output >= 2 error_message = "The synthetic report shows fewer than two ready replicas." }}The expected value after a fresh apply is 1, so the assertion warns. Setting ready_replicas to 2 makes the assertion pass when the output is known. A check failure by itself does not cancel a normal CLI apply. Other errors may still stop the run. No server, provider API or readiness probe is involved.
Combine independent assertions
A named check can report separate problems. The following standalone configuration checks the fields of a synthetic report.
variable "report" { type = object({ ready = number owner = string }) default = { ready = 2, owner = "" }}
check "report_quality" { assert { condition = var.report.ready >= 2 error_message = "The report needs at least two ready replicas." } assert { condition = try(trimspace(var.report.owner) != "", false) error_message = "The report needs an owner." }}The ready count passes; the owner rule warns. Separate messages help an operator distinguish capacity from missing ownership information. Avoid writing one huge expression that reports only a vague failure. If a rule must block provisioning, choose an appropriate blocking condition or an independently enforced policy gate.
Distinguish static validation from run-specific evidence
Use these commands only in an isolated reviewed fixture with the provisional version and no external dependencies. The validate command checks configuration consistency; use plan to check a particular run with its inputs and state.
terraform init -backend=falseterraform validateterraform plan -var="ready_replicas=1"These commands are intended for the capacity-report fixture above. A fresh plan may defer the check because report.output is unknown. A successful validation does not certify external APIs, actual availability or compliance. Review diagnostics even when the command succeeds. No native command has been executed for this lesson.
Understand scoped observations and unknowns
Checks can use a nested data source to obtain an observation. Such a source is visible only within the containing check; it requires the appropriate provider and may perform external reads. A failing read in this scoped context is reported as a warning in normal plan/apply, unlike an ordinary data source failure. This chapter does not run scoped reads. Unknown values are not automatically false: an assertion may remain pending until its inputs are available. HCP continuous validation is an optional separate workflow; verify feature access before using it. Ordinary CLI checks are not a continuously running monitor.
Review the warning and choose a response
For a fictional catalog release, a missing mandatory owner should block the relevant operation, whereas a stale synthetic dashboard may only warrant investigation. Record the observed failure, the affected resource, the owner and follow-up. If a release must be blocked on a warning, enforce that rule separately in an approved delivery workflow; do not assume normal check semantics do it. Terraform test has separate assertion behavior and will be taught later. Complete the worksheet using the fictional case data.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Check blocks and failure behavior — knowledge check
Review input contracts, conditions and check warnings.
What does a false check assertion normally produce during CLI apply?
What if a check references a value not yet known at plan time?
Where can the nested data source of a check be referenced?
What does a successful terraform validate establish?
How should a team make a readiness warning block a release?