Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -654,11 +654,18 @@ func loadAzureContext(
envValueMap[value.Key] = value.Value
}

// Use AZURE_AI_DEPLOYMENTS_LOCATION for Scope.Location (used for model filtering).
// Fall back to AZURE_LOCATION for backward compatibility with older environments.
location := envValueMap["AZURE_AI_DEPLOYMENTS_LOCATION"]
if location == "" {
location = envValueMap["AZURE_LOCATION"]
}

return &azdext.AzureContext{
Scope: &azdext.AzureScope{
TenantId: envValueMap["AZURE_TENANT_ID"],
SubscriptionId: envValueMap["AZURE_SUBSCRIPTION_ID"],
Location: envValueMap["AZURE_LOCATION"],
Location: location,
Comment on lines +657 to +668
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadAzureContext now prefers AZURE_AI_DEPLOYMENTS_LOCATION over AZURE_LOCATION. This is behaviorally significant for model filtering and project selection; there don’t appear to be unit tests covering the precedence/fallback behavior. Consider adding tests for (1) AI var set, (2) only AZURE_LOCATION set (back-compat), and (3) neither set.

Copilot uses AI. Check for mistakes.
},
Resources: []string{},
}, nil
Expand Down Expand Up @@ -728,7 +735,9 @@ func ensureSubscription(
}

// ensureLocation prompts for an Azure location if not already set in the AzureContext.
// Both init flows use this.
// Both init flows use this. Sets both AZURE_LOCATION (resource group) and
// AZURE_AI_DEPLOYMENTS_LOCATION (AI/model resources) to the same value as a default.
// If the user later picks a different model region, only AZURE_AI_DEPLOYMENTS_LOCATION changes.
func ensureLocation(
ctx context.Context,
azdClient *azdext.AzdClient,
Expand All @@ -738,7 +747,8 @@ func ensureLocation(
allowedLocations := supportedRegionsForInit()

if azureContext.Scope.Location != "" && locationAllowed(azureContext.Scope.Location, allowedLocations) {
return nil
// Location already set and valid — ensure AZURE_AI_DEPLOYMENTS_LOCATION is also set
return setEnvValue(ctx, azdClient, envName, "AZURE_AI_DEPLOYMENTS_LOCATION", azureContext.Scope.Location)
Comment on lines 749 to +751
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the early-return path, azureContext.Scope.Location may have come from AZURE_AI_DEPLOYMENTS_LOCATION (via loadAzureContext). If AZURE_LOCATION is currently unset, this returns without seeding it, leaving the resource group location missing. Consider reading current env values and setting AZURE_LOCATION only when it is empty, while also ensuring AZURE_AI_DEPLOYMENTS_LOCATION is set when empty (without overwriting an existing, user-chosen RG location).

Copilot uses AI. Check for mistakes.
}
if azureContext.Scope.Location != "" {
fmt.Printf("%s", output.WithWarningFormat(
Expand All @@ -757,7 +767,11 @@ func ensureLocation(

azureContext.Scope.Location = locationName

return setEnvValue(ctx, azdClient, envName, "AZURE_LOCATION", azureContext.Scope.Location)
if err := setEnvValue(ctx, azdClient, envName, "AZURE_LOCATION", azureContext.Scope.Location); err != nil {
return err
}

return setEnvValue(ctx, azdClient, envName, "AZURE_AI_DEPLOYMENTS_LOCATION", azureContext.Scope.Location)
}

// ensureSubscriptionAndLocation ensures both subscription and location are set.
Expand Down Expand Up @@ -1085,10 +1099,22 @@ func selectFoundryProject(

selectedProject := projects[selectedIdx]

// Set location from the selected project
// Set AI deployments location from the selected project.
// The project's location determines where AI models and resources are deployed.
previousLocation := azureContext.Scope.Location
azureContext.Scope.Location = selectedProject.Location
if err := setEnvValue(ctx, azdClient, envName, "AZURE_LOCATION", selectedProject.Location); err != nil {
return nil, fmt.Errorf("failed to set AZURE_LOCATION: %w", err)
if err := setEnvValue(
ctx, azdClient, envName, "AZURE_AI_DEPLOYMENTS_LOCATION", selectedProject.Location,
); err != nil {
return nil, fmt.Errorf("failed to set AZURE_AI_DEPLOYMENTS_LOCATION: %w", err)
}

// Seed AZURE_LOCATION (resource group location) if not already set.
// Default to co-locating with the project; user can override before deploying.
if previousLocation == "" {
if err := setEnvValue(ctx, azdClient, envName, "AZURE_LOCATION", selectedProject.Location); err != nil {
return nil, fmt.Errorf("failed to set AZURE_LOCATION: %w", err)
}
Comment on lines +1102 to +1117
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previousLocation := azureContext.Scope.Location is tracking the AI deployments location (per loadAzureContext), not whether AZURE_LOCATION (resource group location) is set. If an environment has AZURE_AI_DEPLOYMENTS_LOCATION set but AZURE_LOCATION unset, this block will skip seeding AZURE_LOCATION, leaving it missing. Consider checking the actual AZURE_LOCATION env value (e.g., via Environment().GetValue/GetValues) before deciding whether to set it.

Copilot uses AI. Check for mistakes.
}

// Configure all Foundry project environment variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ func (a *modelSelector) updateEnvLocation(ctx context.Context, selectedLocation

_, err := a.azdClient.Environment().SetValue(ctx, &azdext.SetEnvRequest{
EnvName: envName,
Key: "AZURE_LOCATION",
Key: "AZURE_AI_DEPLOYMENTS_LOCATION",
Value: selectedLocation,
})
if err != nil {
return fmt.Errorf("failed to update AZURE_LOCATION in azd environment: %w", err)
return fmt.Errorf("failed to update AZURE_AI_DEPLOYMENTS_LOCATION in azd environment: %w", err)
}

if a.azureContext == nil {
Expand All @@ -98,7 +98,9 @@ func (a *modelSelector) updateEnvLocation(ctx context.Context, selectedLocation
}
a.azureContext.Scope.Location = selectedLocation

fmt.Println(output.WithSuccessFormat("Updated AZURE_LOCATION to '%s' in your azd environment.", selectedLocation))
fmt.Println(output.WithSuccessFormat(
"Updated AZURE_AI_DEPLOYMENTS_LOCATION to '%s' in your azd environment.", selectedLocation,
))
Comment on lines 84 to +103
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateEnvLocation now updates AZURE_AI_DEPLOYMENTS_LOCATION instead of AZURE_LOCATION, and also mutates a.azureContext.Scope.Location. There are unit tests in this package but none covering this env update path; consider adding a test to verify the correct key is written and that the in-memory AzureContext is updated accordingly.

Copilot uses AI. Check for mistakes.
return nil
}

Expand Down
Loading