Skip to content

Add resource group location mismatch preflight check (azure.ai.agents)#9007

Open
vhvb1989 wants to merge 1 commit into
mainfrom
vhvb1989/agents-preflight-rg-location
Open

Add resource group location mismatch preflight check (azure.ai.agents)#9007
vhvb1989 wants to merge 1 commit into
mainfrom
vhvb1989/agents-preflight-rg-location

Conversation

@vhvb1989

@vhvb1989 vhvb1989 commented Jul 7, 2026

Copy link
Copy Markdown
Member

What

Adds a local-preflight validation check to the azure.ai.agents extension that detects an immutable resource-group region conflict before provisioning and stops azd with a clear note + remediation suggestion.

This is the #1 production ARM error (InvalidResourceGroupLocation, 87 operations in the top-5 report): a subscription-scoped Bicep deployment fails because the target resource group already exists in a different region than AZURE_LOCATION. A resource group's region cannot be changed, so proceeding is a guaranteed failure — the check is a blocking Error, surfaced during azd's validation phase instead of at deploy time.

How

  • New internal/project/resource_group_location_check.goResourceGroupLocationCheck implementing azdext.ValidationCheckProvider.
  • Registered in internal/cmd/listen.go via the extension WithValidationCheck capability (CheckType: local-preflight, RuleID: resource_group_location_mismatch), matching the demo extension pattern.
  • Reads AZURE_LOCATION (prefers ValidationContext.EnvLocation()), AZURE_SUBSCRIPTION_ID, AZURE_RESOURCE_GROUP (fallback rg-{env}); resolves credential via LookupTenantAzureDeveloperCLICredential; GETs the resource group and compares regions (case-insensitive).
  • Best-effort / non-blocking: skips silently on missing env values, auth failure, a 404 (RG not created yet), or any API error — it never blocks validation itself. Only a definitive mismatch emits a blocking result.
  • Unit tests for the pure comparison/message logic.

What the user sees

Resource group "rg-myenv-abc123" already exists in region "eastus", but AZURE_LOCATION is set to "westus2". A resource group's region cannot be changed, so provisioning would fail with the ARM error "InvalidResourceGroupLocation".

…with a suggestion offering 3 remediation paths (azd env set AZURE_LOCATION, a different resource group, or az group delete).

Testing

go build, go test ./internal/project ./internal/cmd, go vet, golangci-lint (0 issues), gofmt, cspell — all pass. Repro steps to see azd stop with the note + suggestion are in the linked issue.

Fixes #9006
Part of #9005

Adds a local-preflight validation check to the azure.ai.agents extension that
detects an immutable resource-group region conflict before provisioning. When
the target resource group already exists in a different region than
AZURE_LOCATION, the subscription-scoped Bicep deployment fails with the ARM
error "InvalidResourceGroupLocation" (the #1 production error). This check
surfaces the conflict during azd's validation phase with a clear message and
remediation guidance instead of a slow deploy-time failure.

Registered via the extension WithValidationCheck capability
(RuleID resource_group_location_mismatch, severity Error). The check is
best-effort: it skips silently on missing env values, auth failures, a 404
(resource group not created yet), or any API error.

Fixes #9006

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

📋 Prioritization Note

Thanks for the contribution! The linked issue isn't in the current milestone yet.
Thank you for logging this issue; our team is reviewing it. If you need urgent prioritization, tag @RickWinter and @kristenwomack to let us know.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a best-effort local-preflight validation check to the azure.ai.agents extension that detects an immutable resource-group region conflict before provisioning. When the target resource group already exists in a region different from AZURE_LOCATION, ARM would fail a subscription-scoped deployment with InvalidResourceGroupLocation; this check surfaces a blocking error with remediation guidance during azd's validation phase instead. The check is wired via the extension WithValidationCheck capability, mirroring the existing demo-extension pattern, and is non-blocking on any resolution/auth/API failure (only a definitive mismatch blocks).

Changes:

  • New ResourceGroupLocationCheck implementing azdext.ValidationCheckProvider, resolving env values + credential and comparing the existing RG region against AZURE_LOCATION (case-insensitive).
  • Registered the check in listen.go with CheckType: local-preflight, RuleID: resource_group_location_mismatch.
  • Unit tests for the pure comparison/message logic (evaluateResourceGroupLocation).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
cli/azd/extensions/azure.ai.agents/internal/project/resource_group_location_check.go New check: reads env/context values, resolves credential, GETs the RG, and emits a blocking mismatch result with remediation guidance.
cli/azd/extensions/azure.ai.agents/internal/project/resource_group_location_check_test.go Table-style unit tests covering matching (incl. case-insensitive) and mismatching regions and the message/suggestion content.
cli/azd/extensions/azure.ai.agents/internal/cmd/listen.go Registers the new validation check with the extension host.

resourceGroup := envValue(ctx, envClient, envName, "AZURE_RESOURCE_GROUP")
if resourceGroup == "" {
// Mirror azd's default when AZURE_RESOURCE_GROUP is unset.
resourceGroup = fmt.Sprintf("rg-%s", envName)
if err != nil {
return ""
}
return resp.Value

@jongio jongio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The check logic is solid: best-effort/non-blocking pattern is correct, credential handling follows the established LookupTenant pattern used across the extension, and the pure-function separation makes the comparison testable without Azure access.

Two minor items already noted by the bot: reusing defaultResourceGroupName instead of the inline fmt.Sprintf keeps the fallback in sync with provisioning, and trimming in the package-level envValue would prevent a false-positive block if a value has stray whitespace.

@trangevi

trangevi commented Jul 7, 2026

Copy link
Copy Markdown
Member

Is it possible to do a quick evaluation of why this might be happening? Adding this preflight check doesn't actually get rid of the error, it just moves it. We should try and figure out what is actually causing this mismatch, and if there's something we can do to prevent it at the beginning.

@vhvb1989

vhvb1989 commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

Is it possible to do a quick evaluation of why this might be happening? Adding this preflight check doesn't actually get rid of the error, it just moves it. We should try and figure out what is actually causing this mismatch, and if there's something we can do to prevent it at the beginning.

It looks like this could happen for more than one single reason: #9006

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext-agents azure.ai.agents extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

azd validate (local-preflight): detect immutable resource group location mismatch (P0-1)

4 participants