What is a `check` block and how does it differ from validation?
AdvancedConceptLifecycle, Dependencies, Provisioners and Drift
Answer
A check block (1.5+) holds assertions, optionally with a scoped data source, that run at the end of plan and apply. Failures produce warnings, not errors, so they do not block the run. We use them for health probes like "the endpoint returns 200" or certificate expiry, while validation and precondition block bad changes.
check "site_up" {
data "http" "home" { url = "https://${aws_lb.main.dns_name}" }
assert {
condition = data.http.home.status_code == 200
error_message = "Site is not returning 200"
}
}
More on Lifecycle, Dependencies, Provisioners and Drift
What are meta-arguments?BeginnerWhat lifecycle options are available?BeginnerHow does `create_before_destroy` work and what can go wrong?AdvancedWhat does `prevent_destroy` guarantee and what does it not?AdvancedWhen do you use `ignore_changes`?IntermediateWhat does `replace_triggered_by` do?Advanced