Skip to content

Commit 27f7af8

Browse files
committed
feat: add randomized region selection for azd deployments
- Add preprovision hook to automatically select random region - Create randomize-region scripts for both bash and PowerShell - Limit allowed regions in main.bicep - Hook runs before provisioning to set AZURE_LOCATION env var
1 parent 310ef44 commit 27f7af8

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

azure.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ services:
1010
host: function
1111

1212
hooks:
13-
# preprovision:
14-
# posix:
15-
# shell: sh
16-
# run: ./scripts/setup-app-registration.sh
17-
# interactive: false
18-
# continueOnError: false
19-
# windows:
20-
# shell: pwsh
21-
# run: ./scripts/setup-app-registration.ps1
22-
# interactive: false
23-
# continueOnError: false
13+
preprovision:
14+
posix:
15+
shell: sh
16+
run: ./scripts/randomize-region.sh
17+
interactive: false
18+
continueOnError: false
19+
windows:
20+
shell: pwsh
21+
run: ./scripts/randomize-region.ps1
22+
interactive: false
23+
continueOnError: false
2424
postprovision:
2525
windows:
2626
shell: pwsh

infra/main.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ param environmentName string
77

88
@minLength(1)
99
@description('Primary location for all resources')
10-
@allowed([ 'westus2', 'westus3', 'eastus2'])
10+
@allowed([ 'westus2', 'westus3', 'eastus2', 'northcentralus'])
1111
@metadata({
1212
azd: {
1313
type: 'location'

scripts/randomize-region.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Randomly select one of the allowed regions and set it as the default
2+
# Run this script before 'azd provision' or 'azd up' to use a random region
3+
# without being prompted. Otherwise, azd will prompt you to select a region.
4+
5+
$regions = @("westus2", "westus3", "eastus2", "northcentralus")
6+
$selectedRegion = Get-Random -InputObject $regions
7+
8+
Write-Host "🎲 Randomly selected region: $selectedRegion" -ForegroundColor Green
9+
azd env set AZURE_LOCATION $selectedRegion
10+
Write-Host "✅ Region set. Run 'azd provision' to deploy without being prompted." -ForegroundColor Green
11+
Write-Host " To change: azd env set AZURE_LOCATION <region>" -ForegroundColor Gray

scripts/randomize-region.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
# Randomly select one of the allowed regions and set it as the default
3+
# Run this script before 'azd provision' or 'azd up' to use a random region
4+
# without being prompted. Otherwise, azd will prompt you to select a region.
5+
6+
REGIONS=("westus2" "westus3" "eastus2", "northcentralus")
7+
RANDOM_INDEX=$((RANDOM % 3))
8+
SELECTED_REGION="${REGIONS[$RANDOM_INDEX]}"
9+
10+
echo "🎲 Randomly selected region: $SELECTED_REGION"
11+
azd env set AZURE_LOCATION "$SELECTED_REGION"
12+
echo "✅ Region set. Run 'azd provision' to deploy without being prompted."
13+
echo " To change: azd env set AZURE_LOCATION <region>"

0 commit comments

Comments
 (0)