Skip to content

Commit 0974468

Browse files
committed
fix: correct region array syntax in randomize scripts
- Improve existence check to properly handle missing vs empty AZURE_LOCATION
1 parent cacdb72 commit 0974468

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

scripts/randomize-region.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
# Check if AZURE_LOCATION is already set
66
$existingLocation = azd env get-value AZURE_LOCATION 2>$null
7+
$locationExists = $LASTEXITCODE -eq 0
78

8-
if ($existingLocation) {
9+
if ($locationExists -and $existingLocation) {
910
Write-Host "ℹ️ AZURE_LOCATION is already set to: $existingLocation" -ForegroundColor Cyan
1011
Write-Host " Keeping existing location. To change, run: azd env set AZURE_LOCATION <region>" -ForegroundColor Gray
1112
} else {
13+
# Variable doesn't exist or is empty - randomize
1214
$regions = @("westus2", "westus3", "eastus2", "northcentralus")
1315
$selectedRegion = Get-Random -InputObject $regions
1416

scripts/randomize-region.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,26 @@
44
# without being prompted. Otherwise, azd will prompt you to select a region.
55

66
# Check if AZURE_LOCATION is already set
7-
EXISTING_LOCATION=$(azd env get-value AZURE_LOCATION 2>/dev/null)
7+
if azd env get-value AZURE_LOCATION >/dev/null 2>&1; then
8+
EXISTING_LOCATION=$(azd env get-value AZURE_LOCATION 2>/dev/null)
9+
if [ -n "$EXISTING_LOCATION" ]; then
10+
echo "ℹ️ AZURE_LOCATION is already set to: $EXISTING_LOCATION"
11+
echo " Keeping existing location. To change, run: azd env set AZURE_LOCATION <region>"
12+
else
13+
# Variable exists but is empty - randomize
14+
REGIONS=("westus2" "westus3" "eastus2" "northcentralus")
15+
RANDOM_INDEX=$((RANDOM % 4))
16+
SELECTED_REGION="${REGIONS[$RANDOM_INDEX]}"
817

9-
if [ -n "$EXISTING_LOCATION" ]; then
10-
echo "ℹ️ AZURE_LOCATION is already set to: $EXISTING_LOCATION"
11-
echo " Keeping existing location. To change, run: azd env set AZURE_LOCATION <region>"
18+
echo "🎲 Randomly selected region: $SELECTED_REGION"
19+
azd env set AZURE_LOCATION "$SELECTED_REGION"
20+
echo "✅ Region set. Run 'azd provision' to deploy without being prompted."
21+
echo " To change: azd env set AZURE_LOCATION <region>"
22+
fi
1223
else
13-
REGIONS=("westus2" "westus3" "eastus2", "northcentralus")
14-
RANDOM_INDEX=$((RANDOM % 3))
24+
# Variable doesn't exist - randomize
25+
REGIONS=("westus2" "westus3" "eastus2" "northcentralus")
26+
RANDOM_INDEX=$((RANDOM % 4))
1527
SELECTED_REGION="${REGIONS[$RANDOM_INDEX]}"
1628

1729
echo "🎲 Randomly selected region: $SELECTED_REGION"

0 commit comments

Comments
 (0)