Skip to content

Commit 9fb289c

Browse files
author
Mike Swantek
committed
Update pre-provision failover from bash to posh
1 parent cca1768 commit 9fb289c

3 files changed

Lines changed: 111 additions & 1 deletion

File tree

azure.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ hooks:
1818
# Integrated preprovision:
1919
# - Runs AI Landing Zone preprovision to generate deploy/ files and Template Specs
2020
# - Ensures our wrapper points to deploy/main.bicep (Template Spec-based) to avoid ARM 4MB template limit
21-
# On Windows, `shell: sh` may not be available; fall back to the PowerShell script.
21+
# On Windows, `shell: sh` may not be available; the PowerShell script is a fallback.
2222
- shell: sh
2323
run: ./scripts/preprovision-integrated.sh
2424
interactive: false

scripts/preprovision-integrated.ps1

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,74 @@ Write-Host " AI Landing Zone - Integrated Preprovision" -ForegroundColor Cyan
1717
Write-Host "================================================" -ForegroundColor Cyan
1818
Write-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+
2088
function Resolve-AzdEnvironmentValues {
2189
param(
2290
[string]$Location,
@@ -192,6 +260,13 @@ if ($wrapperContent -match $pattern) {
192260

193261
Write-Host ""
194262
Write-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+
195270
Write-Host ""
196271
Write-Host " Template Specs created in resource group: $ResourceGroup" -ForegroundColor White
197272
Write-Host " Deploy directory with Template Spec references ready" -ForegroundColor White

scripts/preprovision-integrated.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,32 @@ echo ""
1818
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
1919
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
2020

21+
# Marker to indicate preprovision succeeded for the currently selected azd environment.
22+
ENV_NAME="${AZURE_ENV_NAME:-}"
23+
if [ -z "$ENV_NAME" ] && command -v azd >/dev/null 2>&1; then
24+
ENV_NAME="$(azd env get-value AZURE_ENV_NAME 2>/dev/null || true)"
25+
fi
26+
if [ -z "$ENV_NAME" ]; then
27+
ENV_NAME="default"
28+
fi
29+
MARKER_DIR="$REPO_ROOT/.azure"
30+
MARKER_PATH="$MARKER_DIR/preprovision-integrated.${ENV_NAME}.ok"
31+
32+
already_complete() {
33+
local deploy_dir="$REPO_ROOT/submodules/ai-landing-zone/bicep/deploy"
34+
local wrapper_path="$REPO_ROOT/infra/main.bicep"
35+
[ -f "$MARKER_PATH" ] || return 1
36+
[ -d "$deploy_dir" ] || return 1
37+
[ -f "$wrapper_path" ] || return 1
38+
grep -q "/bicep/deploy/main.bicep" "$wrapper_path" || return 1
39+
return 0
40+
}
41+
42+
if already_complete; then
43+
echo "[i] Preprovision already completed by prior step; skipping."
44+
exit 0
45+
fi
46+
2147
# Try to populate AZURE_* variables from the currently selected azd environment
2248
if [ -z "${AZURE_LOCATION}" ] || [ -z "${AZURE_RESOURCE_GROUP}" ] || [ -z "${AZURE_SUBSCRIPTION_ID}" ]; then
2349
if command -v azd >/dev/null 2>&1; then
@@ -112,6 +138,15 @@ else
112138
echo " [!] Warning: Wrapper file not found at $WRAPPER_PATH"
113139
fi
114140

141+
# Write success marker (gitignored) so the PowerShell preprovision hook can no-op.
142+
mkdir -p "$MARKER_DIR"
143+
{
144+
echo "timestamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
145+
echo "location=${AZURE_LOCATION}"
146+
echo "resourceGroup=${AZURE_RESOURCE_GROUP}"
147+
echo "subscriptionId=${AZURE_SUBSCRIPTION_ID}"
148+
} > "$MARKER_PATH"
149+
115150
echo ""
116151
echo "[OK] Preprovision complete!"
117152
echo ""

0 commit comments

Comments
 (0)