Skip to content

Add subscription ID support to existing Azure resource scope - #11150

Closed
David Fowler (davidfowl) with Copilot wants to merge 6 commits into
mainfrom
copilot/fix-7514
Closed

Add subscription ID support to existing Azure resource scope#11150
David Fowler (davidfowl) with Copilot wants to merge 6 commits into
mainfrom
copilot/fix-7514

Conversation

Copilot AI commented Aug 28, 2025

Copy link
Copy Markdown
Contributor
  • Initial subscription support implementation
  • Add subscription support to ExistingAzureResourceAnnotation and extension methods
  • Enhance AzureBicepResourceScope with subscription constructors
  • Update manifest serialization to include subscription information
  • Create comprehensive tests for all subscription scenarios
  • Accept snapshot tests for subscription support
  • Implement review feedback:
    • Delete .nuget/NuGet/NuGet.Config file as requested
    • Delete test_scope.cs file as requested
    • Revert changes to src/Aspire.Hosting.Azure/api/Aspire.Hosting.Azure.cs (auto-generated file)
    • Rename subscriptionOnly parameter to isSubscriptionScope in AzureBicepResourceScope constructor
    • Update all usages of the renamed parameter throughout the codebase

Implementation Summary

The PR successfully adds subscription ID support to existing Azure resource scoping with the following key features:

Enhanced ExistingAzureResourceAnnotation

  • Added constructor supporting subscription IDs: ExistingAzureResourceAnnotation(object name, object? resourceGroup, object subscription)
  • Added Subscription property for subscription information

Extended Extension Methods

  • All existing resource extension methods now have overloads supporting subscription parameters
  • Examples: RunAsExisting(name, resourceGroup, subscription), PublishAsExisting(nameParam, rgParam, subParam), AsExisting("name", "rg", "subscription")

Enhanced AzureBicepResourceScope

  • Three constructor overloads supporting different scoping scenarios:
    • Resource group only: AzureBicepResourceScope(object resourceGroup)
    • Resource group + subscription: AzureBicepResourceScope(object resourceGroup, object subscription)
    • Subscription only: AzureBicepResourceScope(object subscription, bool isSubscriptionScope)

Enhanced Bicep Scope Generation

  • Cross-subscription resource group: resourceGroup(subscriptionId, resourceGroupName)
  • Subscription-level resource: subscription(subscriptionId)
  • Same subscription: resourceGroup(resourceGroupName) (backward compatible)

Updated Manifest Schema

  • Extended manifest serialization to include subscription information for deployment tools

All changes maintain full backward compatibility and the build completes successfully.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits August 28, 2025 08:31
…sion methods

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copilot AI changed the title [WIP] Consider supporting subscription IDs in existing resource scope Add subscription ID support to existing Azure resource scope Aug 28, 2025
@davidfowl

Copy link
Copy Markdown
Collaborator

Copilot check anywhere that uses AzureBicepResourceScope that may need to be updated.

Also make sure the newly added tests pass, we're missing the snapshot files.

Copilot AI and others added 2 commits August 28, 2025 15:17
…e usage sites

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
…tests

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

Copilot AI commented Aug 28, 2025

Copy link
Copy Markdown
Contributor Author

Copilot check anywhere that uses AzureBicepResourceScope that may need to be updated.

Also make sure the newly added tests pass, we're missing the snapshot files.

I've addressed both requests in commit 5269430:

  1. Checked and updated all AzureBicepResourceScope usage sites: Updated AzureProvisioningResource.cs and AzureResourcePreparer.cs to properly handle subscription scoping with the new constructors.

  2. Fixed snapshot tests: All new subscription support tests now pass and snapshots have been accepted. The tests correctly show subscription support in both the manifest JSON (scope section) and generated Bicep (subscription() scope expressions).

The implementation now properly handles three scenarios:

  • Resource group only: new AzureBicepResourceScope(resourceGroup)
  • Resource group + subscription: new AzureBicepResourceScope(resourceGroup, subscription)
  • Subscription only: new AzureBicepResourceScope(subscription, subscriptionOnly: true)

