jason-johnson / azure-pipelines-tasks-terraform

Azure Pipelines extension for Terraform
MIT License
125 stars 53 forks source link

Come up with a more sophisticated way of detecting changes #376

Open jason-johnson opened 1 year ago

jason-johnson commented 1 year ago

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?)

Mechanolatry commented 10 months ago

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