@@ -35,27 +35,12 @@ function ConvertTo-TagArray {
3535 $items += ($text -split ' [,\s]+' | Where-Object { $_ })
3636 }
3737 if (-not $items ) {
38- return @ (' foundation' , ' dspm' , ' defender' , ' foundry' )
38+ return @ (' foundation' , ' dspm' , ' defender' , ' foundry' )
3939 }
4040 $deduped = $items | ForEach-Object { $_.Trim () } | Where-Object { $_ } | Select-Object - Unique
4141 return @ ($deduped )
4242}
4343
44- function Add-TagSource {
45- param (
46- [System.Collections.Generic.List [object ]]$Target ,
47- [object ]$Source
48- )
49- if (-not $Target ) { return }
50- if ($null -eq $Source ) { return }
51- if ($Source -is [System.Collections.IEnumerable ] -and $Source -isnot [string ]) {
52- foreach ($item in $Source ) {
53- Add-TagSource - Target $Target - Source $item
54- }
55- return
56- }
57- $Target.Add ($Source ) | Out-Null
58- }
5944
6045function Restore-StrictMode {
6146 param ([object ]$PreviousValue )
@@ -86,6 +71,11 @@ function Get-BicepParameterConfig {
8671 $json = & $bicepCmd.Source build-params $ParamFile -- stdout 2> $null
8772 if (-not $json ) { return $bag }
8873 $doc = $json | ConvertFrom-Json
74+ # Newer Bicep CLI wraps output as { parametersJson: "<json string>", ... }
75+ $paramJsonProp = $doc.PSObject.Properties [' parametersJson' ]
76+ if ($paramJsonProp -and $paramJsonProp.Value ) {
77+ $doc = $paramJsonProp.Value | ConvertFrom-Json
78+ }
8979 $parametersProp = $doc.PSObject.Properties [' parameters' ]
9080 if ($parametersProp -and $parametersProp.Value ) {
9181 foreach ($prop in $parametersProp.Value.PSObject.Properties ) {
@@ -174,12 +164,22 @@ if (-not (Test-Path -Path $specPath)) {
174164}
175165
176166$paramTags = Get-ParamArray ' dagaTags'
177- $combinedTags = New-Object ' System.Collections.Generic.List[object]'
178- Add-TagSource - Target $combinedTags - Source $Tags
179167$envTags = Get-Default - value $env: DAGA_POSTPROVISION_TAGS - fallback $null
180- if (-not [string ]::IsNullOrWhiteSpace($envTags )) { Add-TagSource - Target $combinedTags - Source $envTags }
181- Add-TagSource - Target $combinedTags - Source $paramTags
182- $tagArray = ConvertTo-TagArray - tagInput ($combinedTags.ToArray ())
168+
169+ # Filter out null/whitespace entries so empty values don't short-circuit the priority chain
170+ $Tags = @ ($Tags | Where-Object { -not [string ]::IsNullOrWhiteSpace($_ ) })
171+ $paramTags = @ (if ($paramTags ) { $paramTags | Where-Object { -not [string ]::IsNullOrWhiteSpace($_ ) } })
172+
173+ # Priority chain: CLI -Tags > DAGA_POSTPROVISION_TAGS env var > bicep dagaTags param > fallback
174+ if ($Tags.Count -gt 0 ) {
175+ $tagArray = ConvertTo-TagArray - tagInput $Tags
176+ } elseif (-not [string ]::IsNullOrWhiteSpace($envTags )) {
177+ $tagArray = ConvertTo-TagArray - tagInput $envTags
178+ } elseif ($paramTags.Count -gt 0 ) {
179+ $tagArray = ConvertTo-TagArray - tagInput $paramTags
180+ } else {
181+ $tagArray = ConvertTo-TagArray - tagInput $null
182+ }
183183$connectM365 = $ConnectM365.IsPresent
184184if (-not $connectM365 -and $env: DAGA_POSTPROVISION_CONNECT_M365 ) {
185185 [bool ]::TryParse($env: DAGA_POSTPROVISION_CONNECT_M365 , [ref ]$connectM365 ) | Out-Null
0 commit comments