Terraform & IaC (50 Qs)•Part 2: Modules, Multi-Environment & GitOps (16 - 30)
What is Policy as Code? Enforcing Guardrails with Open Policy Agent (OPA) / Conftest.
junior LevelterraformModules
In Simple Words:
Policy as Code validates planned infrastructure against organizational compliance, security, and cost rules before apply runs.
Using Conftest (OPA / Rego):
- Export plan as JSON:
terraform show -json tfplan.binary > plan.json. - Evaluate rules written in Rego:
- "No S3 buckets without server-side encryption."
- "No security groups with 0.0.0.0/0 open to port 22 (SSH)."
- If a violation is detected, CI/CD blocks the merge.