diff --git a/.changelog/32023.txt b/.changelog/32023.txt new file mode 100644 index 00000000000..5595ba98dee --- /dev/null +++ b/.changelog/32023.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_networkmanager_attachment_accepter: Added support for Transit Gateway route table attachments +``` \ No newline at end of file diff --git a/internal/service/networkmanager/attachment_accepter.go b/internal/service/networkmanager/attachment_accepter.go index 77a288cadbe..6cb9aff139a 100644 --- a/internal/service/networkmanager/attachment_accepter.go +++ b/internal/service/networkmanager/attachment_accepter.go @@ -41,14 +41,10 @@ func ResourceAttachmentAccepter() *schema.Resource { // querying attachments requires knowing the type ahead of time // therefore type is required in provider, though not on the API "attachment_type": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{ - networkmanager.AttachmentTypeVpc, - networkmanager.AttachmentTypeSiteToSiteVpn, - networkmanager.AttachmentTypeConnect, - }, false), + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice(networkmanager.AttachmentType_Values(), false), }, "core_network_arn": { Type: schema.TypeString, @@ -123,6 +119,17 @@ func resourceAttachmentAccepterCreate(ctx context.Context, d *schema.ResourceDat d.SetId(attachmentID) + case networkmanager.AttachmentTypeTransitGatewayRouteTable: + tgwAttachment, err := FindTransitGatewayRouteTableAttachmentByID(ctx, conn, attachmentID) + + if err != nil { + return diag.Errorf("reading Network Manager Transit Gateway Route Table Attachment (%s): %s", attachmentID, err) + } + + state = aws.StringValue(tgwAttachment.Attachment.State) + + d.SetId(attachmentID) + default: return diag.Errorf("unsupported Network Manager Attachment type: %s", attachmentType) } @@ -153,6 +160,11 @@ func resourceAttachmentAccepterCreate(ctx context.Context, d *schema.ResourceDat if _, err := waitConnectAttachmentAvailable(ctx, conn, attachmentID, d.Timeout(schema.TimeoutCreate)); err != nil { return diag.Errorf("waiting for Network Manager Connect Attachment (%s) create: %s", attachmentID, err) } + + case networkmanager.AttachmentTypeTransitGatewayRouteTable: + if _, err := waitTransitGatewayRouteTableAttachmentAvailable(ctx, conn, attachmentID, d.Timeout(schema.TimeoutCreate)); err != nil { + return diag.Errorf("waiting for Network Manager Transit Gateway Route Table Attachment (%s) create: %s", attachmentID, err) + } } } @@ -209,6 +221,21 @@ func resourceAttachmentAccepterRead(ctx context.Context, d *schema.ResourceData, } a = connectAttachment.Attachment + + case networkmanager.AttachmentTypeTransitGatewayRouteTable: + tgwAttachment, err := FindTransitGatewayRouteTableAttachmentByID(ctx, conn, d.Id()) + + if !d.IsNewResource() && tfresource.NotFound(err) { + log.Printf("[WARN] Network Manager Transit Gateway Route Table Attachment %s not found, removing from state", d.Id()) + d.SetId("") + return nil + } + + if err != nil { + return diag.Errorf("reading Network Manager Transit Gateway Route Table Attachment (%s): %s", d.Id(), err) + } + + a = tgwAttachment.Attachment } d.Set("attachment_policy_rule_number", a.AttachmentPolicyRuleNumber) diff --git a/internal/service/networkmanager/transit_gateway_peering_test.go b/internal/service/networkmanager/transit_gateway_peering_test.go index 7e8618b2d57..4a56f84f2e8 100644 --- a/internal/service/networkmanager/transit_gateway_peering_test.go +++ b/internal/service/networkmanager/transit_gateway_peering_test.go @@ -200,13 +200,17 @@ resource "aws_networkmanager_global_network" "test" { resource "aws_networkmanager_core_network" "test" { global_network_id = aws_networkmanager_global_network.test.id - policy_document = data.aws_networkmanager_core_network_policy_document.test.json tags = { Name = %[1]q } } +resource "aws_networkmanager_core_network_policy_attachment" "test" { + core_network_id = aws_networkmanager_core_network.test.id + policy_document = data.aws_networkmanager_core_network_policy_document.test.json +} + data "aws_networkmanager_core_network_policy_document" "test" { core_network_configuration { # Don't overlap with default TGW ASN: 64512. diff --git a/internal/service/networkmanager/transit_gateway_route_table_attachment.go b/internal/service/networkmanager/transit_gateway_route_table_attachment.go index 09bd0573f63..a0f21cfaede 100644 --- a/internal/service/networkmanager/transit_gateway_route_table_attachment.go +++ b/internal/service/networkmanager/transit_gateway_route_table_attachment.go @@ -218,7 +218,7 @@ func FindTransitGatewayRouteTableAttachmentByID(ctx context.Context, conn *netwo return output.TransitGatewayRouteTableAttachment, nil } -func StatusTransitGatewayRouteTableAttachmentState(ctx context.Context, conn *networkmanager.NetworkManager, id string) retry.StateRefreshFunc { +func statusTransitGatewayRouteTableAttachmentState(ctx context.Context, conn *networkmanager.NetworkManager, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := FindTransitGatewayRouteTableAttachmentByID(ctx, conn, id) @@ -239,7 +239,7 @@ func waitTransitGatewayRouteTableAttachmentCreated(ctx context.Context, conn *ne Pending: []string{networkmanager.AttachmentStateCreating, networkmanager.AttachmentStatePendingNetworkUpdate}, Target: []string{networkmanager.AttachmentStateAvailable, networkmanager.AttachmentStatePendingAttachmentAcceptance}, Timeout: timeout, - Refresh: StatusTransitGatewayRouteTableAttachmentState(ctx, conn, id), + Refresh: statusTransitGatewayRouteTableAttachmentState(ctx, conn, id), } outputRaw, err := stateConf.WaitForStateContext(ctx) @@ -256,7 +256,7 @@ func waitTransitGatewayRouteTableAttachmentDeleted(ctx context.Context, conn *ne Pending: []string{networkmanager.AttachmentStateDeleting}, Target: []string{}, Timeout: timeout, - Refresh: StatusTransitGatewayRouteTableAttachmentState(ctx, conn, id), + Refresh: statusTransitGatewayRouteTableAttachmentState(ctx, conn, id), NotFoundChecks: 1, } @@ -268,3 +268,20 @@ func waitTransitGatewayRouteTableAttachmentDeleted(ctx context.Context, conn *ne return nil, err } + +func waitTransitGatewayRouteTableAttachmentAvailable(ctx context.Context, conn *networkmanager.NetworkManager, id string, timeout time.Duration) (*networkmanager.TransitGatewayRouteTableAttachment, error) { + stateConf := &retry.StateChangeConf{ + Pending: []string{networkmanager.AttachmentStateCreating, networkmanager.AttachmentStatePendingAttachmentAcceptance, networkmanager.AttachmentStatePendingNetworkUpdate}, + Target: []string{networkmanager.AttachmentStateAvailable}, + Timeout: timeout, + Refresh: statusTransitGatewayRouteTableAttachmentState(ctx, conn, id), + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*networkmanager.TransitGatewayRouteTableAttachment); ok { + return output, err + } + + return nil, err +} diff --git a/internal/service/networkmanager/transit_gateway_route_table_attachment_test.go b/internal/service/networkmanager/transit_gateway_route_table_attachment_test.go index 5cac87a0f2e..6af17579f5e 100644 --- a/internal/service/networkmanager/transit_gateway_route_table_attachment_test.go +++ b/internal/service/networkmanager/transit_gateway_route_table_attachment_test.go @@ -183,7 +183,7 @@ resource "aws_networkmanager_transit_gateway_peering" "test" { Name = %[1]q } - depends_on = [aws_ec2_transit_gateway_policy_table.test] + depends_on = [aws_ec2_transit_gateway_policy_table.test, aws_networkmanager_core_network_policy_attachment.test] } resource "aws_ec2_transit_gateway_route_table" "test" { @@ -209,6 +209,11 @@ resource "aws_networkmanager_transit_gateway_route_table_attachment" "test" { depends_on = [aws_ec2_transit_gateway_policy_table_association.test] } + +resource "aws_networkmanager_attachment_accepter" "test" { + attachment_id = aws_networkmanager_transit_gateway_route_table_attachment.test.id + attachment_type = aws_networkmanager_transit_gateway_route_table_attachment.test.attachment_type +} `) } @@ -224,6 +229,11 @@ resource "aws_networkmanager_transit_gateway_route_table_attachment" "test" { depends_on = [aws_ec2_transit_gateway_policy_table_association.test] } + +resource "aws_networkmanager_attachment_accepter" "test" { + attachment_id = aws_networkmanager_transit_gateway_route_table_attachment.test.id + attachment_type = aws_networkmanager_transit_gateway_route_table_attachment.test.attachment_type +} `, tagKey1, tagValue1)) } @@ -240,5 +250,10 @@ resource "aws_networkmanager_transit_gateway_route_table_attachment" "test" { depends_on = [aws_ec2_transit_gateway_policy_table_association.test] } + +resource "aws_networkmanager_attachment_accepter" "test" { + attachment_id = aws_networkmanager_transit_gateway_route_table_attachment.test.id + attachment_type = aws_networkmanager_transit_gateway_route_table_attachment.test.attachment_type +} `, tagKey1, tagValue1, tagKey2, tagValue2)) } diff --git a/website/docs/r/networkmanager_attachment_accepter.html.markdown b/website/docs/r/networkmanager_attachment_accepter.html.markdown index 2110a44f3b1..8b4d35bfbff 100644 --- a/website/docs/r/networkmanager_attachment_accepter.html.markdown +++ b/website/docs/r/networkmanager_attachment_accepter.html.markdown @@ -35,7 +35,7 @@ resource "aws_networkmanager_attachment_accepter" "test" { The following arguments are required: - `attachment_id` - (Required) The ID of the attachment. -- `attachment_type` - The type of attachment. Valid values can be found in the [AWS Documentation](https://docs.aws.amazon.com/networkmanager/latest/APIReference/API_ListAttachments.html#API_ListAttachments_RequestSyntax) +- `attachment_type` - (Required) The type of attachment. Valid values can be found in the [AWS Documentation](https://docs.aws.amazon.com/networkmanager/latest/APIReference/API_ListAttachments.html#API_ListAttachments_RequestSyntax) ## Attributes Reference