Skip to main content
InterviewHubPRO
Section Overview
Q21

Question 21 of 50

Part 2: Modules, Multi-Environment & GitOps (16 - 30)

42%
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):

  1. Export plan as JSON: terraform show -json tfplan.binary > plan.json.
  2. 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.