The check block defines post-deploy, runtime assertions that validate the state of deployed resources. Checks run after resources are provisioned and can depend on specific resources being in place.
Syntax
check name {
depends_on = [resource_a, resource_b]
assert {
condition = <boolean expression>
error_message = <string expression>
}
}
The label is a bare identifier, quotes optional. A quoted label may contain spaces.
Fields
| Field | Description |
|---|
depends_on | Optional. A list of resource references the check depends on. The check runs after these resources are available. |
assert { } | One or more assertion blocks. See assert. |
Assert blocks
Each assert block has exactly two required fields:
| Field | Description |
|---|
condition | A boolean expression that must evaluate to true for the check to pass. |
error_message | A string expression reported when the condition is false. |
for, count, and for_each are not allowed inside check blocks.
Example
check api_health {
depends_on = [api_gateway, backend]
assert {
condition = api_gateway.stage == "prod"
error_message = "API gateway must be on the prod stage"
}
}
How checks are used
Checks run as post-deploy assertions. Use depends_on to ensure the referenced resources exist before the assert conditions are evaluated against their live state.