Preconditions or external policy: which to use?
IntermediateProductionTesting and Policy as Code
Answer
precondition and validation live with the code, run everywhere (including laptops and tests) and express module-specific assumptions. External policy (OPA, Sentinel, Checkov) expresses organization-wide rules that apply across all repos and cannot be removed by the module author. We use both: module invariants in-code, company rules outside.
More on Testing and Policy as Code
How do you test infrastructure code, and what does the testing pyramid look like?BeginnerWhat does the static-analysis layer catch?BeginnerWhat does tflint do, and how is it configured?BeginnerHow do Checkov and Trivy differ?IntermediateHow does `terraform test` work?BeginnerHow do mock providers work in `terraform test`?Advanced