Interview Prep/Terraform/Testing Upgrades and Large-Scale Operations

How do you write unit tests for policy rules without deploying?

AdvancedScenarioTesting Upgrades and Large-Scale Operations
Answer

Situation read → Policies need tests like code.

What I'd do →

  1. Keep a folder of sample plan JSONs (good and bad cases).
  2. Run conftest verify for Rego unit tests, or opa test policy/.
  3. Generate sample plans from small fixtures using terraform show -json.
  4. Run policy tests in CI whenever policies change.

Why → Untested policies either block everything or nothing.

Interview tip → Test both the deny and the allow path.

All Terraform questions Roadmap: Terraform in production

More on Testing Upgrades and Large-Scale Operations