Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Prepare Azure environments for new workloads—subscriptions, networking, identity, and landing zones
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/azure-context.md
1# Azure Context (Subscription & Location)23Detect and confirm Azure subscription and location before generating artifacts. Run region capacity check for customer selected location45---67## Step 1: Check for Existing AZD Environment89If the project already uses AZD, check for an existing environment with values already set:1011```bash12azd env list13```1415**If an environment is selected** (marked with `*`), check its values:1617```bash18azd env get-values19```2021If `AZURE_SUBSCRIPTION_ID` and `AZURE_LOCATION` are already set, use `ask_user` to confirm reuse:2223```24Question: "I found an existing AZD environment with these settings. Would you like to continue with them?"2526Environment: {env-name}27Subscription: {subscription-name} ({subscription-id})28Location: {location}2930Choices: [31"Yes, use these settings (Recommended)",32"No, let me choose different settings"33]34```3536If user confirms → skip to **Record in Plan**. Otherwise → continue to Step 2.3738---3940## Step 2: Detect Defaults4142Check for user-configured defaults:4344```bash45azd config get defaults46```4748Returns JSON with any configured defaults:49```json50{51"subscription": "25fd0362-aa79-488b-b37b-d6e892009fdf",52"location": "eastus2"53}54```5556Use these as **recommended** values if present.5758If no defaults, fall back to az CLI:59```bash60az account show --query "{name:name, id:id}" -o json61```6263## Step 3: Confirm Subscription with User6465Use `ask_user` with the **actual subscription name and ID**:6667✅ **Correct:**68```69Question: "Which Azure subscription would you like to deploy to?"70Choices: [71"Use current: jongdevdiv (25fd0362-aa79-488b-b37b-d6e892009fdf) (Recommended)",72"Let me specify a different subscription"73]74```7576❌ **Wrong** (never do this):77```78Choices: [79"Use default subscription", // ← Does not show actual name80"Let me specify"81]82```8384If user wants a different subscription:85```bash86az account list --output table87```8889---9091## Step 4: Confirm Location with User92931. Consult [Region Availability](region-availability.md) for services with limited availability942. Present only regions that support ALL selected services953. Use `ask_user`:964. After customer selected region, do provisioning limit check, consult [Resource Limits and Quotas](resources-limits-quotas.md). For this also invoke azure-quotas9798```99Question: "Which Azure region would you like to deploy to?"100Based on your architecture ({list services}), these regions support all services:101Choices: [102"eastus2 (Recommended)",103"westus2",104"westeurope"105]106```107108⚠️ Do NOT include regions that don't support all services — deployment will fail.109110---111## Step 5: Check Resource Provisioning Limits1121131. **List resource types and quantities** that will be deployed from the planned architecture (e.g., 2x Standard D4s v3 VMs, 1x VNet, 3x Storage Accounts)1141152. **Determine limits for each resource type** using the user-selected subscription and region:116- Reference [./resources-limits-quotas.md](./resources-limits-quotas.md) for documented limits117- Use **azure-quotas** skill to check current quotas and usage for the selected subscription and region118- If `az quota list` returns `BadRequest` error, the resource provider doesn't support quota API1191203. **For resources that don't support quota API** (e.g., Microsoft.DocumentDB, or when you get `BadRequest` from `az quota list`):121- Invoke **azure-resource-lookup** skill to count existing deployments of that resource type in the selected subscription and region122- Use the count to calculate: `Total After Deployment = Current Count + Planned Deployment`123- Reference [Azure service limits documentation](https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/azure-subscription-service-limits) for the limit value124- Document in provisioning checklist as "Fetched from: azure-resource-lookup + Official docs"1251264. **Validate deployment capacity**:127- Compare planned deployment quantities against available quota (limit - current usage)128- If **insufficient capacity** is found, notify the customer and return to **Step 4** to select a different region129- Use **azure-quotas** skill to compare capacity across multiple regions and recommend alternatives130131## Record in Plan132133After confirmation, record in `.azure/deployment-plan.md`:134135```markdown136## Azure Context137- **Subscription**: jongdevdiv (25fd0362-aa79-488b-b37b-d6e892009fdf)138- **Location**: eastus2139```140141---142143## Step 6: Apply to AZD Environment144145> **⛔ CRITICAL for Aspire and azd projects**: After user confirms subscription and location, you **MUST** set these values in the azd environment immediately after running `azd init` or `azd env new`. Always use `--no-prompt` with these commands to prevent interactive prompts from blocking execution.146>147> **DO NOT** wait until validation or deployment. The Azure CLI and azd maintain separate configuration contexts.148149**For Aspire projects using `azd init --from-code`:**150151```bash152# 1. Run azd init153azd init --from-code -e <environment-name> --no-prompt154155# 2. IMMEDIATELY set the user-confirmed subscription156azd env set AZURE_SUBSCRIPTION_ID <subscription-id>157158# 3. Set the location159azd env set AZURE_LOCATION <location>160161# 4. Verify162azd env get-values163```164165**For non-Aspire projects using `azd env new`:**166167```bash168# 1. Create environment169azd env new <environment-name> --no-prompt170171# 2. IMMEDIATELY set the user-confirmed subscription172azd env set AZURE_SUBSCRIPTION_ID <subscription-id>173174# 3. Set the location175azd env set AZURE_LOCATION <location>176177# 4. Verify178azd env get-values179```180181**Why this is critical:**182- `az account show` returns the Azure CLI's default subscription183- `azd` maintains its own configuration with potentially different defaults184- If you don't set `AZURE_SUBSCRIPTION_ID` explicitly, azd will use its own default185- This can result in deploying to the wrong subscription despite user confirmation186