Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 23, 2025

Summary

This PR implements support for selecting existing Azure resource groups during Aspire provisioning, addressing issue #12084. The implementation features an improved UX flow where resource group selection comes before location selection, and location is only prompted when creating a new resource group.

Changes Made

  • Add method to IArmClient for fetching available resource groups from a subscription
  • Implement resource group fetching in DefaultArmClientProvider with location information
  • Add TryGetResourceGroupsAsync and TryGetResourceGroupsWithLocationAsync methods to BaseProvisioningContextProvider
  • Implement improved UX flow: Resource group selection before location selection
  • Update RunModeProvisioningContextProvider to display resource groups in dropdown with dynamic loading and automatic location selection
  • Update PublishModeProvisioningContextProvider to show separate dialogs for resource group and location
  • Add localization strings for resource group selection UI
  • Update test helpers (TestArmClient) to implement new interface methods
  • Add test for GetAvailableResourceGroupsAsync functionality
  • Update all tests to reflect new UX flow and input type changes
  • Build and test all changes successfully

Key Features

  1. Improved UX Flow: Resource group selection is prompted first, followed by location only when needed
  2. Smart Location Selection: When selecting an existing resource group, its location is automatically used without prompting
  3. New Resource Groups: Location is only prompted when creating a new resource group (custom name entered)
  4. Dynamic Resource Group Selection: Users can select from existing resource groups in their subscription or enter a new name
  5. RunMode: Resource groups are shown in a dropdown with dynamic loading; location input adapts based on selection
  6. PublishMode: Separate dialogs for resource group selection and location (only for new groups)
  7. Backward Compatible: Existing functionality for auto-generating or specifying resource group names is preserved
  8. AllowCustomChoice: Users can still create new resource groups by entering a custom name

Testing

  • All 12 ProvisioningContextProviderTests pass successfully
  • All 13 AzureDeployerTests pass successfully
  • Tests updated to reflect new UX flow (resource group before location)
  • New test added for GetAvailableResourceGroupsAsync
  • No regressions found in related test suites

Fixes #11037

Original prompt

This section details on the original issue you should resolve

<issue_title>Support modeling Azure resource groups as Aspire resources</issue_title>
<issue_description>from issue: Azure/azure-dev#3550

Publishing Aspire to a Resource Group instead of to a Subscription is something that people would need to model in the AppHost. Similar to how people can model the Azure Container Environment, people should be able to target one specific RG to be created or to re-use.

</issue_description>

<agent_instructions>I think we should just let you pick an existing resource group or make a new one.

Both RunModeProvisioningContextProvider and PublishModeProvisioningContextProvider should show the subscription's resource groups and allow you to choose one or enter a new one.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@davidfowl More details? Deploying to an existing rg? @vhvb1989 Either to an existing RG or to a new RG which you can define in your apphost.

You could, for example, define one parameter and use it for selecting a rg. Azd would use that to list rg from your subscription and let users pick one to publish your app.

This is supported by azd, just need to be modeled in Aspire. Then azd would create a main.bicep scoped to rg deployment </comment_new>
<comment_new>@davidfowl
@vhvb1989 Currently azd owns the resource group generation when using azd (main.bicep). Wouldn't this still be part of azd?

For aspire deploy/publish, this should be possible to change in the apphost.</comment_new>
<comment_new>@vhvb1989
@davidfowl , yes, azd is providing a default resource group. However, what I am trying to avoid is introducing an azd-way to customize the resource group. Instead, whatever you make in the AppHost to customize your resource group should be understandable for Aspire deploy/publish as well as azd. </comment_new>
<comment_new>@davidfowl
cc @captainsafia </comment_new>
<comment_new>@captainsafia
We've talked about supporting this by modeling the resource group as a distinct resource in the application model that we can emit a Bicep template for.

When we do this, we'll need to rework aspects of our Bicep provisioning since the logic (like azd) currently assumes that the creation and customization of resource groups is owned by the deployment logic and not the Aspire app model.</comment_new>
<comment_new>@davidfowl
You can already use resources from different resource groups but you can't deploy resources in different resource groups.</comment_new>
<comment_new>@davidfowl
In the short term no, we're not optimizing for deploying to multiple resource groups. We're trying to solve the basics first. We'll support deploying to a single resource group and using resources from existing resouregroups, tenants and subscriptons.</comment_new>

Fixes #11037


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits October 23, 2025 07:42
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
@davidfowl davidfowl requested a review from mitchdenny October 23, 2025 07:47
Copilot AI changed the title [WIP] Add support for modeling Azure resource groups as Aspire resources Add support for selecting existing Azure resource groups during provisioning Oct 23, 2025
Copilot finished work on behalf of davidfowl October 23, 2025 07:48
Copilot AI requested a review from davidfowl October 23, 2025 07:48
@github-actions
Copy link
Contributor

