Skip to content

Allow Azure VNet subnet name to be a parameter#18056

Open
Waleed-KH wants to merge 1 commit into
microsoft:mainfrom
Waleed-KH:subnet-name
Open

Allow Azure VNet subnet name to be a parameter#18056
Waleed-KH wants to merge 1 commit into
microsoft:mainfrom
Waleed-KH:subnet-name

Conversation

@Waleed-KH

Copy link
Copy Markdown
Contributor

Description

This pull request enhances support for parameterized subnet names in Azure subnet resources, enabling more flexible and dynamic provisioning scenarios. The main changes include updating the AzureSubnetResource class to accept either a literal string or a ParameterResource for the subnet name, adding a new overload for AddSubnet that supports parameterized subnet names and prefixes, and updating infrastructure configuration logic to handle these cases robustly.

Support for parameterized subnet names and address prefixes:

  • AzureSubnetResource now accepts either a string or a ParameterResource for the subnet name and address prefix, and exposes new properties (SubnetNameParameter, AddressPrefixParameter) for accessing them. The class logic and constructor overloads have been updated accordingly.
  • The ToProvisioningEntity method in AzureSubnetResource is updated to set the subnet name and address prefix from either a string or a parameter, throwing an exception if neither is set.

API surface improvements:

  • A new overload for AddSubnet in AzureVirtualNetworkExtensions allows adding a subnet with both parameterized address prefix and subnet name, making it easier to define subnets dynamically in code.

Infrastructure configuration robustness:

  • The AKS infrastructure configuration in AzureKubernetesEnvironmentExtensions now checks for both literal and parameterized subnet names, throwing an exception if neither is set, to ensure correctness during provisioning.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

Copilot AI review requested due to automatic review settings June 9, 2026 17:25
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
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/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 18056

Or

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

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

Note

Copilot was unable to run its full agentic suite in this review.

This PR adds support for parameterizing Azure subnet names (in addition to address prefixes) so subnets can be provisioned with values supplied via ParameterResource.

Changes:

  • Added a new AddSubnet overload that accepts ParameterResource for both subnet name and address prefix.
  • Updated AzureSubnetResource to store subnet name as either a literal string or a ParameterResource, and emit the correct provisioning value.
  • Updated AKS infrastructure wiring to handle parameterized subnet names when referencing existing subnets.

Reviewed changes

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

File Description
src/Aspire.Hosting.Azure.Network/AzureVirtualNetworkExtensions.cs Adds an AddSubnet overload for parameterized subnet name + address prefix.
src/Aspire.Hosting.Azure.Network/AzureSubnetResource.cs Extends subnet resource model to support parameterized subnet names and provisioning emission.
src/Aspire.Hosting.Azure.Kubernetes/AzureKubernetesEnvironmentExtensions.cs Resolves subnet name from either literal or parameter when configuring AKS infra.

Comment on lines +74 to +76
/// Gets the subnet name, or <c>null</c> if the subnet name is provided via a <see cref="ParameterResource"/>.
/// </summary>
public string? SubnetName => _subnetName as string;
Comment on lines +768 to +779
if (subnet.SubnetName is not null)
{
existingSubnet.Name = subnet.SubnetName;
}
else if (subnet.SubnetNameParameter is not null)
{
existingSubnet.Name = subnet.SubnetNameParameter.AsProvisioningParameter(infrastructure);
}
else
{
throw new UnreachableException("Subnet name must be set.");
}
Comment on lines 24 to 26
// Backing field holds either string or ParameterResource
private readonly object _subnetName;
private readonly object _addressPrefix;
}
else
{
throw new UnreachableException("Subnet name must be set.");
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.

2 participants