Skip to content

azurerm_nat_gateway_public_ip_association - support associating IPv6 Public IP#32176

Merged
sreallymatt merged 5 commits intohashicorp:mainfrom
teowa:nat-pip-ipv6
Apr 21, 2026
Merged

azurerm_nat_gateway_public_ip_association - support associating IPv6 Public IP#32176
sreallymatt merged 5 commits intohashicorp:mainfrom
teowa:nat-pip-ipv6

Conversation

@teowa
Copy link
Copy Markdown
Collaborator

@teowa teowa commented Apr 16, 2026

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

supersede #31321

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.

  • azurerm_nat_gateway_public_ip_association - support associating IPv6 Public IP

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

AI Assistance Disclosure

  • AI Assisted - This contribution was made by, or with the assistance of, AI/LLMs

Rollback Plan

If a change needs to be reverted, we will publish an updated version of the provider.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

Note

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

Copy link
Copy Markdown
Collaborator

@wuxu92 wuxu92 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I left some comments; we can take another look once they're addressed.

}
}

func resourceNATGatewayPublicIpAssociationCustomizeDiff(ctx context.Context, d *pluginsdk.ResourceDiff, meta any) error {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

as we are supporting both ipv4 and ipv6 now, this CustomizeDiff is not necessary anymore, we can error out in Create if configured id not eixsts.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

removed

}

func natGatewayPublicIpAssociationIsIPv6(publicIPAddress *publicipaddresses.PublicIPAddress) bool {
return pointer.From(publicIPAddress.Properties.PublicIPAddressVersion) == publicipaddresses.IPVersionIPvSix
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

publicIPAddress.Properties can be nil and panic here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

nil check added

return nil
}

func validateNATGatewayPublicIpAssociation(natGateway *natgateways.NatGateway, publicIPAddress *publicipaddresses.PublicIPAddress) error {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm unsure if this validate is solid and necessary here. if the api call is a light operation, may be we should defer to service side to validate it

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

make sense, the validation is removed

@teowa
Copy link
Copy Markdown
Collaborator Author

teowa commented Apr 17, 2026

Hi @wuxu92 , thanks for reviewing this. I have updated the code, please take another look.
image

Copy link
Copy Markdown
Collaborator

@wuxu92 wuxu92 left a comment

Choose a reason for hiding this comment

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

Some comments about the code format, it's good to go once addressed. Thanks!

Comment on lines 155 to 163
if model := natGateway.Model; model != nil && model.Properties != nil {
if !natGatewayPublicIpAssociationExists(model.Properties, id.Second.ID()) {
log.Printf("[DEBUG] Association between %s and %s was not found - removing from state", id.First, id.Second)
d.SetId("")
return nil
}
} else {
return fmt.Errorf("retrieving %s: `model` or `properties` was nil", id.First)
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

make it clear:

Suggested change
if model := natGateway.Model; model != nil && model.Properties != nil {
if !natGatewayPublicIpAssociationExists(model.Properties, id.Second.ID()) {
log.Printf("[DEBUG] Association between %s and %s was not found - removing from state", id.First, id.Second)
d.SetId("")
return nil
}
} else {
return fmt.Errorf("retrieving %s: `model` or `properties` was nil", id.First)
}
if natGateway.Model == nil || natGateway.Model.Properties == nil {
return fmt.Errorf("retrieving %s: `model` or `properties` was nil", id.First)
}
if !natGatewayPublicIpAssociationExists(natGateway.Model.Properties, id.Second.ID()) {
log.Printf("[DEBUG] Association between %s and %s was not found - removing from state", id.First, id.Second)
d.SetId("")
return nil
}

Copy link
Copy Markdown
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 +210 to +216
func natGatewayPublicIpAssociationIsIPv6(publicIPAddress *publicipaddresses.PublicIPAddress) bool {
if publicIPAddress == nil || publicIPAddress.Properties == nil {
return false
}

return pointer.From(publicIPAddress.Properties.PublicIPAddressVersion) == publicipaddresses.IPVersionIPvSix
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

since only one caller for this method, can we inline it?

Copy link
Copy Markdown
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 +103 to +110
isIPv6 := natGatewayPublicIpAssociationIsIPv6(publicIPAddress.Model)

if strings.EqualFold(*existingPublicIPAddress.Id, publicIpAddressId.ID()) {
return tf.ImportAsExistsError("azurerm_nat_gateway_public_ip_association", id.ID())
}
id := commonids.NewCompositeResourceID(natGatewayId, publicIpAddressId)

publicIpAddresses = append(publicIpAddresses, existingPublicIPAddress)
publicIpAddresses := pointer.From(natGateway.Model.Properties.PublicIPAddresses)
if isIPv6 {
publicIpAddresses = pointer.From(natGateway.Model.Properties.PublicIPAddressesV6)
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

make it clear:

Suggested change
isIPv6 := natGatewayPublicIpAssociationIsIPv6(publicIPAddress.Model)
if strings.EqualFold(*existingPublicIPAddress.Id, publicIpAddressId.ID()) {
return tf.ImportAsExistsError("azurerm_nat_gateway_public_ip_association", id.ID())
}
id := commonids.NewCompositeResourceID(natGatewayId, publicIpAddressId)
publicIpAddresses = append(publicIpAddresses, existingPublicIPAddress)
publicIpAddresses := pointer.From(natGateway.Model.Properties.PublicIPAddresses)
if isIPv6 {
publicIpAddresses = pointer.From(natGateway.Model.Properties.PublicIPAddressesV6)
}
isIPv6 := pointer.From(publicIPAddress.Model.Properties.PublicIPAddressVersion) == publicipaddresses.IPVersionIPvSix
id := commonids.NewCompositeResourceID(natGatewayId, publicIpAddressId)
gatewayProps := natGateway.Model.Properties
publicIpAddresses := pointer.From(gatewayProps.PublicIPAddresses)
if isIPv6 {
publicIpAddresses = pointer.From(gagewayProps.PublicIPAddressesV6)
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

updated

@teowa teowa requested a review from wuxu92 April 17, 2026 00:53
@teowa teowa changed the title azurerm_nat_gateway_public_ip_association - supports association with IPv6 Public IP azurerm_nat_gateway_public_ip_association - support associating IPv6 Public IP Apr 17, 2026
Copy link
Copy Markdown
Collaborator

@gerrytan gerrytan left a comment

Choose a reason for hiding this comment

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

Thank you, this PR looks good to me.

Copy link
Copy Markdown
Collaborator

@sreallymatt sreallymatt 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 ✅

@sreallymatt sreallymatt merged commit 5b1f310 into hashicorp:main Apr 21, 2026
31 checks passed
@github-actions github-actions Bot added this to the v4.70.0 milestone Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants