Skip to content

New Resource: azurerm_nat_gateway_public_ip_prefix_v6_association#31325

Closed
neil-yechenwei wants to merge 21 commits intohashicorp:mainfrom
neil-yechenwei:natgatewaypublicipv6prefixassociation
Closed

New Resource: azurerm_nat_gateway_public_ip_prefix_v6_association#31325
neil-yechenwei wants to merge 21 commits intohashicorp:mainfrom
neil-yechenwei:natgatewaypublicipv6prefixassociation

Conversation

@neil-yechenwei
Copy link
Copy Markdown
Contributor

@neil-yechenwei neil-yechenwei commented Dec 9, 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

This PR is to support new association resource azurerm_nat_gateway_public_ip_prefix_v6_association for new feature publicIpPrefixesV6. This PR depends on #31197. Once PR 31197 is merged, please don't merge this PR since I will rebase the code.

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)
--- PASS: TestAccNatGatewayPublicIpPrefixV6Association_requiresImport (192.23s)
--- PASS: TestAccNatGatewayPublicIpPrefixV6Association_basic (145.13s)

Change Log

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

  • New Resource: azurerm_nat_gateway_public_ip_prefix_v6_association

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.

@teowa
Copy link
Copy Markdown
Collaborator

teowa commented Dec 11, 2025

Thanks @neil-yechenwei , LGTM!

if props := model.Properties; props != nil {
publicIpPrefixesV6 := make([]natgateways.SubResource, 0)

if publicIPPrefixesV6 := props.PublicIPPrefixesV6; publicIPPrefixesV6 != nil {
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.

publicIPPrefixesV6 is re-assigned here in the if-condition.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated

if props := model.Properties; props != nil {
publicIpPrefixesV6 := make([]natgateways.SubResource, 0)

if publicIPPrefixesV6 := props.PublicIPPrefixesV6; publicIPPrefixesV6 != nil {
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.

Same as above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated


type NatGatewayPublicIpPrefixV6AssociationResource struct{}

func TestAccNatGatewayPublicIpPrefixV6Association_basic(t *testing.T) {
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.

Add a test to verify multiple associations

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated

@neil-yechenwei
Copy link
Copy Markdown
Contributor Author

neil-yechenwei commented Dec 11, 2025

@ms-henglu , thanks for the comments. I updated PR. Please take another look. Below is the latest test result.

--- PASS: TestAccNatGatewayPublicIpPrefixV6Association_multipleAssociations (229.01s)
--- PASS: TestAccNatGatewayPublicIpPrefixV6Association_requiresImport (187.13s)
--- PASS: TestAccNatGatewayPublicIpPrefixV6Association_basic (156.21s)

natGateway.Model.Properties.PublicIPPrefixesV6 = pointer.To(publicIpPrefixesV6)

if err := client.CreateOrUpdateThenPoll(ctx, *id.First, *natGateway.Model); err != nil {
return fmt.Errorf("removing association between %s and %s: %+v", *id.First, *id.Second, err)
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.

Suggested change
return fmt.Errorf("removing association between %s and %s: %+v", *id.First, *id.Second, err)
return fmt.Errorf("deleting %s: %+v", id, err)

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.

fixed


var state NATGatewayPublicIpPrefixV6AssociationModel
if err := metadata.Decode(&state); err != nil {
return err
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.

Suggested change
return err
return fmt.Errorf("decoding: %+v", err)

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.

fixed

A NAT Gateway and IPv6 Public IP Prefix association can be imported using the `resource id`, e.g.

```shell
terraform import azurerm_nat_gateway_public_ip_prefix_v6_association.example "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.Network/natGateways/natGateway1|/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.Network/publicIPPrefixes/publicIPPrefix1"
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.

Suggested change
terraform import azurerm_nat_gateway_public_ip_prefix_v6_association.example "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.Network/natGateways/natGateway1|/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.Network/publicIPPrefixes/publicIPPrefix1"
terraform import azurerm_nat_gateway_public_ip_prefix_v6_association.example "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/natGateways/gateway1|/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/publicIPPrefixes/prefix1"

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.

fixed


In addition to the Arguments listed above - the following Attributes are exported:

* `id` - The (Terraform specific) ID of the Association between the NAT Gateway and the IPv6 Public IP Prefix.
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.

Suggested change
* `id` - The (Terraform specific) ID of the Association between the NAT Gateway and the IPv6 Public IP Prefix.
* `id` - The ID of the Association between the NAT Gateway and the IPv6 Public IP Prefix.

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.

fixed

natGateway.Model.Properties.PublicIPPrefixesV6 = pointer.To(publicIpPrefixesV6)

if err := client.CreateOrUpdateThenPoll(ctx, *natGatewayId, *natGateway.Model); err != nil {
return fmt.Errorf("updating %s: %+v", *natGatewayId, err)
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.

Suggested change
return fmt.Errorf("updating %s: %+v", *natGatewayId, err)
return fmt.Errorf("creating %s: %+v", id, err)

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.

fixed

@teowa
Copy link
Copy Markdown
Collaborator

teowa commented Apr 8, 2026

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

Copy link
Copy Markdown
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.

LGTM~

@WodansSon WodansSon marked this pull request as ready for review April 8, 2026 08:32
@teowa
Copy link
Copy Markdown
Collaborator

teowa commented Apr 8, 2026

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.

Thanks for the updates on this PR! could you please have a look and update it to align with comment in #31321 (review) as these two PRs are very similar.

@teowa
Copy link
Copy Markdown
Collaborator

teowa commented Apr 9, 2026

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

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 @teowa The resource looks good now. could you please add the identity support for the new resource with guidance: ./contributing/topics/guide-resource-identity.md . also add identity support for the ipv6 association resource. Thanks!

@teowa
Copy link
Copy Markdown
Collaborator

teowa commented Apr 9, 2026

Hi @wuxu92 , ResourceWithIdentity is not implemented here because this resource uses a composite Terraform ID:

type CompositeResourceID[T1 resourceids.ResourceId, T2 resourceids.ResourceId] struct {
// First specifies the first component of this Resource ID.
// This is in the format `{first}|{second}`.
First T1
// Second specifies the second component of this Resource ID
// This is in the format `{first}|{second}`.
Second T2
}

The identity framework behind ResourceWithIdentity expects a single segment-based ARM-style ID built from Segments(), not a pipe-delimited composite ID.

type ResourceWithIdentity interface {
Resource
// Identity returns the resource's identity type
Identity() resourceids.ResourceId
}

type ResourceId interface {
// FromParseResult populates the Resource ID using the ParseResult provided in `input`
FromParseResult(input ParseResult) error
// ID returns the fully formatted ID for this Resource ID
ID() string
// String returns a friendly description of the components of this Resource ID
// which is suitable for use in error messages (for example 'MyThing %q / Resource Group %q')
String() string
// Segments returns an ordered list of expected Segments that make up this Resource ID
Segments() []Segment
}

@sreallymatt
Copy link
Copy Markdown
Collaborator

Is being discussed internally with @wuxu92

@sreallymatt
Copy link
Copy Markdown
Collaborator

superseded by #32195

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.

10 participants