A platform team is building an automated reviewer for pull requests that must count how many resources a plan will delete or replace and fail the check above a threshold. Which approach gives the reviewer reliable, structured data to analyze?
Select an answer to reveal the explanation.
Short Explanation
Don't screen-scrape a report written for humans. Save the plan, ask Terraform for its JSON, and read the actions list: a delete or a delete-plus-create is exactly what your reviewer is hunting for.
Full Explanation
terraform show -json on a saved plan file produces the documented machine-readable plan representation. Each entry in its resource changes list carries a change object whose actions array is one of no-op, create, read, update, delete, delete then create, or create then delete. Replacements are represented with both delete and create in either order precisely so tools can scan for delete to find every case where an object will be destroyed. Counting entries whose actions include delete therefore gives an exact figure for destroys plus replacements, and the format carries a version key for compatibility. The human-readable plan is meant for people; its layout and wording can change between releases, and text matching misses or miscounts annotations, so it is a brittle contract. Comparing state listings before and after apply only reports deletions once they have already happened, which defeats a pre-merge gate. The graph command emits a dependency graph in DOT format for visualization; it does not mark planned actions. Exam caveat: the JSON may contain sensitive values in plain text, so treat the artifact with the same care as state. Operational check: feed the reviewer a plan that replaces one resource and confirm it counts one, then confirm a plan with only updates counts zero.