All changes maintain backward compatibility and the API surface has been updated accordingly.

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 /home/REDACTED/work/aspire/aspire/artifacts/bin/Aspire.Hosting.Azure.Tests/Debug/net8.0/main.bicep --stdout (dns block)
    • Triggering command: /usr/local/bin/bicep build /home/REDACTED/work/aspire/aspire/artifacts/bin/Aspire.Hosting.Azure.Tests/Debug/net8.0/api.module.bicep --stdout (dns block)
    • Triggering command: /usr/local/bin/bicep build /home/REDACTED/work/aspire/aspire/artifacts/bin/Aspire.Hosting.Azure.Tests/Debug/net8.0/cache.module.bicep --stdout (dns block)

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

/// </summary>
/// <param name="subscription">The subscription identifier for subscription-level resources.</param>
/// <param name="subscriptionOnly">Must be true to indicate this is a subscription-only scope.</param>
public AzureBicepResourceScope(object subscription, bool subscriptionOnly)

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.

This API is kinda weird. I understand we got here because both the resourceGroup and subscription parameters are weakly-typed but it feels like this should be:

Suggested change
public AzureBicepResourceScope(object subscription, bool subscriptionOnly)
public AzureBicepResourceScope(object subscription, bool isSubscriptionScope)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this even a thing?

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.

Is this even a thing?

Bicep resources that are only subscription scoped are a thing. I dunno if we need to model it this directly in the app model. I could see it being useful if you wanted to create your own "main.bicep" and declare multiple resource groups per environment or something but maybe the pattern we'd use there is having you initiate different ResourceGroupBicepResources for each environment.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the module can be subscription scoped, but resources are are always in a resource group no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed parameter from subscriptionOnly to isSubscriptionScope as suggested and updated all usage sites in commit 7c35c67.

Comment thread .nuget/NuGet/NuGet.Config Outdated
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remove this file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

File deleted in commit 7c35c67.

{
public AzureBicepResourceScope(object resourceGroup) { }

public object ResourceGroup { get { throw null; } }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do not update this file, it will be auto updated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

API file reverted to original state in commit 7c35c67.

Comment thread test_scope.cs Outdated
@@ -0,0 +1,33 @@
using System.Text.Json.Nodes;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This test file should be deleted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Test file deleted in commit 7c35c67.

@davidfowl

Copy link
Copy Markdown
Collaborator

Copilot implement the review feedback

…arameter

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

Copilot AI commented Aug 30, 2025

Copy link
Copy Markdown
Contributor Author

Copilot implement the review feedback

All review feedback implemented in commit 7c35c67:

  • Deleted .nuget/NuGet/NuGet.Config file
  • Deleted test_scope.cs file
  • Reverted auto-generated API file changes
  • Renamed subscriptionOnly parameter to isSubscriptionScope and updated all usages

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 /home/REDACTED/work/aspire/aspire/artifacts/bin/Aspire.Hosting.Azure.Tests/Debug/net8.0/main.bicep --stdout (dns block)
    • Triggering command: /usr/local/bin/bicep build /home/REDACTED/work/aspire/aspire/artifacts/bin/Aspire.Hosting.Azure.Tests/Debug/net8.0/api.module.bicep --stdout (dns block)
    • Triggering command: /usr/local/bin/bicep build /home/REDACTED/work/aspire/aspire/artifacts/bin/Aspire.Hosting.Azure.Tests/Debug/net8.0/cache.module.bicep --stdout (dns block)

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

},
"scope": {
"resourceGroup": "",
"subscription": "{existingSubscriptionId.value}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Victor Vazquez (@vhvb1989) This will require azd changes.

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.

Did you close this PR at the end? nothing else to do?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There’s a new one

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

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

Or

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

@dotnet-policy-service dotnet-policy-service Bot added this to the 9.5 milestone Aug 30, 2025
@davidfowl David Fowler (davidfowl) removed this from the 9.5 milestone Sep 16, 2025
@dotnet-policy-service dotnet-policy-service Bot added this to the 13.1 milestone Nov 22, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 25, 2025
@sebastienros
Sébastien Ros (sebastienros) deleted the copilot/fix-7514 branch January 15, 2026 16:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants