Skip to content

Commit

Permalink
feat: Add arn attribute to aws_ec2_transit_gateway_dx_gateway_attachm…
Browse files Browse the repository at this point in the history
…ent data source
  • Loading branch information
acwwat committed Jan 26, 2025
1 parent 169b319 commit e26179a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
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"
awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand All @@ -31,6 +33,10 @@ func dataSourceTransitGatewayDxGatewayAttachment() *schema.Resource {
},

Schema: map[string]*schema.Schema{
names.AttrARN: {
Type: schema.TypeString,
Computed: true,
},
"dx_gateway_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -85,6 +91,15 @@ func dataSourceTransitGatewayDxGatewayAttachmentRead(ctx context.Context, d *sch
}

d.SetId(aws.ToString(transitGatewayAttachment.TransitGatewayAttachmentId))
resourceOwnerID := aws.ToString(transitGatewayAttachment.ResourceOwnerId)
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("dx_gateway_id", transitGatewayAttachment.ResourceId)
d.Set(names.AttrTransitGatewayID, transitGatewayAttachment.TransitGatewayId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func testAccTransitGatewayDxGatewayAttachmentDataSource_TransitGatewayIdAndDxGat
{
Config: testAccTransitGatewayDxGatewayAttachmentDataSourceConfig_transit(rName, rBgpAsn),
Check: resource.ComposeTestCheckFunc(
acctest.CheckResourceAttrRegionalARNFormat(ctx, dataSourceName, names.AttrARN, "ec2", "transit-gateway-attachment/{id}"),
resource.TestCheckResourceAttrPair(dataSourceName, "dx_gateway_id", dxGatewayResourceName, names.AttrID),
resource.TestCheckResourceAttr(dataSourceName, acctest.CtTagsPercent, "0"),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrTransitGatewayID, transitGatewayResourceName, names.AttrID),
Expand Down Expand Up @@ -65,6 +66,7 @@ func testAccTransitGatewayDxGatewayAttachmentDataSource_filter(t *testing.T, sem
{
Config: testAccTransitGatewayDxGatewayAttachmentDataSourceConfig_transitFilter(rName, rBgpAsn),
Check: resource.ComposeTestCheckFunc(
acctest.CheckResourceAttrRegionalARNFormat(ctx, dataSourceName, names.AttrARN, "ec2", "transit-gateway-attachment/{id}"),
resource.TestCheckResourceAttrPair(dataSourceName, "dx_gateway_id", dxGatewayResourceName, names.AttrID),
resource.TestCheckResourceAttr(dataSourceName, acctest.CtTagsPercent, "0"),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrTransitGatewayID, transitGatewayResourceName, names.AttrID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ The `filter` configuration block supports the following arguments:

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

* `id` - EC2 Transit Gateway Attachment identifier
* `tags` - Key-value tags for the EC2 Transit Gateway Attachment
* `arn` - ARN of the attachment.
* `id` - EC2 Transit Gateway Attachment identifier,
* `tags` - Key-value tags for the EC2 Transit Gateway Attachment.

## Timeouts

Expand Down

0 comments on commit e26179a

Please sign in to comment.