Skip to content

Commit 4402d22

Browse files
author
Jian Wu
committed
fix: separate model deployment location from resource group location
Introduce AZURE_AI_DEPLOYMENTS_LOCATION env var to decouple model/project deployment location from the resource group location (AZURE_LOCATION). When a user selects a model from a different region during init, only AZURE_AI_DEPLOYMENTS_LOCATION is updated, preserving AZURE_LOCATION for the resource group. This prevents provisioning failures when the Foundry project and resource group are in different regions. Fixes #7670 Supersedes #7873
1 parent f878993 commit 4402d22

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

‎cli/azd/extensions/azure.ai.agents/internal/cmd/init_foundry_resources_helpers.go‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,18 @@ func loadAzureContext(
661661
envValueMap[value.Key] = value.Value
662662
}
663663

664+
// Prefer AZURE_AI_DEPLOYMENTS_LOCATION for model/project operations;
665+
// fall back to AZURE_LOCATION for backward compatibility.
666+
location := envValueMap["AZURE_AI_DEPLOYMENTS_LOCATION"]
667+
if location == "" {
668+
location = envValueMap["AZURE_LOCATION"]
669+
}
670+
664671
return &azdext.AzureContext{
665672
Scope: &azdext.AzureScope{
666673
TenantId: envValueMap["AZURE_TENANT_ID"],
667674
SubscriptionId: envValueMap["AZURE_SUBSCRIPTION_ID"],
668-
Location: envValueMap["AZURE_LOCATION"],
675+
Location: location,
669676
},
670677
Resources: []string{},
671678
}, nil
@@ -774,7 +781,7 @@ func ensureLocation(
774781
}
775782
if azureContext.Scope.Location != "" {
776783
fmt.Printf("%s", output.WithWarningFormat(
777-
"The current AZURE_LOCATION '%s' is not supported for this agent setup. Please choose a different location.\n",
784+
"The current location '%s' is not supported for this agent setup. Please choose a different location.\n",
778785
azureContext.Scope.Location,
779786
))
780787
azureContext.Scope.Location = ""
@@ -789,7 +796,13 @@ func ensureLocation(
789796

790797
azureContext.Scope.Location = locationName
791798

792-
return setEnvValue(ctx, azdClient, envName, "AZURE_LOCATION", azureContext.Scope.Location)
799+
// Set both AZURE_LOCATION (resource group) and AZURE_AI_DEPLOYMENTS_LOCATION (model/project resources)
800+
// to the same value by default. AZURE_AI_DEPLOYMENTS_LOCATION can be changed independently later
801+
// (e.g. during model selection) without affecting the resource group location.
802+
if err := setEnvValue(ctx, azdClient, envName, "AZURE_LOCATION", azureContext.Scope.Location); err != nil {
803+
return err
804+
}
805+
return setEnvValue(ctx, azdClient, envName, "AZURE_AI_DEPLOYMENTS_LOCATION", azureContext.Scope.Location)
793806
}
794807

795808
// ensureSubscriptionAndLocation ensures both subscription and location are set.
@@ -1148,6 +1161,13 @@ func selectFoundryProject(
11481161

11491162
// Set location from the selected project
11501163
azureContext.Scope.Location = selectedProject.Location
1164+
if err := setEnvValue(ctx, azdClient, envName, "AZURE_AI_DEPLOYMENTS_LOCATION", selectedProject.Location); err != nil {
1165+
return nil, fmt.Errorf("failed to set AZURE_AI_DEPLOYMENTS_LOCATION: %w", err)
1166+
}
1167+
// Seed AZURE_LOCATION (used for resource group) from the project location so that
1168+
// downstream provisioning has a default. If the user already set AZURE_LOCATION to a
1169+
// different value (e.g. via `azd env set`), this will overwrite it to match the project,
1170+
// which is the correct behavior since the resource group should be co-located.
11511171
if err := setEnvValue(ctx, azdClient, envName, "AZURE_LOCATION", selectedProject.Location); err != nil {
11521172
return nil, fmt.Errorf("failed to set AZURE_LOCATION: %w", err)
11531173
}

‎cli/azd/extensions/azure.ai.agents/internal/cmd/init_models.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ func (a *modelSelector) updateEnvLocation(ctx context.Context, selectedLocation
8282

8383
_, err := a.azdClient.Environment().SetValue(ctx, &azdext.SetEnvRequest{
8484
EnvName: envName,
85-
Key: "AZURE_LOCATION",
85+
Key: "AZURE_AI_DEPLOYMENTS_LOCATION",
8686
Value: selectedLocation,
8787
})
8888
if err != nil {
89-
return fmt.Errorf("failed to update AZURE_LOCATION in azd environment: %w", err)
89+
return fmt.Errorf("failed to update AZURE_AI_DEPLOYMENTS_LOCATION in azd environment: %w", err)
9090
}
9191

9292
if a.azureContext == nil {
@@ -97,7 +97,7 @@ func (a *modelSelector) updateEnvLocation(ctx context.Context, selectedLocation
9797
}
9898
a.azureContext.Scope.Location = selectedLocation
9999

100-
fmt.Println(output.WithSuccessFormat("Updated AZURE_LOCATION to '%s' in your azd environment.", selectedLocation))
100+
fmt.Println(output.WithSuccessFormat("Updated AZURE_AI_DEPLOYMENTS_LOCATION to '%s' in your azd environment.", selectedLocation))
101101
return nil
102102
}
103103

0 commit comments

Comments
 (0)