@@ -17,6 +17,74 @@ Write-Host " AI Landing Zone - Integrated Preprovision" -ForegroundColor Cyan
1717Write-Host " ================================================" - ForegroundColor Cyan
1818Write-Host " "
1919
20+ function Get-PreprovisionMarkerPath {
21+ param (
22+ [string ]$RepoRoot
23+ )
24+
25+ $envName = $env: AZURE_ENV_NAME
26+ if ([string ]::IsNullOrWhiteSpace($envName )) {
27+ try { $envName = (& azd env get-value AZURE_ENV_NAME 2> $null ).ToString().Trim() } catch { $envName = $null }
28+ }
29+ if ([string ]::IsNullOrWhiteSpace($envName )) { $envName = ' default' }
30+
31+ $azureDir = Join-Path $RepoRoot ' .azure'
32+ return Join-Path $azureDir (" preprovision-integrated.$envName .ok" )
33+ }
34+
35+ function Test-PreprovisionAlreadyComplete {
36+ param (
37+ [string ]$RepoRoot
38+ )
39+
40+ $markerPath = Get-PreprovisionMarkerPath - RepoRoot $RepoRoot
41+ if (-not (Test-Path $markerPath )) { return $false }
42+
43+ $deployDir = Join-Path $RepoRoot ' submodules' ' ai-landing-zone' ' bicep' ' deploy'
44+ if (-not (Test-Path $deployDir )) { return $false }
45+
46+ $wrapperPath = Join-Path $RepoRoot ' infra' ' main.bicep'
47+ if (-not (Test-Path $wrapperPath )) { return $false }
48+
49+ try {
50+ $wrapperContent = Get-Content $wrapperPath - Raw
51+ if ($wrapperContent -notmatch ' /bicep/deploy/main\.bicep' ) { return $false }
52+ } catch {
53+ return $false
54+ }
55+
56+ return $true
57+ }
58+
59+ function Write-PreprovisionMarker {
60+ param (
61+ [string ]$RepoRoot ,
62+ [string ]$Location ,
63+ [string ]$ResourceGroup ,
64+ [string ]$SubscriptionId
65+ )
66+
67+ $markerPath = Get-PreprovisionMarkerPath - RepoRoot $RepoRoot
68+ $markerDir = Split-Path - Parent $markerPath
69+ if (-not (Test-Path $markerDir )) {
70+ New-Item - ItemType Directory - Path $markerDir - Force | Out-Null
71+ }
72+
73+ $stamp = (Get-Date ).ToString(' s' )
74+ @ (
75+ " timestamp=$stamp " ,
76+ " location=$Location " ,
77+ " resourceGroup=$ResourceGroup " ,
78+ " subscriptionId=$SubscriptionId "
79+ ) | Set-Content - Path $markerPath - Encoding UTF8
80+ }
81+
82+ $repoRootResolved = (Resolve-Path (Join-Path $PSScriptRoot ' ..' )).Path
83+ if (Test-PreprovisionAlreadyComplete - RepoRoot $repoRootResolved ) {
84+ Write-Host " [i] Preprovision already completed by prior step; skipping PowerShell fallback." - ForegroundColor Yellow
85+ exit 0
86+ }
87+
2088function Resolve-AzdEnvironmentValues {
2189 param (
2290 [string ]$Location ,
@@ -192,6 +260,13 @@ if ($wrapperContent -match $pattern) {
192260
193261Write-Host " "
194262Write-Host " [OK] Preprovision complete!" - ForegroundColor Green
263+
264+ try {
265+ Write-PreprovisionMarker - RepoRoot $repoRootResolved - Location $Location - ResourceGroup $ResourceGroup - SubscriptionId $SubscriptionId
266+ } catch {
267+ # Best-effort marker. Ignore failures so we don't block provisioning.
268+ }
269+
195270Write-Host " "
196271Write-Host " Template Specs created in resource group: $ResourceGroup " - ForegroundColor White
197272Write-Host " Deploy directory with Template Spec references ready" - ForegroundColor White
0 commit comments