Skip to content

azurerm_virtual_network - support for ip_address_pool #29021

Merged
catriona-m merged 7 commits intohashicorp:mainfrom
teowa:vnet-ip-pool
Jun 3, 2025
Merged

azurerm_virtual_network - support for ip_address_pool #29021
catriona-m merged 7 commits intohashicorp:mainfrom
teowa:vnet-ip-pool

Conversation

@teowa
Copy link
Collaborator

@teowa teowa commented Mar 11, 2025

Community Note

  • Please vote on this PR by adding a 👍 reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for PR followers and do not help prioritize for review

Description

azurerm_virtual_network - support for ip_address_pool
Azure Documentation: https://learn.microsoft.com/azure/virtual-network-manager/how-to-manage-ip-addresses-network-manager?tabs=azureportal#associate-a-virtual-network-with-an-ip-address-pool
REST API: https://learn.microsoft.com/rest/api/virtualnetwork/virtual-networks/create-or-update?view=rest-virtualnetwork-2024-05-01&tabs=HTTP#ipampoolprefixallocation

PR Checklist

  • I have followed the guidelines in our Contributing Documentation.
  • I have checked to ensure there aren't other open Pull Requests for the same update/change.
  • I have checked if my changes close any open issues. If so please include appropriate closing keywords below.
  • I have updated/added Documentation as required written in a helpful and kind way to assist users that may be unfamiliar with the resource / data source.
  • I have used a meaningful PR title to help maintainers and other users understand this change and help prevent duplicate work.
    For example: “resource_name_here - description of change e.g. adding property new_property_name_here

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevant documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.
  • (For changes that include a state migration only). I have manually tested the migration path between relevant versions of the provider.

Testing

  • My submission includes Test coverage as described in the Contribution Guide and the tests pass. (if this is not possible for any reason, please include details of why you did or could not add test coverage)
-> % make acctests SERVICE="network" TESTARGS="-parallel 10 -run TestAccVirtualNetwork_ipAddressPool" TESTTIMEOUT='5h'
==> Checking that code complies with gofmt requirements...
==> Checking that Custom Timeouts are used...
==> Checking that acceptance test packages are used...
TF_ACC=1 go test -v ./internal/services/network -parallel 10 -run TestAccVirtualNetwork_ipAddressPool -timeout 5h -ldflags="-X=github.com/hashicorp/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccVirtualNetwork_ipAddressPool
=== PAUSE TestAccVirtualNetwork_ipAddressPool
=== RUN   TestAccVirtualNetwork_ipAddressPoolUpdateBasic
=== PAUSE TestAccVirtualNetwork_ipAddressPoolUpdateBasic
=== RUN   TestAccVirtualNetwork_ipAddressPoolUpdateNumber
=== PAUSE TestAccVirtualNetwork_ipAddressPoolUpdateNumber
=== CONT  TestAccVirtualNetwork_ipAddressPool
=== CONT  TestAccVirtualNetwork_ipAddressPoolUpdateNumber
=== CONT  TestAccVirtualNetwork_ipAddressPoolUpdateBasic
--- PASS: TestAccVirtualNetwork_ipAddressPool (206.72s)
--- PASS: TestAccVirtualNetwork_ipAddressPoolUpdateNumber (232.53s)
--- PASS: TestAccVirtualNetwork_ipAddressPoolUpdateBasic (247.81s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/network       247.854s

Change Log

Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.

  • azurerm_virtual_network - support for ip_address_pool

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

Related Issue(s)

Fixes #0000

Note

If this PR changes meaningfully during the course of review please update the title and description as required.

Copy link
Member

@catriona-m catriona-m left a comment

Choose a reason for hiding this comment

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

Thanks @teowa - I've left some comments inline but once those are addressed we can take another look. Thanks!

ValidateFunc: ipampools.ValidateIPamPoolID,
},

"ip_address_number": {
Copy link
Member

Choose a reason for hiding this comment

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

could we change this to number_of_ip_addresses to make this more clear?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed

},

"ip_address_number": {
Type: pluginsdk.TypeString,
Copy link
Member

Choose a reason for hiding this comment

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

should we make this an int?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need to keep this as a string, as number of IPv6 addresses can be up to 128-bit integers.

Comment on lines 498 to +501
if payload.Properties.AddressSpace == nil {
payload.Properties.AddressSpace = &virtualnetworks.AddressSpace{}
}
if v := d.Get("address_space").(*pluginsdk.Set).List(); len(v) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if payload.Properties.AddressSpace == nil {
payload.Properties.AddressSpace = &virtualnetworks.AddressSpace{}
}
if v := d.Get("address_space").(*pluginsdk.Set).List(); len(v) > 0 {
if v := d.Get("address_space").(*pluginsdk.Set).List(); len(v) > 0 {
if payload.Properties.AddressSpace == nil {
payload.Properties.AddressSpace = &virtualnetworks.AddressSpace{}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed

Comment on lines +509 to +511
if payload.Properties.AddressSpace == nil {
payload.Properties.AddressSpace = &virtualnetworks.AddressSpace{}
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if payload.Properties.AddressSpace == nil {
payload.Properties.AddressSpace = &virtualnetworks.AddressSpace{}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

}

payload.Properties.AddressSpace.AddressPrefixes = utils.ExpandStringSlice(d.Get("address_space").(*pluginsdk.Set).List())
if v := d.Get("ip_address_pool").([]interface{}); len(v) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if v := d.Get("ip_address_pool").([]interface{}); len(v) > 0 {
if v := d.Get("ip_address_pool").([]interface{}); len(v) > 0 {
if payload.Properties.AddressSpace == nil {
payload.Properties.AddressSpace = &virtualnetworks.AddressSpace{}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated


outputs := make([]interface{}, 0)
for _, v := range *input {
if v.Pool != nil && v.Pool.Id != nil {
Copy link
Member

Choose a reason for hiding this comment

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

we shouldn't need to check v.Pool.Id != nil here since pointer.From(v.Pool.Id), should handle this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

Comment on lines +924 to +925
"ip_address_number": pointer.From(v.NumberOfIPAddresses),
"allocated_ip_address_prefixes": pointer.From(v.AllocatedAddressPrefixes),
Copy link
Member

Choose a reason for hiding this comment

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

should we set these separately from id incase v.Pool is nil, but v.NumberOfIPAddresses and v.AllocatedAddressPrefixes are not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

),
},
data.ImportStep(),
// The ip_address_number can only be increated, so here we don't update back
Copy link
Member

Choose a reason for hiding this comment

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

can we check for this case in the update and return an error if a user attempts to decrease the number of ip addresses?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated


"location": commonschema.Location(),

// Optional
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Optional

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

@teowa
Copy link
Collaborator Author

teowa commented Jun 2, 2025

image
VNet tests can pass; the failed test cases aren't related to this PR

Copy link
Member

@catriona-m catriona-m left a comment

Choose a reason for hiding this comment

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

Thanks @teowa LGTM!

@catriona-m catriona-m merged commit b7dcd47 into hashicorp:main Jun 3, 2025
42 checks passed
@github-actions github-actions bot added this to the v4.32.0 milestone Jun 3, 2025
catriona-m added a commit that referenced this pull request Jun 3, 2025
wyattfry pushed a commit that referenced this pull request Jun 5, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2025

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants