Skip to content

Commit

Permalink
Merge pull request #36304 from partcyborg/tgw-peering-state
Browse files Browse the repository at this point in the history
aws_ec2_transit_gateway_peering_attachment: add attachment status
  • Loading branch information
ewbankkit authored Mar 12, 2024
2 parents f4bc32d + 6f3dbc5 commit c4fbee9
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 33 deletions.
7 changes: 7 additions & 0 deletions .changelog/36304.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 `state` attribute
```

```release-note:enhancement
data-source/aws_ec2_transit_gateway_peering_attachment: Add `state` attribute
```
15 changes: 8 additions & 7 deletions internal/service/ec2/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ package ec2

// Exports for use in tests only.
var (
ResourceDefaultNetworkACL = resourceDefaultNetworkACL
ResourceEBSFastSnapshotRestore = newResourceEBSFastSnapshotRestore
ResourceInstanceConnectEndpoint = newResourceInstanceConnectEndpoint
ResourceNetworkACL = resourceNetworkACL
ResourceSecurityGroupEgressRule = newResourceSecurityGroupEgressRule
ResourceSecurityGroupIngressRule = newResourceSecurityGroupIngressRule
ResourceTag = resourceTag
ResourceDefaultNetworkACL = resourceDefaultNetworkACL
ResourceEBSFastSnapshotRestore = newResourceEBSFastSnapshotRestore
ResourceInstanceConnectEndpoint = newResourceInstanceConnectEndpoint
ResourceNetworkACL = resourceNetworkACL
ResourceSecurityGroupEgressRule = newResourceSecurityGroupEgressRule
ResourceSecurityGroupIngressRule = newResourceSecurityGroupIngressRule
ResourceTag = resourceTag
ResourceTransitGatewayPeeringAttachment = resourceTransitGatewayPeeringAttachment

CustomFiltersSchema = customFiltersSchema
FindEBSFastSnapshotRestoreByID = findEBSFastSnapshotRestoreByID
Expand Down
6 changes: 4 additions & 2 deletions internal/service/ec2/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/service/ec2/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,7 @@ func sweepTransitGatewayPeeringAttachments(region string) error {
continue
}

r := ResourceTransitGatewayPeeringAttachment()
r := resourceTransitGatewayPeeringAttachment()
d := r.Data(nil)
d.SetId(aws.StringValue(v.TransitGatewayAttachmentId))

Expand Down
7 changes: 6 additions & 1 deletion internal/service/ec2/transitgateway_peering_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

// @SDKResource("aws_ec2_transit_gateway_peering_attachment", name="Transit Gateway Peering Attachment")
// @Tags(identifierAttribute="id")
func ResourceTransitGatewayPeeringAttachment() *schema.Resource {
func resourceTransitGatewayPeeringAttachment() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceTransitGatewayPeeringAttachmentCreate,
ReadWithoutTimeout: resourceTransitGatewayPeeringAttachmentRead,
Expand Down Expand Up @@ -53,6 +53,10 @@ func ResourceTransitGatewayPeeringAttachment() *schema.Resource {
Required: true,
ForceNew: true,
},
"state": {
Type: schema.TypeString,
Computed: true,
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
"transit_gateway_id": {
Expand Down Expand Up @@ -115,6 +119,7 @@ func resourceTransitGatewayPeeringAttachmentRead(ctx context.Context, d *schema.
d.Set("peer_account_id", transitGatewayPeeringAttachment.AccepterTgwInfo.OwnerId)
d.Set("peer_region", transitGatewayPeeringAttachment.AccepterTgwInfo.Region)
d.Set("peer_transit_gateway_id", transitGatewayPeeringAttachment.AccepterTgwInfo.TransitGatewayId)
d.Set("state", transitGatewayPeeringAttachment.State)
d.Set("transit_gateway_id", transitGatewayPeeringAttachment.RequesterTgwInfo.TransitGatewayId)

setTagsOut(ctx, transitGatewayPeeringAttachment.Tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @SDKDataSource("aws_ec2_transit_gateway_peering_attachment")
func DataSourceTransitGatewayPeeringAttachment() *schema.Resource {
// @SDKDataSource("aws_ec2_transit_gateway_peering_attachment", name="Transit Gateway Peering Attachment")
// @Tags
func dataSourceTransitGatewayPeeringAttachment() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceTransitGatewayPeeringAttachmentRead,

Expand All @@ -45,7 +47,11 @@ func DataSourceTransitGatewayPeeringAttachment() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"tags": tftags.TagsSchemaComputed(),
"state": {
Type: schema.TypeString,
Computed: true,
},
names.AttrTags: tftags.TagsSchemaComputed(),
"transit_gateway_id": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -57,7 +63,6 @@ func DataSourceTransitGatewayPeeringAttachment() *schema.Resource {
func dataSourceTransitGatewayPeeringAttachmentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).EC2Conn(ctx)
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

input := &ec2.DescribeTransitGatewayPeeringAttachmentsInput{}

Expand Down Expand Up @@ -99,11 +104,10 @@ func dataSourceTransitGatewayPeeringAttachmentRead(ctx context.Context, d *schem
d.Set("peer_account_id", peer.OwnerId)
d.Set("peer_region", peer.Region)
d.Set("peer_transit_gateway_id", peer.TransitGatewayId)
d.Set("state", transitGatewayPeeringAttachment.State)
d.Set("transit_gateway_id", local.TransitGatewayId)

if err := d.Set("tags", KeyValueTags(ctx, transitGatewayPeeringAttachment.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return sdkdiag.AppendErrorf(diags, "setting tags: %s", err)
}
setTagsOut(ctx, transitGatewayPeeringAttachment.Tags)

return diags
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ func testAccTransitGatewayPeeringAttachmentDataSource_Filter_sameAccount(t *test
},
ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5FactoriesAlternate(ctx, t),
CheckDestroy: testAccCheckTransitGatewayDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccTransitGatewayPeeringAttachmentDataSourceConfig_filterSameAccount(rName),
Check: resource.ComposeTestCheckFunc(
Check: resource.ComposeAggregateTestCheckFunc(
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"),
resource.TestCheckResourceAttrPair(resourceName, "state", dataSourceName, "state"),
resource.TestCheckResourceAttrPair(resourceName, "tags.%", dataSourceName, "tags.%"),
resource.TestCheckResourceAttrPair(resourceName, "transit_gateway_id", dataSourceName, "transit_gateway_id"),
),
Expand All @@ -58,15 +58,15 @@ func testAccTransitGatewayPeeringAttachmentDataSource_Filter_differentAccount(t
},
ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5FactoriesAlternate(ctx, t),
CheckDestroy: testAccCheckTransitGatewayDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccTransitGatewayPeeringAttachmentDataSourceConfig_filterDifferentAccount(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "peer_region", acctest.Region()),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(transitGatewayResourceName, "owner_id", dataSourceName, "peer_account_id"),
resource.TestCheckResourceAttrPair(resourceName, "transit_gateway_id", dataSourceName, "peer_transit_gateway_id"),
resource.TestCheckResourceAttr(dataSourceName, "peer_region", acctest.Region()),
resource.TestCheckResourceAttrPair(resourceName, "peer_transit_gateway_id", dataSourceName, "transit_gateway_id"),
resource.TestCheckResourceAttrPair(resourceName, "state", dataSourceName, "state"),
resource.TestCheckResourceAttrPair(resourceName, "transit_gateway_id", dataSourceName, "peer_transit_gateway_id"),
),
},
},
Expand All @@ -87,11 +87,10 @@ func testAccTransitGatewayPeeringAttachmentDataSource_ID_sameAccount(t *testing.
},
ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5FactoriesAlternate(ctx, t),
CheckDestroy: testAccCheckTransitGatewayDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccTransitGatewayPeeringAttachmentDataSourceConfig_idSameAccount(rName),
Check: resource.ComposeTestCheckFunc(
Check: resource.ComposeAggregateTestCheckFunc(
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 @@ -119,15 +118,15 @@ func testAccTransitGatewayPeeringAttachmentDataSource_ID_differentAccount(t *tes
},
ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5FactoriesAlternate(ctx, t),
CheckDestroy: testAccCheckTransitGatewayDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccTransitGatewayPeeringAttachmentDataSourceConfig_iDDifferentAccount(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "peer_region", acctest.Region()),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(transitGatewayResourceName, "owner_id", dataSourceName, "peer_account_id"),
resource.TestCheckResourceAttrPair(resourceName, "transit_gateway_id", dataSourceName, "peer_transit_gateway_id"),
resource.TestCheckResourceAttr(dataSourceName, "peer_region", acctest.Region()),
resource.TestCheckResourceAttrPair(resourceName, "peer_transit_gateway_id", dataSourceName, "transit_gateway_id"),
resource.TestCheckResourceAttrPair(resourceName, "state", dataSourceName, "state"),
resource.TestCheckResourceAttrPair(resourceName, "transit_gateway_id", dataSourceName, "peer_transit_gateway_id"),
),
},
},
Expand All @@ -148,14 +147,14 @@ func testAccTransitGatewayPeeringAttachmentDataSource_Tags(t *testing.T) {
},
ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5FactoriesAlternate(ctx, t),
CheckDestroy: testAccCheckTransitGatewayDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccTransitGatewayPeeringAttachmentDataSourceConfig_tagsSameAccount(rName),
Check: resource.ComposeTestCheckFunc(
Check: resource.ComposeAggregateTestCheckFunc(
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"),
resource.TestCheckResourceAttrPair(resourceName, "state", dataSourceName, "state"),
resource.TestCheckResourceAttrPair(resourceName, "tags.%", dataSourceName, "tags.%"),
resource.TestCheckResourceAttrPair(resourceName, "transit_gateway_id", dataSourceName, "transit_gateway_id"),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ func testAccTransitGatewayPeeringAttachment_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccTransitGatewayPeeringAttachmentConfig_sameAccount(rName),
Check: resource.ComposeTestCheckFunc(
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckTransitGatewayPeeringAttachmentExists(ctx, resourceName, &transitGatewayPeeringAttachment),
acctest.CheckResourceAttrAccountID(resourceName, "peer_account_id"),
resource.TestCheckResourceAttr(resourceName, "peer_region", acctest.AlternateRegion()),
resource.TestCheckResourceAttrPair(resourceName, "peer_transit_gateway_id", transitGatewayResourceNamePeer, "id"),
resource.TestCheckResourceAttrSet(resourceName, "state"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttrPair(resourceName, "transit_gateway_id", transitGatewayResourceName, "id"),
),
Expand Down Expand Up @@ -169,6 +170,7 @@ func testAccTransitGatewayPeeringAttachment_differentAccount(t *testing.T) {
},
resource.TestCheckResourceAttr(resourceName, "peer_region", acctest.AlternateRegion()),
resource.TestCheckResourceAttrPair(resourceName, "peer_transit_gateway_id", transitGatewayResourceNamePeer, "id"),
resource.TestCheckResourceAttrSet(resourceName, "state"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.Name", rName),
resource.TestCheckResourceAttrPair(resourceName, "transit_gateway_id", transitGatewayResourceName, "id"),
Expand Down

0 comments on commit c4fbee9

Please sign in to comment.