Interview Prep/Terraform/Lifecycle, Dependencies, Provisioners and Drift

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"
  }
}
All Terraform questions Roadmap: Terraform in production

More on Lifecycle, Dependencies, Provisioners and Drift