azure-pipelines-tasks-terraform icon indicating copy to clipboard operation
azure-pipelines-tasks-terraform copied to clipboard

Come up with a more sophisticated way of detecting changes

Open jason-johnson opened this issue 2 years ago • 2 comments

Right now a regex is ran to detect if any changes happen. Investigate if there would be a way to detect the changes in a less error prone way.

Ideas: scan plan output (can we output a separate plan output if user specified one?)

jason-johnson avatar Sep 30 '23 14:09 jason-johnson

I track this project and while I've not got the ability to contribute directly I have used the following successfully in ADO pipelines in BASH to detect changes using jquery (jq). I wonder if you could use jquery within typescript to achieve the same, more robustly than with regex:

terraform show -json "terraform.tfplan" | jq "." > "terraform.tfplan.json" # Output JSON Plan to scan for destroy changes

HAS_DESTROY_CHANGES=$(jq '[.resource_changes // []|.[]|{"address":.address,"actions":.change.actions[0]}|select(.actions=="delete")]|length>0' "terraform.tfplan.json")

Hope this helps or provides some further ideas

Mechanolatry avatar Nov 28 '23 16:11 Mechanolatry