Add a runtime health assertion to infrastructure without blocking applies.
IntermediateScenarioTesting Upgrades and Large-Scale Operations
Answer
Situation read → You want post-apply validation that warns instead of failing.
What I'd do → Use a check block (Terraform 1.5+).
check "app_is_healthy" {
data "http" "health" {
url = "https://${aws_lb.app.dns_name}/health"
}
assert {
condition = data.http.health.status_code == 200
error_message = "Health endpoint did not return 200."
}
}
Why → Check failures show as warnings on every plan/apply, which is useful for continuous validation.
Interview tip → Contrast with precondition/postcondition, which block.
More on Testing Upgrades and Large-Scale Operations
What does each of `terraform validate`, `plan` and `terraform test` actually check?BeginnerWrite a native test for a module that creates an encrypted S3 bucket.IntermediateCompare Terratest with `terraform test`.IntermediateReal-cloud integration tests leave orphaned resources when they fail midway. How do you handle that?AdvancedHow do you upgrade from Terraform 1.5 to 1.9 safely?IntermediateMajor AWS provider upgrade from v4 to v5 (or v5 to v6) across many stacks. How do you plan it?Advanced