Terraform & IaC
Policy as code
Policy as code checks Terraform plan data against written rules before changes are applied, and it protects a team only when the rules are tested and fail on a known bad plan.
What you will be able to do
- Explain why policy checks read the plan rather than only the source code.
- Decide how to test a policy so that a known bad plan fails the gate.
What is in the lesson
- A real situation where this goes wrong
- How it works, step by step
- A walkthrough with commands you can run
- How it fails in production, and how to tell
- Three quiz questions with explanations
Read this lessonFree. No account needed.
More in Terraform & IaC
- Multi account providersAdvanced · 4 min
Multi-account Terraform works when each provider configuration assumes a role in its own account, because an assumed session carries that role's permissions and then…
- Workspaces limitationsAdvanced · 4 min
Workspaces hold separate states inside one backend and one configuration, which makes them a weak barrier between environments that need separate credentials, so use…
- OPA and SentinelAdvanced · 4 min
OPA and Sentinel are policy frameworks that evaluate rules against plan data, and the right choice depends on whether the checks run inside HCP Terraform or in your own…
- Terraform testingAdvanced · 4 min
Explain how Terraform's built-in test files check a module's behaviour. Plan-mode runs read planned values cheaply, while apply-mode runs create real infrastructure and…
- State recoveryAdvanced · 5 min
Explain how to recover Terraform state when a real object and its state entry disagree. Back up state first, then edit the state map and plan again before any apply.
- Destroy planningAdvanced · 4 min
Explain how to build, save and read a Terraform destroy plan before anything is deleted. The saved plan shows exactly what the destroy will remove, and only that file…