Skip to content

Allow subnet addressprefix to be a parameter.#14358

Merged
eerhardt merged 2 commits intodotnet:mainfrom
eerhardt:AddAddressPrefixParameter
Feb 6, 2026
Merged

Allow subnet addressprefix to be a parameter.#14358
eerhardt merged 2 commits intodotnet:mainfrom
eerhardt:AddAddressPrefixParameter

Conversation

@eerhardt
Copy link
Member

@eerhardt eerhardt commented Feb 5, 2026

Follow-up feedback from #13108

@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

🚀 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 -- 14358

Or

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enables subnet address prefixes to be parameterized in Azure Virtual Network configurations, allowing them to be specified dynamically rather than as hardcoded values. This is a follow-up enhancement to PR #13108 which introduced initial Azure Virtual Network support.

Changes:

  • Added a new AddSubnet overload that accepts IResourceBuilder<ParameterResource> for the address prefix
  • Modified AzureSubnetResource to support both string literals and parameter resources using a discriminated union pattern
  • Added comprehensive test coverage including unit tests and Bicep generation verification

Reviewed changes

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

File Description
src/Aspire.Hosting.Azure.Network/AzureSubnetResource.cs Refactored to support both string and ParameterResource address prefixes using a discriminated union pattern with two constructors and conditional logic in ToProvisioningEntity
src/Aspire.Hosting.Azure.Network/AzureVirtualNetworkExtensions.cs Added new AddSubnet overload accepting IResourceBuilder<ParameterResource> and refactored common logic into AddSubnetCore helper method
tests/Aspire.Hosting.Azure.Tests/AzureVirtualNetworkExtensionsTests.cs Added three new tests covering parameterized subnet creation, custom subnet naming, and Bicep generation
tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureVirtualNetworkExtensionsTests.AddSubnet_WithParameterResource_GeneratesBicep.verified.bicep Snapshot test file verifying correct Bicep template generation with parameterized address prefix

Copy link
Member

@mitchdenny mitchdenny left a comment

Choose a reason for hiding this comment

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

Looks good! One minor suggestion: should the string overload do stricter CIDR notation validation (e.g. regex for x.x.x.x/y)? Currently both the VNet and subnet constructors only check for null/empty, meaning a typo like "10.0.0.0" (missing prefix length) or "not-a-cidr" would be silently accepted and only fail at Azure deployment time. Validating the format early would give developers a faster feedback loop — though it does add a maintenance surface if Azure ever relaxes/changes the accepted formats.

@eerhardt
Copy link
Member Author

eerhardt commented Feb 6, 2026

We don't really do validation of other Azure accepted strings. If anything maybe the validation should be in Azure.Provisioning or bicep and not us.

@eerhardt eerhardt merged commit 9304c85 into dotnet:main Feb 6, 2026
337 checks passed
@eerhardt eerhardt deleted the AddAddressPrefixParameter branch February 6, 2026 01:04
@dotnet-policy-service dotnet-policy-service bot added this to the 13.2 milestone Feb 6, 2026
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

Comments