Skip to content

New Resource: azurerm_network_manager_ipam_pool_static_cidr#29501

Merged
wyattfry merged 9 commits intohashicorp:mainfrom
teowa:nm_ipam_sc
Aug 19, 2025
Merged

New Resource: azurerm_network_manager_ipam_pool_static_cidr#29501
wyattfry merged 9 commits intohashicorp:mainfrom
teowa:nm_ipam_sc

Conversation

@teowa
Copy link
Collaborator

@teowa teowa commented May 8, 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

New Resource: azurerm_network_manager_ipam_pool_static_cidr

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)

image

Change Log

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

  • New Resource: azurerm_network_manager_ipam_pool_static_cidr

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.

@teowa teowa requested a review from a team as a code owner May 8, 2025 10:49
@teowa teowa marked this pull request as draft May 8, 2025 10:49
Copy link
Collaborator

@ms-zhenhua ms-zhenhua left a comment

Choose a reason for hiding this comment

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

Hi @teowa ,

Thanks for this PR - I've taken a look through and left some comments inline. If we can fix those up, this should be good to go 👍

},

"number_of_ip_addresses_to_allocate": {
Type: pluginsdk.TypeString,
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not directly define it as an int type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

for IPv6 addresses, this field might be up to 128 bit integer, so we need to use string type for this.

if metadata.ResourceData.HasChange("address_prefixes") {
if len(model.AddressPrefixes) > 0 {
parameters.Properties.AddressPrefixes = pointer.To(model.AddressPrefixes)
parameters.Properties.NumberOfIPAddressesToAllocate = pointer.To("")
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not set NumberOfIPAddressesToAllocate in else branch?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Both address_prefixes and number_of_ip_addresses_to_allocate will be returned by API but only one of them can be set. When ignore_changes is applied to the unused field, it must be explicitly set to an empty value.

if metadata.ResourceData.HasChange("number_of_ip_addresses_to_allocate") {
if model.NumberOfIPAddressesToAllocate != "" {
parameters.Properties.NumberOfIPAddressesToAllocate = pointer.To(model.NumberOfIPAddressesToAllocate)
parameters.Properties.AddressPrefixes = pointer.To([]string{})
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above


* `address_prefixes` - (Optional) Specifies a list of IPv4 or IPv6 IP address prefixes which will be allocated to the Static CIDR.

-> **NOTE:** Exactly one of `address_prefixes` or `number_of_ip_addresses_to_allocate` must be specified. If you set either property, the Azure API will automatically configure the other. Therefore, if you set `address_prefixes`, consider adding `number_of_ip_addresses_to_allocate` to `ignore_changes` to avoid plan diff.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
-> **NOTE:** Exactly one of `address_prefixes` or `number_of_ip_addresses_to_allocate` must be specified. If you set either property, the Azure API will automatically configure the other. Therefore, if you set `address_prefixes`, consider adding `number_of_ip_addresses_to_allocate` to `ignore_changes` to avoid plan diff.
-> **Note:** Exactly one of `address_prefixes` or `number_of_ip_addresses_to_allocate` must be specified. If you set either property, the Azure API will automatically configure the other. Therefore, if you set `address_prefixes`, consider adding `number_of_ip_addresses_to_allocate` to `ignore_changes` to avoid plan diff.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed


* `number_of_ip_addresses_to_allocate` - (Optional) The number of IP addresses to allocated to the Static CIDR. The value must be a string that represents a positive number, e.g., `"16"`.

-> **NOTE:** Exactly one of `address_prefixes` or `number_of_ip_addresses_to_allocate` must be specified. If you set either property, the Azure API will automatically configure the other. Therefore, if you set `number_of_ip_addresses_to_allocate`, consider adding `address_prefixes` to `ignore_changes` to avoid plan diff.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
-> **NOTE:** Exactly one of `address_prefixes` or `number_of_ip_addresses_to_allocate` must be specified. If you set either property, the Azure API will automatically configure the other. Therefore, if you set `number_of_ip_addresses_to_allocate`, consider adding `address_prefixes` to `ignore_changes` to avoid plan diff.
-> **Note:** Exactly one of `address_prefixes` or `number_of_ip_addresses_to_allocate` must be specified. If you set either property, the Azure API will automatically configure the other. Therefore, if you set `number_of_ip_addresses_to_allocate`, consider adding `address_prefixes` to `ignore_changes` to avoid plan diff.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed


-> **NOTE:** Exactly one of `address_prefixes` or `number_of_ip_addresses_to_allocate` must be specified. If you set either property, the Azure API will automatically configure the other. Therefore, if you set `number_of_ip_addresses_to_allocate`, consider adding `address_prefixes` to `ignore_changes` to avoid plan diff.

-> **NOTE:** If `number_of_ip_addresses_to_allocate` is not set to a power of 2, Azure API will return the nearest power of 2. For instance, if `number_of_ip_addresses_to_allocate` is `"20"`, Azure API will automatically update it to `"32"`. In such cases, please update the `number_of_ip_addresses_to_allocate` in the configuration file to this new value.
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you add a validation of a power of 2 in the provider so that the users will not miss configure the unacceptable value ?

Suggested change
-> **NOTE:** If `number_of_ip_addresses_to_allocate` is not set to a power of 2, Azure API will return the nearest power of 2. For instance, if `number_of_ip_addresses_to_allocate` is `"20"`, Azure API will automatically update it to `"32"`. In such cases, please update the `number_of_ip_addresses_to_allocate` in the configuration file to this new value.
-> **Note:** If `number_of_ip_addresses_to_allocate` is not set to a power of 2, Azure API will return the nearest power of 2. For instance, if `number_of_ip_addresses_to_allocate` is `"20"`, Azure API will automatically update it to `"32"`. In such cases, please update the `number_of_ip_addresses_to_allocate` in the configuration file to this new value.

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, a validation is added

@teowa
Copy link
Collaborator Author

teowa commented May 13, 2025

Hi @ms-zhenhua , thanks for reviewing! I have updated the code, please kindly take another look.
image

…down

Co-authored-by: Zhenhua Hu <zhhu@microsoft.com>
ms-zhenhua
ms-zhenhua previously approved these changes May 14, 2025
Copy link
Collaborator

@ms-zhenhua ms-zhenhua left a comment

Choose a reason for hiding this comment

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

Hi @teowa,

Thanks for your updates. LGTM~

@teowa teowa marked this pull request as ready for review May 14, 2025 03:28
@teowa
Copy link
Collaborator Author

teowa commented Jun 2, 2025

image

ipam_pool_id = azurerm_network_manager_ipam_pool.test.id
address_prefixes = ["10.0.0.0/26", "10.0.0.128/27"]
lifecycle {
ignore_changes = [number_of_ip_addresses_to_allocate]

Choose a reason for hiding this comment

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

Would an option to split this into two resources work better instead of using ignore_changes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi, I think it isn't necessary to split this into two separate resources, because it's the same resource type with the same function; only the IP address can be set from prefixes or a number.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have added DiffSuppressFunc to suppress the diff, ignore_changes is not needed now.

@teowa teowa requested review from WodansSon and magodo as code owners July 23, 2025 08:06
@teowa
Copy link
Collaborator Author

teowa commented Jul 23, 2025

local test results:
image

Copy link
Contributor

@wyattfry wyattfry left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Did you already consider making the number_of_ip_addresses property just the exponent (2^x) instead of having to enter a power-of-two integer? Or the CIDR number prefix / subnet size (following the Portal UI)

image

@teowa
Copy link
Collaborator Author

teowa commented Aug 19, 2025

Hi @wyattfry , thanks for the review! The Portal UI actually maps to the address_prefix field, we can set the value like address_prefix = ["10.0.0.0/30", "10.0.0.128/27"]. It's a good point to expose an exponent number that accepts an integer between 0-64 to set the number of IP addresses. This is more user-friendly, but we might lose some consistency with the API and other resources, such as VNet, that already use the similar number_of_ip_addresses field.

@wyattfry wyattfry self-assigned this Aug 19, 2025
@wyattfry
Copy link
Contributor

Hi @wyattfry , thanks for the review! The Portal UI actually maps to the address_prefix field, we can set the value like address_prefix = ["10.0.0.0/30", "10.0.0.128/27"]. It's a good point to expose an exponent number that accepts an integer between 0-64 to set the number of IP addresses. This is more user-friendly, but we might lose some consistency with the API and other resources, such as VNet, that already use the similar number_of_ip_addresses field.

Great point, let's go with consistency. I don't know if it would be worth mentioning anywhere that Terraform / HCL's built-in functions can be useful here, e.g. pow(2, x), which works up to 2^53 before losing precision.

@wyattfry wyattfry merged commit 5b7a6a3 into hashicorp:main Aug 19, 2025
33 checks passed
@github-actions github-actions bot added this to the v4.41.0 milestone Aug 19, 2025
wyattfry added a commit that referenced this pull request Aug 20, 2025
mbfrahry pushed a commit that referenced this pull request Aug 21, 2025

* `address_prefixes` - (Optional) Specifies a list of IPv4 or IPv6 IP address prefixes which will be allocated to the Static CIDR.

-> **Note:** Exactly one of `address_prefixes` or `number_of_ip_addresses_to_allocate` must be specified.
Copy link
Contributor

Choose a reason for hiding this comment

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

For information about avoiding errors, we're trying to move everything to use the tilde + greater than combo. Not terribly important, but it would help make the docs more consistent. Don't worry about fixing this instance, just a consideration for the future.

Suggested change
-> **Note:** Exactly one of `address_prefixes` or `number_of_ip_addresses_to_allocate` must be specified.
~> **Note:** Exactly one of `address_prefixes` or `number_of_ip_addresses_to_allocate` must be specified.

@github-actions
Copy link
Contributor

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 Sep 22, 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.

5 participants