iac-source-coupled-test
Test uses raw Terraform/HCL text as an infrastructure-behavior oracle.
Why
Substring and regex checks can pass on comments, formatting, or unreachable Terraform configuration without proving the plan or deployed behavior.
Fix
Assert on parsed configuration, Terraform test or rendered plan/state JSON, provider state, or runtime behavior. When exact source representation is the contract, suppress the assertion with that rationale.
Examples
from pathlib import Path
def test_policy(): source = Path("main.tf").read_text() assert "prevent_destroy = true" in sourcedef test_policy(rendered_plan_json: str): plan = json.loads(rendered_plan_json) changes = plan["resource_changes"] assert changes[0]["change"]["actions"] == ["create"]