github-actions bot commented Oct 23, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12302

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12302"

1 similar comment
@github-actions
Copy link
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12302

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12302"

@davidfowl
Copy link
Member

@copilot Fix

🔴 Aspire.Hosting.Azure.Tests.AzureDeployerTests.DeployAsync_PromptsViaInteractionService
Assert.Collection() Failure: Item comparison failure
↓ (pos 1)
Collection: [InteractionInput { AllowCustomChoice = False, Description = null, Disabled = False, DynamicLoading = null, EnableDescriptionMarkdown = False, ··· }, InteractionInput { AllowCustomChoice = True, Description = null, Disabled = False, DynamicLoading = null, EnableDescriptionMarkdown = False, ··· }]
Error: Assert.Equal() Failure: Values differ
Expected: Text
Actual: Choice
Stack Trace:
/home/runner/work/aspire/aspire/tests/Aspire.Hosting.Azure.Tests/AzureDeployerTests.cs(121,0): at Aspire.Hosting.Azure.Tests.AzureDeployerTests.<>c.<DeployAsync_PromptsViaInteractionService>b__3_3(InteractionInput input) at Aspire.Hosting.Azure.Tests.AzureDeployerTests.DeployAsync_PromptsViaInteractionService() in /home/runner/work/aspire/aspire/tests/Aspire.Hosting.Azure.Tests/AzureDeployerTests.cs:line 111
--- End of stack trace from previous location ---

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 23, 2025

@copilot Fix

🔴 Aspire.Hosting.Azure.Tests.AzureDeployerTests.DeployAsync_PromptsViaInteractionService
...

Fixed in commit 3920156. The test now expects InputType.Choice for the resource group input, which matches the new behavior where users can select from existing resource groups or enter a new name.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • aka.ms
    • Triggering command: /usr/local/bin/bicep build /tmp/aspire6tBAHu/env.module.bicep --stdout (dns block)
    • Triggering command: /usr/local/bin/bicep build /tmp/aspireQSVn7u/teststorage.module.bicep --stdout (dns block)
    • Triggering command: /usr/local/bin/bicep build /tmp/aspiredvm94J/env.module.bicep --stdout (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of davidfowl October 23, 2025 08:05

public async Task<IEnumerable<string>> GetAvailableResourceGroupsAsync(string subscriptionId, CancellationToken cancellationToken = default)
{
var subscription = await armClient.GetSubscriptions().GetAsync(subscriptionId, cancellationToken).ConfigureAwait(false);
Copy link
Member

Choose a reason for hiding this comment

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

In many cases we would have already queried for the subscription ID or gotten the subscription list, can we cache the result or do we want to fetch each time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The subscription resource is already obtained earlier in the flow (via GetSubscriptionAndTenantAsync), so we're already making that call. The resource groups are fetched once when the subscription is selected and used to populate the dropdown. For the current implementation, I've kept it simple without additional caching since the fetch happens only once per provisioning session. If we need cross-session caching, we could consider adding it to the deployment state manager in a future update.

@davidfowl
Copy link
Member

@copilot We need to change the ux such that the resource group selection comes before the location selection. Only if a new / custom resource group is selected do we need to prompt for location.

- Resource group selection now comes before location selection
- Location is only prompted when creating a new resource group
- When selecting an existing resource group, its location is automatically used
- Added GetAvailableResourceGroupsWithLocationAsync to fetch RG details
- Updated both RunMode and PublishMode providers
- Added new localization strings for resource group dialog
- Updated all tests to reflect new UX flow

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 23, 2025

@copilot We need to change the ux such that the resource group selection comes before the location selection. Only if a new / custom resource group is selected do we need to prompt for location.

Fixed in commit 9fb6926. The UX now prompts for resource group selection first. If an existing resource group is selected, its location is automatically used. Location is only prompted when creating a new resource group (custom name entered).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • aka.ms
    • Triggering command: /usr/local/bin/bicep build /tmp/aspireNI8Tfc/teststorage.module.bicep --stdout (dns block)
    • Triggering command: /usr/local/bin/bicep build /tmp/aspireE93P2u/env.module.bicep --stdout (dns block)
    • Triggering command: /usr/local/bin/bicep build /tmp/aspirekCqjJW/env.module.bicep --stdout (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add support for selecting existing Azure resource groups during provisioning Add support for selecting existing Azure resource groups during provisioning with improved UX flow Oct 23, 2025
Copilot finished work on behalf of davidfowl October 23, 2025 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support modeling Azure resource groups as Aspire resources

3 participants