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

feat: Add arn attribute to aws_ec2_transit_gateway_peering_attachment resource and data source #41087

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/41087.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_ec2_transit_gateway_peering_attachment: Add `arn` attribute
```

```release-note:enhancement
data-source/aws_ec2_transit_gateway_peering_attachment: Add `arn` attribute
```
15 changes: 15 additions & 0 deletions internal/service/ec2/transitgateway_peering_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ package ec2

import (
"context"
"fmt"
"log"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/arn"
"github.com/aws/aws-sdk-go-v2/service/ec2"
awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/hashicorp/aws-sdk-go-base/v2/tfawserr"
Expand Down Expand Up @@ -39,6 +41,10 @@ func resourceTransitGatewayPeeringAttachment() *schema.Resource {
CustomizeDiff: verify.SetTagsDiff,

Schema: map[string]*schema.Schema{
names.AttrARN: {
Type: schema.TypeString,
Computed: true,
},
"peer_account_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -138,6 +144,15 @@ func resourceTransitGatewayPeeringAttachmentRead(ctx context.Context, d *schema.
return sdkdiag.AppendErrorf(diags, "reading EC2 Transit Gateway Peering Attachment (%s): %s", d.Id(), err)
}

resourceOwnerID := aws.ToString(transitGatewayPeeringAttachment.RequesterTgwInfo.OwnerId)
arn := arn.ARN{
Partition: meta.(*conns.AWSClient).Partition(ctx),
Service: names.EC2,
Region: meta.(*conns.AWSClient).Region(ctx),
AccountID: resourceOwnerID,
Resource: fmt.Sprintf("transit-gateway-attachment/%s", d.Id()),
}.String()
d.Set(names.AttrARN, arn)
d.Set("peer_account_id", transitGatewayPeeringAttachment.AccepterTgwInfo.OwnerId)
d.Set("peer_region", transitGatewayPeeringAttachment.AccepterTgwInfo.Region)
d.Set("peer_transit_gateway_id", transitGatewayPeeringAttachment.AccepterTgwInfo.TransitGatewayId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ package ec2

import (
"context"
"fmt"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/arn"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -30,6 +32,10 @@ func dataSourceTransitGatewayPeeringAttachment() *schema.Resource {
},

Schema: map[string]*schema.Schema{
names.AttrARN: {
Type: schema.TypeString,
Computed: true,
},
names.AttrFilter: customFiltersSchema(),
names.AttrID: {
Type: schema.TypeString,
Expand Down Expand Up @@ -102,6 +108,15 @@ func dataSourceTransitGatewayPeeringAttachmentRead(ctx context.Context, d *schem
peer = transitGatewayPeeringAttachment.RequesterTgwInfo
}

resourceOwnerID := aws.ToString(local.OwnerId)
arn := arn.ARN{
Partition: meta.(*conns.AWSClient).Partition(ctx),
Service: names.EC2,
Region: meta.(*conns.AWSClient).Region(ctx),
AccountID: resourceOwnerID,
Resource: fmt.Sprintf("transit-gateway-attachment/%s", d.Id()),
}.String()
d.Set(names.AttrARN, arn)
d.Set("peer_account_id", peer.OwnerId)
d.Set("peer_region", peer.Region)
d.Set("peer_transit_gateway_id", peer.TransitGatewayId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func testAccTransitGatewayPeeringAttachmentDataSource_Filter_sameAccount(t *test
{
Config: testAccTransitGatewayPeeringAttachmentDataSourceConfig_filterSameAccount(rName),
Check: resource.ComposeAggregateTestCheckFunc(
acctest.CheckResourceAttrRegionalARNFormat(ctx, dataSourceName, names.AttrARN, "ec2", "transit-gateway-attachment/{id}"),
resource.TestCheckResourceAttrPair(resourceName, "peer_account_id", dataSourceName, "peer_account_id"),
resource.TestCheckResourceAttrPair(resourceName, "peer_region", dataSourceName, "peer_region"),
resource.TestCheckResourceAttrPair(resourceName, "peer_transit_gateway_id", dataSourceName, "peer_transit_gateway_id"),
Expand Down Expand Up @@ -65,6 +66,7 @@ func testAccTransitGatewayPeeringAttachmentDataSource_Filter_differentAccount(t
{
Config: testAccTransitGatewayPeeringAttachmentDataSourceConfig_filterDifferentAccount(rName),
Check: resource.ComposeAggregateTestCheckFunc(
acctest.CheckResourceAttrRegionalARNFormat(ctx, dataSourceName, names.AttrARN, "ec2", "transit-gateway-attachment/{id}"),
resource.TestCheckResourceAttrPair(transitGatewayResourceName, names.AttrOwnerID, dataSourceName, "peer_account_id"),
resource.TestCheckResourceAttr(dataSourceName, "peer_region", acctest.Region()),
resource.TestCheckResourceAttrPair(resourceName, "peer_transit_gateway_id", dataSourceName, names.AttrTransitGatewayID),
Expand Down Expand Up @@ -95,6 +97,7 @@ func testAccTransitGatewayPeeringAttachmentDataSource_ID_sameAccount(t *testing.
{
Config: testAccTransitGatewayPeeringAttachmentDataSourceConfig_idSameAccount(rName),
Check: resource.ComposeAggregateTestCheckFunc(
acctest.CheckResourceAttrRegionalARNFormat(ctx, dataSourceName, names.AttrARN, "ec2", "transit-gateway-attachment/{id}"),
resource.TestCheckResourceAttrPair(resourceName, "peer_account_id", dataSourceName, "peer_account_id"),
resource.TestCheckResourceAttrPair(resourceName, "peer_region", dataSourceName, "peer_region"),
resource.TestCheckResourceAttrPair(resourceName, "peer_transit_gateway_id", dataSourceName, "peer_transit_gateway_id"),
Expand Down Expand Up @@ -127,6 +130,7 @@ func testAccTransitGatewayPeeringAttachmentDataSource_ID_differentAccount(t *tes
{
Config: testAccTransitGatewayPeeringAttachmentDataSourceConfig_iDDifferentAccount(rName),
Check: resource.ComposeAggregateTestCheckFunc(
acctest.CheckResourceAttrRegionalARNFormat(ctx, dataSourceName, names.AttrARN, "ec2", "transit-gateway-attachment/{id}"),
resource.TestCheckResourceAttrPair(transitGatewayResourceName, names.AttrOwnerID, dataSourceName, "peer_account_id"),
resource.TestCheckResourceAttr(dataSourceName, "peer_region", acctest.Region()),
resource.TestCheckResourceAttrPair(resourceName, "peer_transit_gateway_id", dataSourceName, names.AttrTransitGatewayID),
Expand Down Expand Up @@ -157,6 +161,7 @@ func testAccTransitGatewayPeeringAttachmentDataSource_Tags(t *testing.T, semapho
{
Config: testAccTransitGatewayPeeringAttachmentDataSourceConfig_tagsSameAccount(rName),
Check: resource.ComposeAggregateTestCheckFunc(
acctest.CheckResourceAttrRegionalARNFormat(ctx, dataSourceName, names.AttrARN, "ec2", "transit-gateway-attachment/{id}"),
resource.TestCheckResourceAttrPair(resourceName, "peer_account_id", dataSourceName, "peer_account_id"),
resource.TestCheckResourceAttrPair(resourceName, "peer_region", dataSourceName, "peer_region"),
resource.TestCheckResourceAttrPair(resourceName, "peer_transit_gateway_id", dataSourceName, "peer_transit_gateway_id"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func testAccTransitGatewayPeeringAttachment_basic(t *testing.T, semaphore tfsync
Config: testAccTransitGatewayPeeringAttachmentConfig_sameAccount(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckTransitGatewayPeeringAttachmentExists(ctx, resourceName, &transitGatewayPeeringAttachment),
acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "transit-gateway-attachment/{id}"),
resource.TestCheckResourceAttr(resourceName, "options.#", "0"),
acctest.CheckResourceAttrAccountID(ctx, resourceName, "peer_account_id"),
resource.TestCheckResourceAttr(resourceName, "peer_region", acctest.AlternateRegion()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ which take the following arguments:

This data source exports the following attributes in addition to the arguments above:

* `peer_account_id` - Identifier of the peer AWS account
* `peer_region` - Identifier of the peer AWS region
* `peer_transit_gateway_id` - Identifier of the peer EC2 Transit Gateway
* `transit_gateway_id` - Identifier of the local EC2 Transit Gateway
* `arn` - ARN of the attachment.
* `peer_account_id` - Identifier of the peer AWS account.
* `peer_region` - Identifier of the peer AWS region.
* `peer_transit_gateway_id` - Identifier of the peer EC2 Transit Gateway.
* `transit_gateway_id` - Identifier of the local EC2 Transit Gateway.

## Timeouts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ The `options` block supports the following:

This resource exports the following attributes in addition to the arguments above:

* `id` - EC2 Transit Gateway Attachment identifier
* `arn` - ARN of the attachment.
* `id` - EC2 Transit Gateway Attachment identifier.
* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block).

## Import
Expand Down
Loading