Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_nat_gateway: add association_id attribute to resource and data source #30546

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/30546.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_nat_gateway: Add `association_id` attribute
```

```release-note:enhancement
data-source/aws_nat_gateway: Add `association_id` attribute
```
19 changes: 14 additions & 5 deletions internal/service/ec2/vpc_nat_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func ResourceNATGateway() *schema.Resource {
Optional: true,
ForceNew: true,
},
"association_id": {
Type: schema.TypeString,
Computed: true,
},
"connectivity_type": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -126,12 +130,17 @@ func resourceNATGatewayRead(ctx context.Context, d *schema.ResourceData, meta in
return diag.Errorf("reading EC2 NAT Gateway (%s): %s", d.Id(), err)
}

address := ng.NatGatewayAddresses[0]
d.Set("allocation_id", address.AllocationId)
for _, address := range ng.NatGatewayAddresses {
if aws.BoolValue(address.IsPrimary) {
d.Set("allocation_id", address.AllocationId)
d.Set("association_id", address.AssociationId)
d.Set("network_interface_id", address.NetworkInterfaceId)
d.Set("private_ip", address.PrivateIp)
d.Set("public_ip", address.PublicIp)
}
}

d.Set("connectivity_type", ng.ConnectivityType)
d.Set("network_interface_id", address.NetworkInterfaceId)
d.Set("private_ip", address.PrivateIp)
d.Set("public_ip", address.PublicIp)
d.Set("subnet_id", ng.SubnetId)

SetTagsOut(ctx, ng.Tags)
Expand Down
7 changes: 6 additions & 1 deletion internal/service/ec2/vpc_nat_gateway_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func DataSourceNATGateway() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"association_id": {
Type: schema.TypeString,
Computed: true,
},
"connectivity_type": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -114,8 +118,9 @@ func dataSourceNATGatewayRead(ctx context.Context, d *schema.ResourceData, meta
d.Set("vpc_id", ngw.VpcId)

for _, address := range ngw.NatGatewayAddresses {
if aws.StringValue(address.AllocationId) != "" {
if aws.BoolValue(address.IsPrimary) {
d.Set("allocation_id", address.AllocationId)
d.Set("association_id", address.AssociationId)
d.Set("network_interface_id", address.NetworkInterfaceId)
d.Set("private_ip", address.PrivateIp)
d.Set("public_ip", address.PublicIp)
Expand Down
1 change: 1 addition & 0 deletions internal/service/ec2/vpc_nat_gateway_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestAccVPCNATGatewayDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(dataSourceNameById, "private_ip"),
resource.TestCheckNoResourceAttr(dataSourceNameById, "attached_vpc_id"),
resource.TestCheckResourceAttrSet(dataSourceNameById, "tags.OtherTag"),
resource.TestCheckResourceAttrPair(dataSourceNameById, "association_id", resourceName, "association_id"),
),
},
},
Expand Down
3 changes: 3 additions & 0 deletions internal/service/ec2/vpc_nat_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestAccVPCNATGateway_basic(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckNATGatewayExists(ctx, resourceName, &natGateway),
resource.TestCheckResourceAttrSet(resourceName, "allocation_id"),
resource.TestCheckResourceAttrSet(resourceName, "association_id"),
resource.TestCheckResourceAttr(resourceName, "connectivity_type", "public"),
resource.TestCheckResourceAttrSet(resourceName, "network_interface_id"),
resource.TestCheckResourceAttrSet(resourceName, "private_ip"),
Expand Down Expand Up @@ -89,6 +90,7 @@ func TestAccVPCNATGateway_ConnectivityType_private(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckNATGatewayExists(ctx, resourceName, &natGateway),
resource.TestCheckResourceAttr(resourceName, "allocation_id", ""),
resource.TestCheckResourceAttr(resourceName, "association_id", ""),
resource.TestCheckResourceAttr(resourceName, "connectivity_type", "private"),
resource.TestCheckResourceAttrSet(resourceName, "network_interface_id"),
resource.TestCheckResourceAttrSet(resourceName, "private_ip"),
Expand Down Expand Up @@ -123,6 +125,7 @@ func TestAccVPCNATGateway_privateIP(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckNATGatewayExists(ctx, resourceName, &natGateway),
resource.TestCheckResourceAttr(resourceName, "allocation_id", ""),
resource.TestCheckResourceAttr(resourceName, "association_id", ""),
resource.TestCheckResourceAttr(resourceName, "connectivity_type", "private"),
resource.TestCheckResourceAttrSet(resourceName, "network_interface_id"),
resource.TestCheckResourceAttr(resourceName, "private_ip", "10.0.0.8"),
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/nat_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ the selected Nat Gateway.
Each attachment supports the following:

* `allocation_id` - ID of the EIP allocated to the selected Nat Gateway.
* `association_id` - The association ID of the Elastic IP address that's associated with the NAT gateway. Only available when `connectivity_type` is `public`.
* `connectivity_type` - Connectivity type of the NAT Gateway.
* `network_interface_id` - The ID of the ENI allocated to the selected Nat Gateway.
* `private_ip` - Private Ip address of the selected Nat Gateway.
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/nat_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ The following arguments are supported:

In addition to all arguments above, the following attributes are exported:

* `association_id` - The association ID of the Elastic IP address that's associated with the NAT gateway. Only available when `connectivity_type` is `public`.
* `id` - The ID of the NAT Gateway.
* `network_interface_id` - The ID of the network interface associated with the NAT gateway.
* `public_ip` - The Elastic IP address associated with the NAT gateway.
Expand Down