diff --git a/aws/resources/transit_gateway.go b/aws/resources/transit_gateway.go index 2d6798de..fe453586 100644 --- a/aws/resources/transit_gateway.go +++ b/aws/resources/transit_gateway.go @@ -5,9 +5,9 @@ import ( "fmt" "time" - "github.com/aws/aws-sdk-go/aws" - awsgo "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" + awsgo "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" + "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/cloud-nuke/logging" "github.com/gruntwork-io/cloud-nuke/report" @@ -30,7 +30,7 @@ const ( // Returns a formatted string of TransitGateway IDs func (tgw *TransitGateways) getAll(c context.Context, configObj config.Config) ([]*string, error) { - result, err := tgw.Client.DescribeTransitGatewaysWithContext(tgw.Context, &ec2.DescribeTransitGatewaysInput{}) + result, err := tgw.Client.DescribeTransitGateways(tgw.Context, &ec2.DescribeTransitGatewaysInput{}) if err != nil { logging.Debugf("[DescribeTransitGateways Failed] %s", err) return nil, errors.WithStackTrace(err) @@ -45,11 +45,11 @@ func (tgw *TransitGateways) getAll(c context.Context, configObj config.Config) ( Time: transitGateway.CreationTime, Name: hostNameTagValue, }) && - awsgo.StringValue(transitGateway.State) != "deleted" && awsgo.StringValue(transitGateway.State) != "deleting" { + transitGateway.State != types.TransitGatewayStateDeleted && transitGateway.State != types.TransitGatewayStateDeleting { ids = append(ids, transitGateway.TransitGatewayId) } - if currentOwner != nil && transitGateway.OwnerId != nil && currentOwner != awsgo.StringValue(transitGateway.OwnerId) { + if currentOwner != nil && transitGateway.OwnerId != nil && currentOwner != awsgo.ToString(transitGateway.OwnerId) { tgw.SetNukableStatus(*transitGateway.TransitGatewayId, util.ErrDifferentOwner) continue } @@ -62,9 +62,9 @@ func (tgw *TransitGateways) getAll(c context.Context, configObj config.Config) ( tgw.VerifyNukablePermissions(ids, func(id *string) error { params := &ec2.DeleteTransitGatewayInput{ TransitGatewayId: id, - DryRun: aws.Bool(true), // dry run set as true , checks permission without actualy making the request + DryRun: awsgo.Bool(true), // dry run set as true , checks permission without actualy making the request } - _, err := tgw.Client.DeleteTransitGatewayWithContext(tgw.Context, params) + _, err := tgw.Client.DeleteTransitGateway(tgw.Context, params) return err }) @@ -77,7 +77,7 @@ func (tgw *TransitGateways) nuke(id *string) error { return errors.WithStackTrace(err) } - if _, err := tgw.Client.DeleteTransitGatewayWithContext(tgw.Context, &ec2.DeleteTransitGatewayInput{ + if _, err := tgw.Client.DeleteTransitGateway(tgw.Context, &ec2.DeleteTransitGatewayInput{ TransitGatewayId: id, }); err != nil { return errors.WithStackTrace(err) @@ -87,76 +87,76 @@ func (tgw *TransitGateways) nuke(id *string) error { } func (tgw *TransitGateways) nukeAttachments(id *string) error { - logging.Debugf("nuking transit gateway attachments for %v", awsgo.StringValue(id)) - output, err := tgw.Client.DescribeTransitGatewayAttachmentsWithContext(tgw.Context, &ec2.DescribeTransitGatewayAttachmentsInput{ - Filters: []*ec2.Filter{ + logging.Debugf("nuking transit gateway attachments for %v", awsgo.ToString(id)) + output, err := tgw.Client.DescribeTransitGatewayAttachments(tgw.Context, &ec2.DescribeTransitGatewayAttachmentsInput{ + Filters: []types.Filter{ { Name: awsgo.String("transit-gateway-id"), - Values: []*string{ - id, + Values: []string{ + awsgo.ToString(id), }, }, { Name: awsgo.String("state"), - Values: []*string{ - awsgo.String("available"), + Values: []string{ + "available", }, }, }, }) if err != nil { - logging.Errorf("[Failed] unable to describe the transit gateway attachments for %v : %s", awsgo.StringValue(id), err) + logging.Errorf("[Failed] unable to describe the transit gateway attachments for %v : %s", awsgo.ToString(id), err) return errors.WithStackTrace(err) } - logging.Debugf("%v attachment(s) found with %v", len(output.TransitGatewayAttachments), awsgo.StringValue(id)) + logging.Debugf("%v attachment(s) found with %v", len(output.TransitGatewayAttachments), awsgo.ToString(id)) for _, attachments := range output.TransitGatewayAttachments { var ( err error - attachmentType = awsgo.StringValue(attachments.ResourceType) + attachmentType = attachments.ResourceType now = time.Now() ) switch attachmentType { case TransitGatewayAttachmentTypePeering: - logging.Debugf("[Execution] deleting the attachments of type %v for %v ", attachmentType, awsgo.StringValue(id)) + logging.Debugf("[Execution] deleting the attachments of type %v for %v ", attachmentType, awsgo.ToString(id)) // Delete the Transit Gateway Peering Attachment - _, err = tgw.Client.DeleteTransitGatewayPeeringAttachmentWithContext(tgw.Context, &ec2.DeleteTransitGatewayPeeringAttachmentInput{ + _, err = tgw.Client.DeleteTransitGatewayPeeringAttachment(tgw.Context, &ec2.DeleteTransitGatewayPeeringAttachmentInput{ TransitGatewayAttachmentId: attachments.TransitGatewayAttachmentId, }) case TransitGatewayAttachmentTypeVPC: - logging.Debugf("[Execution] deleting the attachments of type %v for %v ", attachmentType, awsgo.StringValue(id)) + logging.Debugf("[Execution] deleting the attachments of type %v for %v ", attachmentType, awsgo.ToString(id)) // Delete the Transit Gateway VPC Attachment - _, err = tgw.Client.DeleteTransitGatewayVpcAttachmentWithContext(tgw.Context, &ec2.DeleteTransitGatewayVpcAttachmentInput{ + _, err = tgw.Client.DeleteTransitGatewayVpcAttachment(tgw.Context, &ec2.DeleteTransitGatewayVpcAttachmentInput{ TransitGatewayAttachmentId: attachments.TransitGatewayAttachmentId, }) case TransitGatewayAttachmentTypeConnect: - logging.Debugf("[Execution] deleting the attachments of type %v for %v ", attachmentType, awsgo.StringValue(id)) + logging.Debugf("[Execution] deleting the attachments of type %v for %v ", attachmentType, awsgo.ToString(id)) // Delete the Transit Gateway Connect Attachment - _, err = tgw.Client.DeleteTransitGatewayConnectWithContext(tgw.Context, &ec2.DeleteTransitGatewayConnectInput{ + _, err = tgw.Client.DeleteTransitGatewayConnect(tgw.Context, &ec2.DeleteTransitGatewayConnectInput{ TransitGatewayAttachmentId: attachments.TransitGatewayAttachmentId, }) default: err = fmt.Errorf("%v typed transit gateway attachment nuking not handled", attachmentType) } if err != nil { - logging.Errorf("[Failed] unable to delete the transit gateway peernig attachment for %v : %s", awsgo.StringValue(id), err) + logging.Errorf("[Failed] unable to delete the transit gateway peernig attachment for %v : %s", awsgo.ToString(id), err) return err } if err := tgw.WaitUntilTransitGatewayAttachmentDeleted(id, attachmentType); err != nil { - logging.Errorf("[Failed] unable to wait until nuking the transit gateway attachment with type %v for %v : %s", attachmentType,awsgo.StringValue(id), err) + logging.Errorf("[Failed] unable to wait until nuking the transit gateway attachment with type %v for %v : %s", attachmentType, awsgo.ToString(id), err) return errors.WithStackTrace(err) } logging.Debugf("waited %v to nuke the attachment", time.Since(now)) } - logging.Debugf("[Ok] successfully nuked all the attachments on %v", awsgo.StringValue(id)) + logging.Debugf("[Ok] successfully nuked all the attachments on %v", awsgo.ToString(id)) return nil } -func (tgw *TransitGateways) WaitUntilTransitGatewayAttachmentDeleted(id *string, attachmentType string) error { +func (tgw *TransitGateways) WaitUntilTransitGatewayAttachmentDeleted(id *string, attachmentType types.TransitGatewayAttachmentResourceType) error { timeoutCtx, cancel := context.WithTimeout(tgw.Context, 5*time.Minute) defer cancel() @@ -168,19 +168,19 @@ func (tgw *TransitGateways) WaitUntilTransitGatewayAttachmentDeleted(id *string, case <-timeoutCtx.Done(): return fmt.Errorf("transit gateway attachments deletion check timed out after 5 minute") case <-ticker.C: - output, err := tgw.Client.DescribeTransitGatewayAttachmentsWithContext(tgw.Context, &ec2.DescribeTransitGatewayAttachmentsInput{ - Filters: []*ec2.Filter{ + output, err := tgw.Client.DescribeTransitGatewayAttachments(tgw.Context, &ec2.DescribeTransitGatewayAttachmentsInput{ + Filters: []types.Filter{ { Name: awsgo.String("transit-gateway-id"), - Values: []*string{ - id, + Values: []string{ + awsgo.ToString(id), }, }, { Name: awsgo.String("state"), - Values: []*string{ - awsgo.String("available"), - awsgo.String("deleting"), + Values: []string{ + "available", + "deleting", }, }, }, @@ -220,7 +220,7 @@ func (tgw *TransitGateways) nukeAll(ids []*string) error { // Record status of this resource e := report.Entry{ - Identifier: aws.StringValue(id), + Identifier: awsgo.ToString(id), ResourceType: "Transit Gateway", Error: err, } diff --git a/aws/resources/transit_gateway_test.go b/aws/resources/transit_gateway_test.go index 5d345872..00405c8a 100644 --- a/aws/resources/transit_gateway_test.go +++ b/aws/resources/transit_gateway_test.go @@ -5,17 +5,15 @@ import ( "testing" "time" + "github.com/aws/aws-sdk-go-v2/service/ec2" + "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/aws/aws-sdk-go/aws" - awsgo "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/request" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/aws/aws-sdk-go/service/ec2/ec2iface" "github.com/gruntwork-io/cloud-nuke/config" "github.com/stretchr/testify/require" ) type mockedTransitGateway struct { - ec2iface.EC2API + TransitGatewayAPI DescribeTransitGatewaysOutput ec2.DescribeTransitGatewaysOutput DeleteTransitGatewayOutput ec2.DeleteTransitGatewayOutput DescribeTransitGatewayAttachmentsOutput ec2.DescribeTransitGatewayAttachmentsOutput @@ -23,34 +21,31 @@ type mockedTransitGateway struct { DeleteTransitGatewayVpcAttachmentOutput ec2.DeleteTransitGatewayVpcAttachmentOutput DeleteVpnConnectionOutput ec2.DeleteVpnConnectionOutput DeleteTransitGatewayConnectOutput ec2.DeleteTransitGatewayConnectOutput - } -func (m mockedTransitGateway) DescribeTransitGatewaysWithContext(_ awsgo.Context, _ *ec2.DescribeTransitGatewaysInput, _ ...request.Option) (*ec2.DescribeTransitGatewaysOutput, error) { +func (m mockedTransitGateway) DescribeTransitGateways(ctx context.Context, params *ec2.DescribeTransitGatewaysInput, optFns ...func(*ec2.Options)) (*ec2.DescribeTransitGatewaysOutput, error) { return &m.DescribeTransitGatewaysOutput, nil } -func (m mockedTransitGateway) DeleteTransitGatewayWithContext(_ awsgo.Context, _ *ec2.DeleteTransitGatewayInput, _ ...request.Option) (*ec2.DeleteTransitGatewayOutput, error) { +func (m mockedTransitGateway) DeleteTransitGateway(ctx context.Context, params *ec2.DeleteTransitGatewayInput, optFns ...func(*ec2.Options)) (*ec2.DeleteTransitGatewayOutput, error) { return &m.DeleteTransitGatewayOutput, nil } -func (m mockedTransitGateway) DescribeTransitGatewayAttachmentsWithContext(awsgo.Context, *ec2.DescribeTransitGatewayAttachmentsInput, ...request.Option) (*ec2.DescribeTransitGatewayAttachmentsOutput, error) { +func (m mockedTransitGateway) DescribeTransitGatewayAttachments(ctx context.Context, params *ec2.DescribeTransitGatewayAttachmentsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeTransitGatewayAttachmentsOutput, error) { return &m.DescribeTransitGatewayAttachmentsOutput, nil } -func (m mockedTransitGateway) DeleteTransitGatewayPeeringAttachmentWithContext(aws.Context, *ec2.DeleteTransitGatewayPeeringAttachmentInput, ...request.Option) (*ec2.DeleteTransitGatewayPeeringAttachmentOutput, error) { +func (m mockedTransitGateway) DeleteTransitGatewayPeeringAttachment(ctx context.Context, params *ec2.DeleteTransitGatewayPeeringAttachmentInput, optFns ...func(*ec2.Options)) (*ec2.DeleteTransitGatewayPeeringAttachmentOutput, error) { return &m.DeleteTransitGatewayPeeringAttachmentOutput, nil } -func (m mockedTransitGateway) DeleteTransitGatewayVpcAttachmentWithContext(_ awsgo.Context, _ *ec2.DeleteTransitGatewayVpcAttachmentInput, _ ...request.Option) (*ec2.DeleteTransitGatewayVpcAttachmentOutput, error) { + +func (m mockedTransitGateway) DeleteTransitGatewayVpcAttachment(ctx context.Context, params *ec2.DeleteTransitGatewayVpcAttachmentInput, optFns ...func(*ec2.Options)) (*ec2.DeleteTransitGatewayVpcAttachmentOutput, error) { return &m.DeleteTransitGatewayVpcAttachmentOutput, nil } -func (m mockedTransitGateway) DeleteTransitGatewayConnectWithContext(_ awsgo.Context, _ *ec2.DeleteTransitGatewayConnectInput, _ ...request.Option) (*ec2.DeleteTransitGatewayConnectOutput, error) { +func (m mockedTransitGateway) DeleteTransitGatewayConnect(ctx context.Context, params *ec2.DeleteTransitGatewayConnectInput, optFns ...func(*ec2.Options)) (*ec2.DeleteTransitGatewayConnectOutput, error) { return &m.DeleteTransitGatewayConnectOutput, nil } -func (m mockedTransitGateway) WaitUntilTransitGatewayAttachmentDeleted(*string, string) error { - return nil -} func TestTransitGateways_GetAll(t *testing.T) { @@ -62,16 +57,16 @@ func TestTransitGateways_GetAll(t *testing.T) { tgw := TransitGateways{ Client: mockedTransitGateway{ DescribeTransitGatewaysOutput: ec2.DescribeTransitGatewaysOutput{ - TransitGateways: []*ec2.TransitGateway{ + TransitGateways: []types.TransitGateway{ { TransitGatewayId: aws.String(gatewayId1), CreationTime: aws.Time(now), - State: aws.String("available"), + State: "available", }, { TransitGatewayId: aws.String(gatewayId2), CreationTime: aws.Time(now.Add(1)), - State: aws.String("deleting"), + State: "deleting", }, }, }, diff --git a/aws/resources/transit_gateway_types.go b/aws/resources/transit_gateway_types.go index ad3656ef..75627c14 100644 --- a/aws/resources/transit_gateway_types.go +++ b/aws/resources/transit_gateway_types.go @@ -3,29 +3,34 @@ package resources import ( "context" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" awsgo "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/aws/aws-sdk-go/service/ec2/ec2iface" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/go-commons/errors" ) +type TransitGatewayAPI interface { + DescribeTransitGateways(ctx context.Context, params *ec2.DescribeTransitGatewaysInput, optFns ...func(*ec2.Options)) (*ec2.DescribeTransitGatewaysOutput, error) + DeleteTransitGateway(ctx context.Context, params *ec2.DeleteTransitGatewayInput, optFns ...func(*ec2.Options)) (*ec2.DeleteTransitGatewayOutput, error) + DescribeTransitGatewayAttachments(ctx context.Context, params *ec2.DescribeTransitGatewayAttachmentsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeTransitGatewayAttachmentsOutput, error) + DeleteTransitGatewayPeeringAttachment(ctx context.Context, params *ec2.DeleteTransitGatewayPeeringAttachmentInput, optFns ...func(*ec2.Options)) (*ec2.DeleteTransitGatewayPeeringAttachmentOutput, error) + DeleteTransitGatewayVpcAttachment(ctx context.Context, params *ec2.DeleteTransitGatewayVpcAttachmentInput, optFns ...func(*ec2.Options)) (*ec2.DeleteTransitGatewayVpcAttachmentOutput, error) + DeleteTransitGatewayConnect(ctx context.Context, params *ec2.DeleteTransitGatewayConnectInput, optFns ...func(*ec2.Options)) (*ec2.DeleteTransitGatewayConnectOutput, error) +} + // TransitGateways - represents all transit gateways type TransitGateways struct { BaseAwsResource - Client ec2iface.EC2API + Client TransitGatewayAPI Region string Ids []string } -func (tgw *TransitGateways) Init(session *session.Session) { - // to initialize base resource - // NOTE : This is madatory to initialize the nukables map - tgw.BaseAwsResource.Init(session) - tgw.Client = ec2.New(session) - +func (tgw *TransitGateways) InitV2(cfg aws.Config) { + tgw.Client = ec2.NewFromConfig(cfg) } +func (tgw *TransitGateways) IsUsingV2() bool { return true } // ResourceName - the simple name of the aws resource func (tgw *TransitGateways) ResourceName() string { diff --git a/go.mod b/go.mod index 6f740c19..845ed7ee 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,11 @@ go 1.21 require ( github.com/aws/aws-sdk-go v1.49.13 - github.com/aws/aws-sdk-go-v2 v1.31.0 + github.com/aws/aws-sdk-go-v2 v1.32.2 github.com/aws/aws-sdk-go-v2/config v1.27.24 github.com/aws/aws-sdk-go-v2/credentials v1.17.24 github.com/aws/aws-sdk-go-v2/service/amp v1.27.1 + github.com/aws/aws-sdk-go-v2/service/ec2 v1.184.0 github.com/aws/aws-sdk-go-v2/service/eventbridge v1.33.7 github.com/aws/aws-sdk-go-v2/service/scheduler v1.10.7 github.com/aws/aws-sdk-go-v2/service/sns v1.32.3 @@ -28,16 +29,16 @@ require ( atomicgo.dev/cursor v0.1.1 // indirect atomicgo.dev/keyboard v0.2.8 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.9 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.17 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.3 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.15 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.2 // indirect github.com/aws/aws-sdk-go-v2/service/sso v1.22.1 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.2 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.30.1 // indirect - github.com/aws/smithy-go v1.21.0 // indirect + github.com/aws/smithy-go v1.22.0 // indirect github.com/containerd/console v1.0.3 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index 16d1565f..89963969 100644 --- a/go.sum +++ b/go.sum @@ -15,30 +15,46 @@ github.com/MarvinJWendt/testza v0.4.2/go.mod h1:mSdhXiKH8sg/gQehJ63bINcCKp7RtYew github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk= github.com/aws/aws-sdk-go v1.49.13 h1:f4mGztsgnx2dR9r8FQYa9YW/RsKb+N7bgef4UGrOW1Y= github.com/aws/aws-sdk-go v1.49.13/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= -github.com/aws/aws-sdk-go-v2 v1.31.0 h1:3V05LbxTSItI5kUqNwhJrrrY1BAXxXt0sN0l72QmG5U= -github.com/aws/aws-sdk-go-v2 v1.31.0/go.mod h1:ztolYtaEUtdpf9Wftr31CJfLVjOnD/CVRkKOOYgF8hA= +github.com/aws/aws-sdk-go-v2 v1.16.7/go.mod h1:6CpKuLXg2w7If3ABZCl/qZ6rEgwtjZTn4eAf4RcEyuw= +github.com/aws/aws-sdk-go-v2 v1.32.2 h1:AkNLZEyYMLnx/Q/mSKkcMqwNFXMAvFto9bNsHqcTduI= +github.com/aws/aws-sdk-go-v2 v1.32.2/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo= github.com/aws/aws-sdk-go-v2/config v1.27.24 h1:NM9XicZ5o1CBU/MZaHwFtimRpWx9ohAUAqkG6AqSqPo= github.com/aws/aws-sdk-go-v2/config v1.27.24/go.mod h1:aXzi6QJTuQRVVusAO8/NxpdTeTyr/wRcybdDtfUwJSs= github.com/aws/aws-sdk-go-v2/credentials v1.17.24 h1:YclAsrnb1/GTQNt2nzv+756Iw4mF8AOzcDfweWwwm/M= github.com/aws/aws-sdk-go-v2/credentials v1.17.24/go.mod h1:Hld7tmnAkoBQdTMNYZGzztzKRdA4fCdn9L83LOoigac= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.9 h1:Aznqksmd6Rfv2HQN9cpqIV/lQRMaIpJkLLaJ1ZI76no= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.9/go.mod h1:WQr3MY7AxGNxaqAtsDWn+fBxmd4XvLkzeqQ8P1VM0/w= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.14/go.mod h1:kdjrMwHwrC3+FsKhNcCMJ7tUVj/8uSD5CZXeQ4wV6fM= github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18 h1:kYQ3H1u0ANr9KEKlGs/jTLrBFPo8P8NaH/w7A01NeeM= github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18/go.mod h1:r506HmK5JDUh9+Mw4CfGJGSSoqIiLCndAuqXuhbv67Y= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 h1:UAsR3xA31QGf79WzpG/ixT9FZvQlh5HY1NRqSHBNOCk= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21/go.mod h1:JNr43NFf5L9YaG3eKTm7HQzls9J+A9YYcGI5Quh1r2Y= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.8/go.mod h1:ZIV8GYoC6WLBW5KGs+o4rsc65/ozd+eQ0L31XF5VDwk= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18 h1:Z7IdFUONvTcvS7YuhtVxN99v2cCoHRXOS4mTr0B/pUc= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18/go.mod h1:DkKMmksZVVyat+Y+r1dEOgJEfUeA7UngIHWeKsi0yNc= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 h1:6jZVETqmYCadGFvrYEQfC5fAQmlo80CeL5psbno6r0s= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21/go.mod h1:1SR0GbLlnN3QUmYaflZNiH1ql+1qrSiB2vwcJ+4UM60= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.17 h1:Roo69qTpfu8OlJ2Tb7pAYVuF0CpuUMB0IYWwYP/4DZM= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.17/go.mod h1:NcWPxQzGM1USQggaTVwz6VpqMZPX1CvDJLDh6jnOCa4= github.com/aws/aws-sdk-go-v2/service/amp v1.27.1 h1:va9j7MGA8jBlQs9KujMlkSdnC26TuEJXv7ywnFjmTZ8= github.com/aws/aws-sdk-go-v2/service/amp v1.27.1/go.mod h1:QhmX7qjomjuHJjCJbW+QRdaCBM42v1eAbWvBVFrT1Vw= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.47.2 h1:81hrDgbXHL44WdY6M/fHGXLlv17qTpOFzutXRVDEk3Y= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.47.2/go.mod h1:VoBcwURHnJVCWuXHdqVuG03i2lUlHJ5DTTqDSyCdEcc= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.184.0 h1:SZnuDlml1uFv5ojh+QTxS+Yru89Hr3QYIUwWoY71frI= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.184.0/go.mod h1:kYXaB4FzyhEJjvrJ84oPnMElLiEAjGxxUunVW2tBSng= github.com/aws/aws-sdk-go-v2/service/eventbridge v1.33.7 h1:q+xiPu+Dk5MFC20ZjdGGhbihD39Xsih98epvVjnOjyE= github.com/aws/aws-sdk-go-v2/service/eventbridge v1.33.7/go.mod h1:iQCsmx9LyBMyMEkLCBVqnIAz+rfo6/ss3oLcYn26+no= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.3 h1:dT3MqvGhSoaIhRseqw2I0yH81l7wiR2vjs57O51EAm8= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.3/go.mod h1:GlAeCkHwugxdHaueRr4nhPuY+WW+gR8UjlcqzPr1SPI= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 h1:TToQNkvGguu209puTojY/ozlqy2d/SFNcoLIqTFi42g= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0/go.mod h1:0jp+ltwkf+SwG2fm/PKo8t4y8pJSgOCO4D8Lz3k0aHQ= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.8/go.mod h1:rDVhIMAX9N2r8nWxDUlbubvvaFMnfsm+3jAV7q+rpM4= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.15 h1:I9zMeF107l0rJrpnHpjEiiTSCKYAIw8mALiXcPsGBiA= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.15/go.mod h1:9xWJ3Q/S6Ojusz1UIkfycgD1mGirJfLLKqq3LPT7WN8= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.2 h1:s7NA1SOw8q/5c0wr8477yOPp0z+uBaXBnLE0XYb0POA= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.2/go.mod h1:fnjjWyAW/Pj5HYOxl9LJqWtEwS7W2qgcRLWP+uWbss0= github.com/aws/aws-sdk-go-v2/service/scheduler v1.10.7 h1:EcPyKUUo3neD2tDFKnq3TR3B9s2uZe9eWgxVQgixdzc= github.com/aws/aws-sdk-go-v2/service/scheduler v1.10.7/go.mod h1:MlNx35QVGG8TB2x1kOC0TKd9e93+RmFUE8HzYDLDLso= github.com/aws/aws-sdk-go-v2/service/sns v1.32.3 h1:LC5JBrEAdJ0SSRLfNcLzOLsfoc3xO/BAsHiUNcQfDI4= @@ -51,8 +67,9 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.2 h1:ORnrOK0C4WmYV/uYt3koHEWB github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.2/go.mod h1:xyFHA4zGxgYkdD73VeezHt3vSKEG9EmFnGwoKlP00u4= github.com/aws/aws-sdk-go-v2/service/sts v1.30.1 h1:+woJ607dllHJQtsnJLi52ycuqHMwlW+Wqm2Ppsfp4nQ= github.com/aws/aws-sdk-go-v2/service/sts v1.30.1/go.mod h1:jiNR3JqT15Dm+QWq2SRgh0x0bCNSRP2L25+CqPNpJlQ= -github.com/aws/smithy-go v1.21.0 h1:H7L8dtDRk0P1Qm6y0ji7MCYMQObJ5R9CRpyPhRUkLYA= -github.com/aws/smithy-go v1.21.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= +github.com/aws/smithy-go v1.12.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= +github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM= +github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/charmbracelet/lipgloss v0.6.0 h1:1StyZB9vBSOyuZxQUcUwGr17JmojPNm87inij9N3wJY= github.com/charmbracelet/lipgloss v0.6.0/go.mod h1:tHh2wr34xcHjC2HCXIlGSG1jaDF0S0atAUvBMP6Ppuk= @@ -68,6 +85,7 @@ github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= +github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs= github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= diff --git a/util/tag.go b/util/tag.go index 0e4c4dd1..5a4b7b60 100644 --- a/util/tag.go +++ b/util/tag.go @@ -1,6 +1,7 @@ package util import ( + "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/aws/aws-sdk-go/service/autoscaling" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/iam" @@ -27,6 +28,15 @@ func ConvertEC2TagsToMap(tags []*ec2.Tag) map[string]string { return tagMap } +func ConvertTypesTagsToMap(tags []types.Tag) map[string]string { + tagMap := make(map[string]string) + for _, tag := range tags { + tagMap[*tag.Key] = *tag.Value + } + + return tagMap +} + func ConvertAutoScalingTagsToMap(tags []*autoscaling.TagDescription) map[string]string { tagMap := make(map[string]string) for _, tag := range tags { @@ -63,8 +73,17 @@ func ConvertRDSTagsToMap(tags []*rds.Tag) map[string]string { return tagMap } -func GetEC2ResourceNameTagValue(tags []*ec2.Tag) *string { - tagMap := ConvertEC2TagsToMap(tags) +func GetEC2ResourceNameTagValue[T *ec2.Tag | types.Tag](tags []T) *string { + var tagMap map[string]string + + switch t := any(tags).(type) { + case []*ec2.Tag: + tagMap = ConvertEC2TagsToMap(t) + case []types.Tag: + tagMap = ConvertTypesTagsToMap(t) + default: + return nil + } if name, ok := tagMap["Name"]; ok { return &name