@@ -45,17 +45,14 @@ function Get-TerraformStackFolders
4545 [string []]$StacksToRun
4646 )
4747
48- # ─────────────────────────────────── pre-checks ────────────────────────────
4948 if (-not (Test-Path $CodeRoot ))
5049 {
5150 _LogMessage - Level ' ERROR' - Message " Code root not found: $CodeRoot " `
5251 - InvocationName $MyInvocation.MyCommand.Name
5352 throw " Code root not found: $CodeRoot "
5453 }
5554
56- # Match folders like 0_rg or 0-rg or allstackskip_99-azdo-pipelines-setup
57- $allDirs = Get-ChildItem - Path $CodeRoot - Directory |
58- Where-Object { $_.Name -match ' ^\d+[-_].+' -or $_.Name -match ' ^allstackskip[-_].+' }
55+ $allDirs = Get-ChildItem - Path $CodeRoot - Directory
5956
6057 if (-not $allDirs )
6158 {
@@ -64,7 +61,6 @@ function Get-TerraformStackFolders
6461 throw " No stack folders found underneath $CodeRoot "
6562 }
6663
67- # ──────────────────────────── discover / index stacks ─────────────────────
6864 $stackLookup = @ { }
6965 foreach ($dir in $allDirs )
7066 {
@@ -73,25 +69,33 @@ function Get-TerraformStackFolders
7369 $stackLookup [$matches.name.ToLower ()] = @ {
7470 Path = $dir.FullName
7571 Order = [int ]$matches.order
72+ IsNumbered = $true
7673 }
7774 }
7875 elseif ($dir.Name -match ' ^allstackskip[-_](?<rest>.+)$' )
7976 {
80- # Remove leading number/underscore from rest if present
8177 $stackName = $matches.rest -replace ' ^\d+[-_]' , ' '
8278 $stackLookup [$stackName.ToLower ()] = @ {
8379 Path = $dir.FullName
8480 Order = 9999
8581 IsStackSkip = $true
82+ IsNumbered = $false
83+ }
84+ }
85+ else
86+ {
87+ $stackLookup [$dir.Name.ToLower ()] = @ {
88+ Path = $dir.FullName
89+ Order = 9999
90+ IsNumbered = $false
8691 }
8792 }
8893 }
8994
90- # ──────────────────────────── argument sanitisation ────────────────────────
9195 $requested = @ (
9296 $StacksToRun |
9397 ForEach-Object { $_.Trim () } |
94- Where-Object { $_ } # drop empty entries
98+ Where-Object { $_ }
9599 )
96100
97101 if ($requested -contains ' all' -and $requested.Count -gt 1 )
@@ -103,7 +107,6 @@ function Get-TerraformStackFolders
103107 $requested = $requested | Where-Object { $_.ToLower () -ne ' all' }
104108 }
105109
106- # ──────────────────────────── resolve stack list ───────────────────────────
107110 $result = [System.Collections.Generic.List [string ]]::new()
108111
109112 if (($requested.Count -eq 1 ) -and ($requested [0 ].ToLower() -eq ' all' ))
@@ -112,11 +115,8 @@ function Get-TerraformStackFolders
112115 - InvocationName $MyInvocation.MyCommand.Name
113116
114117 $stackLookup.GetEnumerator () |
118+ Where-Object { $_.Value.IsNumbered -eq $true -and (-not ($_.Value.PSObject.Properties [' IsStackSkip' ] -and $_.Value.IsStackSkip )) } |
115119 Sort-Object { $_.Value.Order } |
116- Where-Object {
117- $folderName = Split-Path - Path $_.Value.Path - Leaf
118- $folderName -notmatch ' ^allstackskip[-_]'
119- } |
120120 ForEach-Object { [void ]$result.Add ($_.Value.Path ) }
121121 }
122122 else
@@ -134,7 +134,6 @@ function Get-TerraformStackFolders
134134 }
135135 }
136136
137- # ────────────────────────────────── debug log ──────────────────────────────
138137 _LogMessage - Level ' DEBUG' `
139138 - Message " Stack execution order → $ ( $result -join ' , ' ) " `
140139 - InvocationName $MyInvocation.MyCommand.Name
@@ -143,6 +142,7 @@ function Get-TerraformStackFolders
143142}
144143
145144
145+
146146# ##############################################################################
147147# Run `terraform init`
148148# ##############################################################################
0 commit comments