Back to feed
Dev.to
Dev.to
5/9/2026
Build a Terraform Plan JSON

Build a Terraform Plan JSON

Original: How I Built a Terraform Plan JSON Parser in Python

Short summary

A technical deep-dive for building infrastructure tooling on Terraform, with practical Python examples. Covers the two-step process to generate JSON plans, parsing the resource_changes structure, understanding action types (create, update, delete, replace), and handling subprocess execution. Explains non-obvious behavior like timeout configuration and why create-before-destroy lifecycle settings affect change ordering. Drawn from the author's experience building tfdrift.

  • Two-step process required: terraform plan -out=tfplan, then terraform show -json tfplan
  • resource_changes array contains before/after snapshots with action types indicating create, update, delete, or replace
  • Compound actions like [create,delete] vs [delete,create] determine if downtime occurs during resource replacement

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Explore more