Interview Prep/Terraform/Testing and Policy as Code

How do you test that a module is idempotent?

IntermediateProductionTesting and Policy as Code
Answer

Apply it, then run plan and assert no changes. In terraform test, use two sequential run blocks: the second runs command = plan against the same state and asserts nothing changes; in Terratest use InitAndApplyAndIdempotent. A non-empty second plan means a perpetual diff bug.

All Terraform questions Roadmap: Terraform in production

More on Testing and Policy as Code