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

Migrate Network Manager resources to AWS SDK v2 #38915

Merged
merged 42 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9eb409b
feat: generate `v2` client
DanielRieske Aug 18, 2024
b456d7c
feat: migrate r/attachment_accepter to sdkv2
DanielRieske Aug 18, 2024
35ad479
feat: migrate r/connect_attachment to sdkv2
DanielRieske Aug 18, 2024
2d1998f
feat: migrate r/connect_peer to sdkv2
DanielRieske Aug 18, 2024
3390fe3
feat: migrate r/connection to sdkv2
DanielRieske Aug 18, 2024
ef8222e
feat: migrate d/connection to sdkv2
DanielRieske Aug 18, 2024
1de1526
feat: migrate d/connections to sdkv2
DanielRieske Aug 18, 2024
c481575
feat: migrate r/core_network_policy_attachment to sdkv2
DanielRieske Aug 18, 2024
1fcc1d1
feat: migrate d/core_network_policy_document to sdkv2
DanielRieske Aug 18, 2024
2fd2e59
feat: migrate r/core_network to sdkv2
DanielRieske Aug 18, 2024
7bea7c5
feat: migrate r/customer_gateway_association to sdkv2
DanielRieske Aug 18, 2024
5fea1a8
feat: migrate r/device to sdkv2
DanielRieske Aug 18, 2024
55ce508
feat: migrate d/device to sdkv2
DanielRieske Aug 18, 2024
06502ae
feat: migrate d/devices to sdkv2
DanielRieske Aug 18, 2024
6fa95cf
feat: migrate r/global_network to sdkv2
DanielRieske Aug 18, 2024
67a7b9b
feat: migrate d/global_network to sdkv2
DanielRieske Aug 18, 2024
730f983
feat: migrate d/global_networks to sdkv2
DanielRieske Aug 18, 2024
3589778
feat: migrate r/link_association to sdkv2
DanielRieske Aug 18, 2024
102e0ca
feat: migrate r/link to sdkv2
DanielRieske Aug 18, 2024
8e79c77
feat: migrate d/link to sdkv2
DanielRieske Aug 18, 2024
c6843c2
feat: migrate d/links to sdkv2
DanielRieske Aug 18, 2024
b5e1fe4
feat: migrate r/core_network_policy_attachment to sdkv2
DanielRieske Aug 18, 2024
5e39da6
feat: migrate d/site to sdkv2
DanielRieske Aug 18, 2024
058fa3d
feat: migrate r/site to sdkv2
DanielRieske Aug 18, 2024
3a16139
feat: migrate r/site_to_site_vpn_attachment to sdkv2
DanielRieske Aug 18, 2024
8a70d9f
feat: migrate d/sites to sdkv2
DanielRieske Aug 18, 2024
8f54208
feat: migrate r/transit_gateway_connect_peer_association to sdkv2
DanielRieske Aug 18, 2024
d25cbba
feat: migrate r/transit_gateway_peering to sdkv2
DanielRieske Aug 18, 2024
21f31f2
feat: migrate r/transit_gateway_registration to sdkv2
DanielRieske Aug 18, 2024
4c3eb1f
feat: migrate r/transit_gateway_route_table_attachment to sdkv2
DanielRieske Aug 18, 2024
f54c09a
feat: migrate r/vpc_attachment to sdkv2
DanielRieske Aug 18, 2024
0a1de9f
feat: migrate sweepers to sdkv2
DanielRieske Aug 18, 2024
a93979a
feat: migrate `errors` and exports
DanielRieske Aug 18, 2024
3e52c75
chore: add `AWSSDKVersion` to v2 on generate
DanielRieske Aug 18, 2024
3dfc6ca
feat: migrate r/core_network_policy_attachment change `aws-sdk-go` to v2
DanielRieske Aug 18, 2024
6e1f6f6
chore: ignore `state` attribute on import verify check
DanielRieske Aug 19, 2024
cdbb835
fix: `TestAccNetworkManagerCoreNetworkPolicyAttachment_expectPolicyEr…
DanielRieske Aug 19, 2024
cd99062
chore: run `make fix-constants`
DanielRieske Aug 19, 2024
5b4ebab
Merge branch 'main' into HEAD
ewbankkit Aug 19, 2024
66aa7e9
Fix 'TestAccNetworkManagerConnectAttachment_basic_NoDependsOn'.
ewbankkit Aug 20, 2024
b53290b
Fix 'TestAccNetworkManagerCoreNetworkPolicyDocumentDataSource_basic'.
ewbankkit Aug 20, 2024
0b43517
r/aws_networkmanager_vpc_attachment: Increase delete conflict retry t…
ewbankkit Aug 20, 2024
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/mwaa v1.29.5
github.com/aws/aws-sdk-go-v2/service/neptunegraph v1.11.1
github.com/aws/aws-sdk-go-v2/service/networkfirewall v1.41.1
github.com/aws/aws-sdk-go-v2/service/networkmanager v1.29.4
github.com/aws/aws-sdk-go-v2/service/networkmonitor v1.5.4
github.com/aws/aws-sdk-go-v2/service/oam v1.13.5
github.com/aws/aws-sdk-go-v2/service/opensearch v1.39.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ github.com/aws/aws-sdk-go-v2/service/neptunegraph v1.11.1 h1:Gk7iJhJQEwqldrKpMBh
github.com/aws/aws-sdk-go-v2/service/neptunegraph v1.11.1/go.mod h1:hnsmCvIWzyUk2RdWVSWnoHLwoKOQZToC9NoYsMagT3U=
github.com/aws/aws-sdk-go-v2/service/networkfirewall v1.41.1 h1:e1HnAPUIGkM1Eu4A5o83VQOp0MqWcW1BQXljHf8jCww=
github.com/aws/aws-sdk-go-v2/service/networkfirewall v1.41.1/go.mod h1:58gRrHmzxlsKfI3sNNXR4rz9RHv0g1Lk3Xl72PusRJc=
github.com/aws/aws-sdk-go-v2/service/networkmanager v1.29.4 h1:5LMCceliYKB9m3n2yHWBWBlg9cW/RmYGnYAty3Njotw=
github.com/aws/aws-sdk-go-v2/service/networkmanager v1.29.4/go.mod h1:cgdt9gLLpMm3ft6/MNTDmZ0pKPJa/sOPFkuWkyRQ9VY=
github.com/aws/aws-sdk-go-v2/service/networkmonitor v1.5.4 h1:u/vDkh3lVqFHavOO2ujv5tJ3pdAwa88eJL6zxu0uR8Q=
github.com/aws/aws-sdk-go-v2/service/networkmonitor v1.5.4/go.mod h1:kLZ+wCSQ04+zCjbymFTlNmlB78Mxi7dORmfbeChB7CY=
github.com/aws/aws-sdk-go-v2/service/oam v1.13.5 h1:51VYR5C0+/QEUrFURnwIGvT1eyiaKwnfQCoXVMRKtmg=
Expand Down
6 changes: 3 additions & 3 deletions internal/conns/awsclient_gen.go

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

98 changes: 51 additions & 47 deletions internal/service/networkmanager/attachment_accepter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/networkmanager"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/networkmanager"
awstypes "github.com/aws/aws-sdk-go-v2/service/networkmanager/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/enum"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/names"
Expand All @@ -23,8 +24,8 @@ import (
// AttachmentAccepter does not require AttachmentType. However, querying attachments for status updates requires knowing type
// To facilitate querying and waiters on specific attachment types, attachment_type set to required

// @SDKResource("aws_networkmanager_attachment_accepter")
func ResourceAttachmentAccepter() *schema.Resource {
// @SDKResource("aws_networkmanager_attachment_accepter", name="Attachment Accepter")
func resourceAttachmentAccepter() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceAttachmentAccepterCreate,
ReadWithoutTimeout: resourceAttachmentAccepterRead,
Expand All @@ -47,10 +48,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(networkmanager.AttachmentType_Values(), false),
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateDiagFunc: enum.Validate[awstypes.AttachmentType](),
},
"core_network_arn": {
Type: schema.TypeString,
Expand Down Expand Up @@ -87,89 +88,89 @@ func ResourceAttachmentAccepter() *schema.Resource {
func resourceAttachmentAccepterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

conn := meta.(*conns.AWSClient).NetworkManagerConn(ctx)
conn := meta.(*conns.AWSClient).NetworkManagerClient(ctx)

var state string
var state awstypes.AttachmentState
attachmentID := d.Get("attachment_id").(string)
attachmentType := d.Get("attachment_type").(string)
attachmentType := awstypes.AttachmentType(d.Get("attachment_type").(string))

switch attachmentType {
case networkmanager.AttachmentTypeVpc:
vpcAttachment, err := FindVPCAttachmentByID(ctx, conn, attachmentID)
case awstypes.AttachmentTypeVpc:
vpcAttachment, err := findVPCAttachmentByID(ctx, conn, attachmentID)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading Network Manager VPC Attachment (%s): %s", attachmentID, err)
}

state = aws.StringValue(vpcAttachment.Attachment.State)
state = vpcAttachment.Attachment.State

d.SetId(attachmentID)

case networkmanager.AttachmentTypeSiteToSiteVpn:
vpnAttachment, err := FindSiteToSiteVPNAttachmentByID(ctx, conn, attachmentID)
case awstypes.AttachmentTypeSiteToSiteVpn:
vpnAttachment, err := findSiteToSiteVPNAttachmentByID(ctx, conn, attachmentID)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading Network Manager Site To Site VPN Attachment (%s): %s", attachmentID, err)
}

state = aws.StringValue(vpnAttachment.Attachment.State)
state = vpnAttachment.Attachment.State

d.SetId(attachmentID)

case networkmanager.AttachmentTypeConnect:
connectAttachment, err := FindConnectAttachmentByID(ctx, conn, attachmentID)
case awstypes.AttachmentTypeConnect:
connectAttachment, err := findConnectAttachmentByID(ctx, conn, attachmentID)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading Network Manager Connect Attachment (%s): %s", attachmentID, err)
}

state = aws.StringValue(connectAttachment.Attachment.State)
state = connectAttachment.Attachment.State

d.SetId(attachmentID)

case networkmanager.AttachmentTypeTransitGatewayRouteTable:
tgwAttachment, err := FindTransitGatewayRouteTableAttachmentByID(ctx, conn, attachmentID)
case awstypes.AttachmentTypeTransitGatewayRouteTable:
tgwAttachment, err := findTransitGatewayRouteTableAttachmentByID(ctx, conn, attachmentID)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading Network Manager Transit Gateway Route Table Attachment (%s): %s", attachmentID, err)
}

state = aws.StringValue(tgwAttachment.Attachment.State)
state = tgwAttachment.Attachment.State

d.SetId(attachmentID)

default:
return sdkdiag.AppendErrorf(diags, "unsupported Network Manager Attachment type: %s", attachmentType)
}

if state == networkmanager.AttachmentStatePendingAttachmentAcceptance || state == networkmanager.AttachmentStatePendingTagAcceptance {
if state == awstypes.AttachmentStatePendingAttachmentAcceptance || state == awstypes.AttachmentStatePendingTagAcceptance {
input := &networkmanager.AcceptAttachmentInput{
AttachmentId: aws.String(attachmentID),
}

_, err := conn.AcceptAttachmentWithContext(ctx, input)
_, err := conn.AcceptAttachment(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "accepting Network Manager Attachment (%s): %s", attachmentID, err)
}

switch attachmentType {
case networkmanager.AttachmentTypeVpc:
case awstypes.AttachmentTypeVpc:
if _, err := waitVPCAttachmentAvailable(ctx, conn, attachmentID, d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Network Manager VPC Attachment (%s) to be attached: %s", attachmentID, err)
}

case networkmanager.AttachmentTypeSiteToSiteVpn:
case awstypes.AttachmentTypeSiteToSiteVpn:
if _, err := waitSiteToSiteVPNAttachmentAvailable(ctx, conn, attachmentID, d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Network Manager VPN Attachment (%s) create: %s", attachmentID, err)
}

case networkmanager.AttachmentTypeConnect:
case awstypes.AttachmentTypeConnect:
if _, err := waitConnectAttachmentAvailable(ctx, conn, attachmentID, d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Network Manager Connect Attachment (%s) create: %s", attachmentID, err)
}

case networkmanager.AttachmentTypeTransitGatewayRouteTable:
case awstypes.AttachmentTypeTransitGatewayRouteTable:
if _, err := waitTransitGatewayRouteTableAttachmentAvailable(ctx, conn, attachmentID, d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Network Manager Transit Gateway Route Table Attachment (%s) create: %s", attachmentID, err)
}
Expand All @@ -182,13 +183,14 @@ func resourceAttachmentAccepterCreate(ctx context.Context, d *schema.ResourceDat
func resourceAttachmentAccepterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

conn := meta.(*conns.AWSClient).NetworkManagerConn(ctx)
conn := meta.(*conns.AWSClient).NetworkManagerClient(ctx)

var a *networkmanager.Attachment
var a *awstypes.Attachment
attachmentType := awstypes.AttachmentType(d.Get("attachment_type").(string))

switch aType := d.Get("attachment_type"); aType {
case networkmanager.AttachmentTypeVpc:
vpcAttachment, err := FindVPCAttachmentByID(ctx, conn, d.Id())
switch attachmentType {
case awstypes.AttachmentTypeVpc:
vpcAttachment, err := findVPCAttachmentByID(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] Network Manager VPC Attachment %s not found, removing from state", d.Id())
Expand All @@ -202,8 +204,8 @@ func resourceAttachmentAccepterRead(ctx context.Context, d *schema.ResourceData,

a = vpcAttachment.Attachment

case networkmanager.AttachmentTypeSiteToSiteVpn:
vpnAttachment, err := FindSiteToSiteVPNAttachmentByID(ctx, conn, d.Id())
case awstypes.AttachmentTypeSiteToSiteVpn:
vpnAttachment, err := findSiteToSiteVPNAttachmentByID(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] Network Manager Site To Site VPN Attachment %s not found, removing from state", d.Id())
Expand All @@ -217,8 +219,8 @@ func resourceAttachmentAccepterRead(ctx context.Context, d *schema.ResourceData,

a = vpnAttachment.Attachment

case networkmanager.AttachmentTypeConnect:
connectAttachment, err := FindConnectAttachmentByID(ctx, conn, d.Id())
case awstypes.AttachmentTypeConnect:
connectAttachment, err := findConnectAttachmentByID(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] Network Manager Connect Attachment %s not found, removing from state", d.Id())
Expand All @@ -232,8 +234,8 @@ func resourceAttachmentAccepterRead(ctx context.Context, d *schema.ResourceData,

a = connectAttachment.Attachment

case networkmanager.AttachmentTypeTransitGatewayRouteTable:
tgwAttachment, err := FindTransitGatewayRouteTableAttachmentByID(ctx, conn, d.Id())
case awstypes.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())
Expand Down Expand Up @@ -263,15 +265,17 @@ func resourceAttachmentAccepterRead(ctx context.Context, d *schema.ResourceData,
func resourceAttachmentAccepterDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

conn := meta.(*conns.AWSClient).NetworkManagerConn(ctx)
conn := meta.(*conns.AWSClient).NetworkManagerClient(ctx)

attachmentType := awstypes.AttachmentType(d.Get("attachment_type").(string))

switch d.Get("attachment_type") {
case networkmanager.AttachmentTypeVpc:
_, err := conn.DeleteAttachmentWithContext(ctx, &networkmanager.DeleteAttachmentInput{
switch attachmentType {
case awstypes.AttachmentTypeVpc:
_, err := conn.DeleteAttachment(ctx, &networkmanager.DeleteAttachmentInput{
AttachmentId: aws.String(d.Id()),
})

if tfawserr.ErrCodeEquals(err, networkmanager.ErrCodeResourceNotFoundException) {
if errs.IsA[*awstypes.ResourceNotFoundException](err) {
return diags
}

Expand Down
Loading
Loading