Allow Azure VNet subnet name to be a parameter#18056
Open
Waleed-KH wants to merge 1 commit into
Open
Conversation
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 18056Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 18056" |
Contributor
There was a problem hiding this comment.
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
AddSubnetoverload that acceptsParameterResourcefor both subnet name and address prefix. - Updated
AzureSubnetResourceto store subnet name as either a literal string or aParameterResource, 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."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
AzureSubnetResourceclass to accept either a literal string or aParameterResourcefor the subnet name, adding a new overload forAddSubnetthat supports parameterized subnet names and prefixes, and updating infrastructure configuration logic to handle these cases robustly.Support for parameterized subnet names and address prefixes:
AzureSubnetResourcenow accepts either a string or aParameterResourcefor 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.ToProvisioningEntitymethod inAzureSubnetResourceis 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:
AddSubnetinAzureVirtualNetworkExtensionsallows adding a subnet with both parameterized address prefix and subnet name, making it easier to define subnets dynamically in code.Infrastructure configuration robustness:
AzureKubernetesEnvironmentExtensionsnow checks for both literal and parameterized subnet names, throwing an exception if neither is set, to ensure correctness during provisioning.Checklist
<remarks />and<code />elements on your triple slash comments?