TL;DR How do I programatically search for an object which may not be in the same location for each file and remove it?
It's fine if I know exactly where the object will be inside the JSON, but if it changes locations it's difficult to script. At the moment we programtically build an ARM template and push it to Azure, but before we do we compare it to see the version in the cloud differs from the newly generated file, and if it does, either replace it or create a new one based on its version.
The problem is when the template spec is built with a new version Bicep, which then injects that information into the JSON file, which then adjusts the version
and templateHash
values. Sadly, I cannot prevent this from happening.
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.4.1008.15138",
"templateHash": "17593852815978663805"
}
I used to do a Compare-Object
to compare the two files after turning them into PowerShell Objects, but when the binary change came in it threw that idea out. Then I started looking into a more complicated PowerShell comparison where it would ignore lines based on patterns, but this morning that failed with some random error that I can't diagnose cos it's in Azure DevOps pipeline.
Write-Host "`n`n##[debug]