Skip to content

Commit

Permalink
Made metadata removal ready for UDT (#4090)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSehr authored Oct 15, 2023
1 parent ffa263a commit 948838b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions utilities/pipelines/staticValidation/helper/helper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,22 @@ function Remove-JSONMetadata {
[hashtable] $TemplateObject
)
$TemplateObject.Remove('metadata')
for ($index = 0; $index -lt $TemplateObject.resources.Count; $index++) {
if ($TemplateObject.resources[$index].type -eq 'Microsoft.Resources/deployments') {
$TemplateObject.resources[$index] = Remove-JSONMetadata -TemplateObject $TemplateObject.resources[$index].properties.template

# Differantiate case: With user defined types (resources property is hashtable) vs without user defined types (resources property is array)
if ($TemplateObject.resources.GetType().BaseType.Name -eq 'Hashtable') {
# Case: Hashtable
$resourceIdentifiers = $TemplateObject.resources.Keys
for ($index = 0; $index -lt $resourceIdentifiers.Count; $index++) {
if ($TemplateObject.resources[$resourceIdentifiers[$index]].type -eq 'Microsoft.Resources/deployments') {
$TemplateObject.resources[$resourceIdentifiers[$index]] = Remove-JSONMetadata -TemplateObject $TemplateObject.resources[$resourceIdentifiers[$index]].properties.template
}
}
} else {
# Case: Array
for ($index = 0; $index -lt $TemplateObject.resources.Count; $index++) {
if ($TemplateObject.resources[$index].type -eq 'Microsoft.Resources/deployments') {
$TemplateObject.resources[$index] = Remove-JSONMetadata -TemplateObject $TemplateObject.resources[$index].properties.template
}
}
}

Expand Down

0 comments on commit 948838b

Please sign in to comment.