From 174aedba2173595e3f882a1748581d2e8999889f Mon Sep 17 00:00:00 2001 From: AJ Date: Wed, 20 Nov 2024 00:44:11 +0000 Subject: [PATCH] change port ec2 ipam byoasn, ec2 ipam custom allocation, ec2 ipam pool, ec2 ipam resource discovery, ec2 ipam scope, ec2 ipam to awsSDKv2 #770 (#790) --- aws/resources/ec2_ipam.go | 96 ++++++------- aws/resources/ec2_ipam_byoasn.go | 21 ++- aws/resources/ec2_ipam_byoasn_test.go | 21 ++- aws/resources/ec2_ipam_byoasn_types.go | 27 ++-- aws/resources/ec2_ipam_custom_allocation.go | 77 +++++------ .../ec2_ipam_custom_allocation_test.go | 55 ++++---- .../ec2_ipam_custom_allocation_types.go | 26 ++-- aws/resources/ec2_ipam_pool.go | 66 ++++----- aws/resources/ec2_ipam_pool_test.go | 41 +++--- aws/resources/ec2_ipam_pool_types.go | 25 ++-- aws/resources/ec2_ipam_resource_discovery.go | 62 ++++----- .../ec2_ipam_resource_discovery_test.go | 40 +++--- .../ec2_ipam_resource_discovery_types.go | 25 ++-- aws/resources/ec2_ipam_scope.go | 63 +++++---- aws/resources/ec2_ipam_scope_test.go | 40 +++--- aws/resources/ec2_ipam_scope_types.go | 25 ++-- aws/resources/ec2_ipam_test.go | 126 +++++++++--------- aws/resources/ec2_ipam_types.go | 30 +++-- go.mod | 22 +-- go.sum | 44 +++--- v2_migration_report/output.md | 12 +- 21 files changed, 486 insertions(+), 458 deletions(-) diff --git a/aws/resources/ec2_ipam.go b/aws/resources/ec2_ipam.go index 00ee5aa0..a0ef49ef 100644 --- a/aws/resources/ec2_ipam.go +++ b/aws/resources/ec2_ipam.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" + "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" @@ -15,10 +15,10 @@ import ( "github.com/gruntwork-io/go-commons/errors" ) -func shouldIncludeIpamID(ipam *ec2.Ipam, firstSeenTime *time.Time, configObj config.Config) bool { +func shouldIncludeIpamID(ipam *types.Ipam, firstSeenTime *time.Time, configObj config.Config) bool { var ipamName string // get the tags as map - tagMap := util.ConvertEC2TagsToMap(ipam.Tags) + tagMap := util.ConvertTypesTagsToMap(ipam.Tags) if name, ok := tagMap["Name"]; ok { ipamName = name } @@ -32,40 +32,40 @@ func shouldIncludeIpamID(ipam *ec2.Ipam, firstSeenTime *time.Time, configObj con // Returns a formatted string of IPAM URLs func (ec2Ipam *EC2IPAMs) getAll(c context.Context, configObj config.Config) ([]*string, error) { - result := []*string{} + var result []*string var firstSeenTime *time.Time var err error - paginator := func(output *ec2.DescribeIpamsOutput, lastPage bool) bool { - for _, ipam := range output.Ipams { - firstSeenTime, err = util.GetOrCreateFirstSeen(c, ec2Ipam.Client, ipam.IpamId, util.ConvertEC2TagsToMap(ipam.Tags)) + params := &ec2.DescribeIpamsInput{ + MaxResults: aws.Int32(10), + } + + ipamsPaginator := ec2.NewDescribeIpamsPaginator(ec2Ipam.Client, params) + for ipamsPaginator.HasMorePages() { + page, errPage := ipamsPaginator.NextPage(c) + if errPage != nil { + return nil, errors.WithStackTrace(errPage) + } + + for _, ipam := range page.Ipams { + firstSeenTime, err = util.GetOrCreateFirstSeen(c, ec2Ipam.Client, ipam.IpamId, util.ConvertTypesTagsToMap(ipam.Tags)) if err != nil { logging.Error("Unable to retrieve tags") continue } // Check for include this ipam - if shouldIncludeIpamID(ipam, firstSeenTime, configObj) { + if shouldIncludeIpamID(&ipam, firstSeenTime, configObj) { result = append(result, ipam.IpamId) } } - return !lastPage - } - - params := &ec2.DescribeIpamsInput{ - MaxResults: awsgo.Int64(10), - } - - err = ec2Ipam.Client.DescribeIpamsPagesWithContext(ec2Ipam.Context, params, paginator) - if err != nil { - return nil, errors.WithStackTrace(err) } // checking the nukable permissions ec2Ipam.VerifyNukablePermissions(result, func(id *string) error { - _, err := ec2Ipam.Client.DeleteIpamWithContext(ec2Ipam.Context, &ec2.DeleteIpamInput{ + _, err := ec2Ipam.Client.DeleteIpam(ec2Ipam.Context, &ec2.DeleteIpamInput{ IpamId: id, Cascade: aws.Bool(true), - DryRun: awsgo.Bool(true), + DryRun: aws.Bool(true), }) return err }) @@ -73,14 +73,14 @@ func (ec2Ipam *EC2IPAMs) getAll(c context.Context, configObj config.Config) ([]* return result, nil } -// deProvisionPoolCIDRs : Detach the CIDR provisiond on the pool +// deProvisionPoolCIDRs : Detach the CIDR provisioned on the pool func (ec2Ipam *EC2IPAMs) deProvisionPoolCIDRs(poolID *string) error { - output, err := ec2Ipam.Client.GetIpamPoolCidrsWithContext(ec2Ipam.Context, &ec2.GetIpamPoolCidrsInput{ + output, err := ec2Ipam.Client.GetIpamPoolCidrs(ec2Ipam.Context, &ec2.GetIpamPoolCidrsInput{ IpamPoolId: poolID, - Filters: []*ec2.Filter{ + Filters: []types.Filter{ { - Name: awsgo.String("state"), - Values: awsgo.StringSlice([]string{"provisioned"}), + Name: aws.String("state"), + Values: []string{"provisioned"}, }, }, }) @@ -89,7 +89,7 @@ func (ec2Ipam *EC2IPAMs) deProvisionPoolCIDRs(poolID *string) error { } for _, poolCidr := range output.IpamPoolCidrs { - _, err := ec2Ipam.Client.DeprovisionIpamPoolCidrWithContext(ec2Ipam.Context, &ec2.DeprovisionIpamPoolCidrInput{ + _, err := ec2Ipam.Client.DeprovisionIpamPoolCidr(ec2Ipam.Context, &ec2.DeprovisionIpamPoolCidrInput{ IpamPoolId: poolID, Cidr: poolCidr.Cidr, }) @@ -97,7 +97,7 @@ func (ec2Ipam *EC2IPAMs) deProvisionPoolCIDRs(poolID *string) error { if err != nil { return errors.WithStackTrace(err) } - logging.Debugf("De-Provisioned CIDR(s) from IPAM Pool %s", aws.StringValue(poolID)) + logging.Debugf("De-Provisioned CIDR(s) from IPAM Pool %s", aws.ToString(poolID)) } return nil @@ -105,7 +105,7 @@ func (ec2Ipam *EC2IPAMs) deProvisionPoolCIDRs(poolID *string) error { // releaseCustomAllocations : Release the custom allocated CIDR(s) from the pool func (ec2Ipam *EC2IPAMs) releaseCustomAllocations(poolID *string) error { - output, err := ec2Ipam.Client.GetIpamPoolAllocationsWithContext(ec2Ipam.Context, &ec2.GetIpamPoolAllocationsInput{ + output, err := ec2Ipam.Client.GetIpamPoolAllocations(ec2Ipam.Context, &ec2.GetIpamPoolAllocationsInput{ IpamPoolId: poolID, }) if err != nil { @@ -114,10 +114,10 @@ func (ec2Ipam *EC2IPAMs) releaseCustomAllocations(poolID *string) error { for _, poolAllocation := range output.IpamPoolAllocations { // we only can release the custom allocations - if *poolAllocation.ResourceType != "custom" { + if poolAllocation.ResourceType != types.IpamPoolAllocationResourceTypeCustom { continue } - _, err := ec2Ipam.Client.ReleaseIpamPoolAllocationWithContext(ec2Ipam.Context, &ec2.ReleaseIpamPoolAllocationInput{ + _, err := ec2Ipam.Client.ReleaseIpamPoolAllocation(ec2Ipam.Context, &ec2.ReleaseIpamPoolAllocationInput{ IpamPoolId: poolID, IpamPoolAllocationId: poolAllocation.IpamPoolAllocationId, Cidr: poolAllocation.Cidr, @@ -126,7 +126,7 @@ func (ec2Ipam *EC2IPAMs) releaseCustomAllocations(poolID *string) error { if err != nil { return errors.WithStackTrace(err) } - logging.Debugf("Release custom allocated CIDR(s) from IPAM Pool %s", aws.StringValue(poolID)) + logging.Debugf("Release custom allocated CIDR(s) from IPAM Pool %s", aws.ToString(poolID)) } return nil @@ -139,8 +139,8 @@ func (ec2Ipam *EC2IPAMs) releaseCustomAllocations(poolID *string) error { // We cannot delete an IPAM pool if there are allocations in it or CIDRs provisioned to it. We must first release the allocations and Deprovision CIDRs // from a pool before we can delete the pool func (ec2Ipam *EC2IPAMs) nukePublicIPAMPools(ipamID *string) error { - ipam, err := ec2Ipam.Client.DescribeIpamsWithContext(ec2Ipam.Context, &ec2.DescribeIpamsInput{ - IpamIds: aws.StringSlice([]string{*ipamID}), + ipam, err := ec2Ipam.Client.DescribeIpams(ec2Ipam.Context, &ec2.DescribeIpamsInput{ + IpamIds: []string{*ipamID}, }) if err != nil { logging.Errorf(fmt.Sprintf("Error describing IPAM %s: %s", *ipamID, err.Error())) @@ -148,10 +148,10 @@ func (ec2Ipam *EC2IPAMs) nukePublicIPAMPools(ipamID *string) error { } // Describe the scope to read the scope arn - scope, err := ec2Ipam.Client.DescribeIpamScopesWithContext(ec2Ipam.Context, &ec2.DescribeIpamScopesInput{ - IpamScopeIds: aws.StringSlice([]string{ + scope, err := ec2Ipam.Client.DescribeIpamScopes(ec2Ipam.Context, &ec2.DescribeIpamScopesInput{ + IpamScopeIds: []string{ *ipam.Ipams[0].PublicDefaultScopeId, - }), + }, }) if err != nil { @@ -160,13 +160,13 @@ func (ec2Ipam *EC2IPAMs) nukePublicIPAMPools(ipamID *string) error { } // get the pools which is assigned on the public scope of the IPAM - output, err := ec2Ipam.Client.DescribeIpamPoolsWithContext(ec2Ipam.Context, &ec2.DescribeIpamPoolsInput{ - Filters: []*ec2.Filter{ + output, err := ec2Ipam.Client.DescribeIpamPools(ec2Ipam.Context, &ec2.DescribeIpamPoolsInput{ + Filters: []types.Filter{ { Name: aws.String("ipam-scope-arn"), - Values: aws.StringSlice([]string{ + Values: []string{ *scope.IpamScopes[0].IpamScopeArn, - }), + }, }, }, }) @@ -191,14 +191,14 @@ func (ec2Ipam *EC2IPAMs) nukePublicIPAMPools(ipamID *string) error { } // delete ipam pool - _, err = ec2Ipam.Client.DeleteIpamPoolWithContext(ec2Ipam.Context, &ec2.DeleteIpamPoolInput{ + _, err = ec2Ipam.Client.DeleteIpamPool(ec2Ipam.Context, &ec2.DeleteIpamPoolInput{ IpamPoolId: pool.IpamPoolId, }) if err != nil { logging.Errorf("[Failed] Delete IPAM Pool %s", err) return errors.WithStackTrace(err) } - logging.Debugf("Deleted IPAM Pool %s from IPAM %s", aws.StringValue(pool.IpamPoolId), aws.StringValue(ipamID)) + logging.Debugf("Deleted IPAM Pool %s from IPAM %s", aws.ToString(pool.IpamPoolId), aws.ToString(ipamID)) } return nil @@ -220,7 +220,7 @@ func (ec2Ipam *EC2IPAMs) deleteIPAM(id *string) error { Cascade: aws.Bool(true), } - _, err := ec2Ipam.Client.DeleteIpamWithContext(ec2Ipam.Context, params) + _, err := ec2Ipam.Client.DeleteIpam(ec2Ipam.Context, params) return err } @@ -256,8 +256,8 @@ func (ec2Ipam *EC2IPAMs) nukeAll(ids []*string) error { for _, id := range ids { - if nukable, reason := ec2Ipam.IsNukable(awsgo.StringValue(id)); !nukable { - logging.Debugf("[Skipping] %s nuke because %v", awsgo.StringValue(id), reason) + if nukable, reason := ec2Ipam.IsNukable(aws.ToString(id)); !nukable { + logging.Debugf("[Skipping] %s nuke because %v", aws.ToString(id), reason) continue } @@ -265,7 +265,7 @@ func (ec2Ipam *EC2IPAMs) nukeAll(ids []*string) error { // Record status of this resource e := report.Entry{ - Identifier: aws.StringValue(id), + Identifier: aws.ToString(id), ResourceType: "IPAM", Error: err, } diff --git a/aws/resources/ec2_ipam_byoasn.go b/aws/resources/ec2_ipam_byoasn.go index 1acc06e6..a38d9040 100644 --- a/aws/resources/ec2_ipam_byoasn.go +++ b/aws/resources/ec2_ipam_byoasn.go @@ -3,9 +3,8 @@ package resources import ( "context" - "github.com/aws/aws-sdk-go/aws" - awsgo "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/cloud-nuke/logging" "github.com/gruntwork-io/cloud-nuke/report" @@ -14,12 +13,12 @@ import ( // Returns a formatted string of IPAM Byoasns func (byoasn *EC2IPAMByoasn) getAll(c context.Context, configObj config.Config) ([]*string, error) { - result := []*string{} + var result []*string params := &ec2.DescribeIpamByoasnInput{ MaxResults: &MaxResultCount, } - output, err := byoasn.Client.DescribeIpamByoasnWithContext(byoasn.Context, params) + output, err := byoasn.Client.DescribeIpamByoasn(byoasn.Context, params) if err != nil { return nil, errors.WithStackTrace(err) } @@ -30,9 +29,9 @@ func (byoasn *EC2IPAMByoasn) getAll(c context.Context, configObj config.Config) // checking the nukable permissions byoasn.VerifyNukablePermissions(result, func(id *string) error { - _, err := byoasn.Client.DisassociateIpamByoasnWithContext(byoasn.Context, &ec2.DisassociateIpamByoasnInput{ + _, err := byoasn.Client.DisassociateIpamByoasn(byoasn.Context, &ec2.DisassociateIpamByoasnInput{ Asn: id, - DryRun: awsgo.Bool(true), + DryRun: aws.Bool(true), }) return err }) @@ -50,18 +49,18 @@ func (byoasn *EC2IPAMByoasn) nukeAll(asns []*string) error { var list []*string for _, id := range asns { - if nukable, reason := byoasn.IsNukable(awsgo.StringValue(id)); !nukable { - logging.Debugf("[Skipping] %s nuke because %v", awsgo.StringValue(id), reason) + if nukable, reason := byoasn.IsNukable(aws.ToString(id)); !nukable { + logging.Debugf("[Skipping] %s nuke because %v", aws.ToString(id), reason) continue } - _, err := byoasn.Client.DisassociateIpamByoasnWithContext(byoasn.Context, &ec2.DisassociateIpamByoasnInput{ + _, err := byoasn.Client.DisassociateIpamByoasn(byoasn.Context, &ec2.DisassociateIpamByoasnInput{ Asn: id, }) // Record status of this resource e := report.Entry{ - Identifier: aws.StringValue(id), + Identifier: aws.ToString(id), ResourceType: "IPAM Byoasn", Error: err, } diff --git a/aws/resources/ec2_ipam_byoasn_test.go b/aws/resources/ec2_ipam_byoasn_test.go index cfa6d49f..6fe27fe5 100644 --- a/aws/resources/ec2_ipam_byoasn_test.go +++ b/aws/resources/ec2_ipam_byoasn_test.go @@ -5,27 +5,26 @@ import ( "testing" "github.com/aws/aws-sdk-go-v2/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/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/stretchr/testify/require" ) type mockedIPAMByoASN struct { - ec2iface.EC2API + EC2IPAMByoasnAPI DescribeIpamByoasnOutput ec2.DescribeIpamByoasnOutput DisassociateIpamByoasnOutput ec2.DisassociateIpamByoasnOutput } -func (m mockedIPAMByoASN) DescribeIpamByoasnWithContext(_ awsgo.Context, _ *ec2.DescribeIpamByoasnInput, _ ...request.Option) (*ec2.DescribeIpamByoasnOutput, error) { - return &m.DescribeIpamByoasnOutput, nil -} -func (m mockedIPAMByoASN) DisassociateIpamByoasnWithContext(_ awsgo.Context, _ *ec2.DisassociateIpamByoasnInput, _ ...request.Option) (*ec2.DisassociateIpamByoasnOutput, error) { +func (m mockedIPAMByoASN) DisassociateIpamByoasn(ctx context.Context, params *ec2.DisassociateIpamByoasnInput, optFns ...func(*ec2.Options)) (*ec2.DisassociateIpamByoasnOutput, error) { return &m.DisassociateIpamByoasnOutput, nil } +func (m mockedIPAMByoASN) DescribeIpamByoasn(ctx context.Context, params *ec2.DescribeIpamByoasnInput, optFns ...func(*ec2.Options)) (*ec2.DescribeIpamByoasnOutput, error) { + return &m.DescribeIpamByoasnOutput, nil +} + func TestIPAMByoASN_GetAll(t *testing.T) { t.Parallel() @@ -39,7 +38,7 @@ func TestIPAMByoASN_GetAll(t *testing.T) { ipam := EC2IPAMByoasn{ Client: mockedIPAMByoASN{ DescribeIpamByoasnOutput: ec2.DescribeIpamByoasnOutput{ - Byoasns: []*ec2.Byoasn{ + Byoasns: []types.Byoasn{ { Asn: aws.String(testId1), IpamId: aws.String(testName1), @@ -68,7 +67,7 @@ func TestIPAMByoASN_GetAll(t *testing.T) { EC2IPAM: tc.configObj, }) require.NoError(t, err) - require.Equal(t, tc.expected, awsgo.StringValueSlice(ids)) + require.Equal(t, tc.expected, aws.ToStringSlice(ids)) }) } } diff --git a/aws/resources/ec2_ipam_byoasn_types.go b/aws/resources/ec2_ipam_byoasn_types.go index fcad343b..288727d8 100644 --- a/aws/resources/ec2_ipam_byoasn_types.go +++ b/aws/resources/ec2_ipam_byoasn_types.go @@ -3,28 +3,33 @@ package resources import ( "context" - 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/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/go-commons/errors" ) -// IPAM Byoasn- represents all IPAMs +type EC2IPAMByoasnAPI interface { + DescribeIpamByoasn(ctx context.Context, params *ec2.DescribeIpamByoasnInput, optFns ...func(*ec2.Options)) (*ec2.DescribeIpamByoasnOutput, error) + DisassociateIpamByoasn(ctx context.Context, params *ec2.DisassociateIpamByoasnInput, optFns ...func(*ec2.Options)) (*ec2.DisassociateIpamByoasnOutput, error) +} + +// EC2IPAMByoasn IPAM Byoasn- represents all IPAMs type EC2IPAMByoasn struct { BaseAwsResource - Client ec2iface.EC2API + Client EC2IPAMByoasnAPI Region string Pools []string } -var MaxResultCount = int64(10) +var MaxResultCount = int32(10) -func (byoasn *EC2IPAMByoasn) Init(session *session.Session) { - byoasn.Client = ec2.New(session) +func (byoasn *EC2IPAMByoasn) InitV2(cfg aws.Config) { + byoasn.Client = ec2.NewFromConfig(cfg) } +func (byoasn *EC2IPAMByoasn) IsUsingV2() bool { return true } + // ResourceName - the simple name of the aws resource func (byoasn *EC2IPAMByoasn) ResourceName() string { return "ipam-byoasn" @@ -46,13 +51,13 @@ func (byoasn *EC2IPAMByoasn) GetAndSetIdentifiers(c context.Context, configObj c return nil, err } - byoasn.Pools = awsgo.StringValueSlice(identifiers) + byoasn.Pools = aws.ToStringSlice(identifiers) return byoasn.Pools, nil } // Nuke - nuke 'em all!!! func (byoasn *EC2IPAMByoasn) Nuke(identifiers []string) error { - if err := byoasn.nukeAll(awsgo.StringSlice(identifiers)); err != nil { + if err := byoasn.nukeAll(aws.StringSlice(identifiers)); err != nil { return errors.WithStackTrace(err) } diff --git a/aws/resources/ec2_ipam_custom_allocation.go b/aws/resources/ec2_ipam_custom_allocation.go index 4d3a7194..2cf3e54d 100644 --- a/aws/resources/ec2_ipam_custom_allocation.go +++ b/aws/resources/ec2_ipam_custom_allocation.go @@ -4,9 +4,9 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - awsgo "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" + "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" @@ -15,21 +15,22 @@ import ( // Get all active pools func (cs *EC2IPAMCustomAllocation) getPools() ([]*string, error) { - result := []*string{} - paginator := func(output *ec2.DescribeIpamPoolsOutput, lastPage bool) bool { - for _, p := range output.IpamPools { - result = append(result, p.IpamPoolId) - } - return !lastPage - } + var result []*string params := &ec2.DescribeIpamPoolsInput{ - MaxResults: awsgo.Int64(10), + MaxResults: aws.Int32(10), } - err := cs.Client.DescribeIpamPoolsPagesWithContext(cs.Context, params, paginator) - if err != nil { - return nil, errors.WithStackTrace(err) + poolsPaginator := ec2.NewDescribeIpamPoolsPaginator(cs.Client, params) + for poolsPaginator.HasMorePages() { + page, err := poolsPaginator.NextPage(cs.Context) + if err != nil { + return nil, errors.WithStackTrace(err) + } + + for _, p := range page.IpamPools { + result = append(result, p.IpamPoolId) + } } return result, nil @@ -37,13 +38,13 @@ func (cs *EC2IPAMCustomAllocation) getPools() ([]*string, error) { // getPoolAllocationCIDR retrieves the CIDR block associated with an IPAM pool allocation in AWS. func (cs *EC2IPAMCustomAllocation) getPoolAllocationCIDR(allocationID *string) (*string, error) { - // get the pool id curresponding to the allocation id + // get the pool id corresponding to the allocation id allocationIPAMPoolID, ok := cs.PoolAndAllocationMap[*allocationID] if !ok { return nil, errors.WithStackTrace(fmt.Errorf("unable to find the pool allocation with %s", *allocationID)) } - output, err := cs.Client.GetIpamPoolAllocationsWithContext(cs.Context, &ec2.GetIpamPoolAllocationsInput{ + output, err := cs.Client.GetIpamPoolAllocations(cs.Context, &ec2.GetIpamPoolAllocationsInput{ IpamPoolId: &allocationIPAMPoolID, IpamPoolAllocationId: allocationID, }) @@ -67,28 +68,28 @@ func (cs *EC2IPAMCustomAllocation) getAll(c context.Context, configObj config.Co } // check though the filters and see the custom allocations - result := []*string{} + var result []*string for _, pool := range activePools { - paginator := func(output *ec2.GetIpamPoolAllocationsOutput, lastPage bool) bool { - for _, allocation := range output.IpamPoolAllocations { - if *allocation.ResourceType == "custom" { - result = append(result, allocation.IpamPoolAllocationId) - cs.PoolAndAllocationMap[*allocation.IpamPoolAllocationId] = *pool - } - } - return !lastPage - } - // prepare the params params := &ec2.GetIpamPoolAllocationsInput{ - MaxResults: awsgo.Int64(int64(cs.MaxBatchSize())), + MaxResults: aws.Int32(int32(cs.MaxBatchSize())), IpamPoolId: pool, } - err := cs.Client.GetIpamPoolAllocationsPagesWithContext(cs.Context, params, paginator) - if err != nil { - logging.Debugf("[Failed] %s", err) - continue + allocationsPaginator := ec2.NewGetIpamPoolAllocationsPaginator(cs.Client, params) + for allocationsPaginator.HasMorePages() { + page, err := allocationsPaginator.NextPage(cs.Context) + if err != nil { + logging.Debugf("[Failed] %s", err) + continue + } + + for _, allocation := range page.IpamPoolAllocations { + if allocation.ResourceType == types.IpamPoolAllocationResourceTypeCustom { + result = append(result, allocation.IpamPoolAllocationId) + cs.PoolAndAllocationMap[*allocation.IpamPoolAllocationId] = *pool + } + } } } @@ -106,11 +107,11 @@ func (cs *EC2IPAMCustomAllocation) getAll(c context.Context, configObj config.Co return fmt.Errorf("unable to find the pool allocation with %s", *id) } - _, err = cs.Client.ReleaseIpamPoolAllocationWithContext(cs.Context, &ec2.ReleaseIpamPoolAllocationInput{ + _, err = cs.Client.ReleaseIpamPoolAllocation(cs.Context, &ec2.ReleaseIpamPoolAllocationInput{ IpamPoolId: &allocationIPAMPoolID, IpamPoolAllocationId: id, Cidr: cidr, - DryRun: awsgo.Bool(true), + DryRun: aws.Bool(true), }) return err }) @@ -130,8 +131,8 @@ func (cs *EC2IPAMCustomAllocation) nukeAll(ids []*string) error { for _, id := range ids { - if nukable, reason := cs.IsNukable(awsgo.StringValue(id)); !nukable { - logging.Debugf("[Skipping] %s nuke because %v", awsgo.StringValue(id), reason) + if nukable, reason := cs.IsNukable(aws.ToString(id)); !nukable { + logging.Debugf("[Skipping] %s nuke because %v", aws.ToString(id), reason) continue } @@ -148,7 +149,7 @@ func (cs *EC2IPAMCustomAllocation) nukeAll(ids []*string) error { } // Release the allocation - _, err = cs.Client.ReleaseIpamPoolAllocationWithContext(cs.Context, &ec2.ReleaseIpamPoolAllocationInput{ + _, err = cs.Client.ReleaseIpamPoolAllocation(cs.Context, &ec2.ReleaseIpamPoolAllocationInput{ IpamPoolId: &allocationIPAMPoolID, IpamPoolAllocationId: id, Cidr: cidr, @@ -156,7 +157,7 @@ func (cs *EC2IPAMCustomAllocation) nukeAll(ids []*string) error { // Record status of this resource e := report.Entry{ - Identifier: aws.StringValue(id), + Identifier: aws.ToString(id), ResourceType: "IPAM", Error: err, } diff --git a/aws/resources/ec2_ipam_custom_allocation_test.go b/aws/resources/ec2_ipam_custom_allocation_test.go index e1292c70..cf259cbf 100644 --- a/aws/resources/ec2_ipam_custom_allocation_test.go +++ b/aws/resources/ec2_ipam_custom_allocation_test.go @@ -4,40 +4,31 @@ import ( "context" "testing" - "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/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/stretchr/testify/require" ) -type mockedIPAMCustomAllocations struct { - ec2iface.EC2API - GetIpamPoolAllocationsOutput ec2.GetIpamPoolAllocationsOutput - ReleaseIpamPoolAllocationOutput ec2.ReleaseIpamPoolAllocationOutput - DescribeIpamPoolsOutput ec2.DescribeIpamPoolsOutput -} - -func (m mockedIPAMCustomAllocations) GetIpamPoolAllocationsPagesWithContext(_ awsgo.Context, _ *ec2.GetIpamPoolAllocationsInput, callback func(*ec2.GetIpamPoolAllocationsOutput, bool) bool, _ ...request.Option) error { - callback(&m.GetIpamPoolAllocationsOutput, true) - return nil -} - -func (m mockedIPAMCustomAllocations) DescribeIpamPoolsPagesWithContext(_ awsgo.Context, _ *ec2.DescribeIpamPoolsInput, callback func(*ec2.DescribeIpamPoolsOutput, bool) bool, _ ...request.Option) error { - callback(&m.DescribeIpamPoolsOutput, true) - return nil +func (m mockedIPAMCustomAllocations) DescribeIpamPools(ctx context.Context, params *ec2.DescribeIpamPoolsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeIpamPoolsOutput, error) { + return &m.DescribeIpamPoolsOutput, nil } - -func (m mockedIPAMCustomAllocations) GetIpamPoolAllocationsWithContext(_ awsgo.Context, _ *ec2.GetIpamPoolAllocationsInput, _ ...request.Option) (*ec2.GetIpamPoolAllocationsOutput, error) { +func (m mockedIPAMCustomAllocations) GetIpamPoolAllocations(ctx context.Context, params *ec2.GetIpamPoolAllocationsInput, optFns ...func(*ec2.Options)) (*ec2.GetIpamPoolAllocationsOutput, error) { return &m.GetIpamPoolAllocationsOutput, nil } -func (m mockedIPAMCustomAllocations) ReleaseIpamPoolAllocationWithContext(_ awsgo.Context, _ *ec2.ReleaseIpamPoolAllocationInput, _ ...request.Option) (*ec2.ReleaseIpamPoolAllocationOutput, error) { +func (m mockedIPAMCustomAllocations) ReleaseIpamPoolAllocation(ctx context.Context, params *ec2.ReleaseIpamPoolAllocationInput, optFns ...func(*ec2.Options)) (*ec2.ReleaseIpamPoolAllocationOutput, error) { return &m.ReleaseIpamPoolAllocationOutput, nil } +type mockedIPAMCustomAllocations struct { + EC2IPAMCustomAllocationAPI + DescribeIpamPoolsOutput ec2.DescribeIpamPoolsOutput + GetIpamPoolAllocationsOutput ec2.GetIpamPoolAllocationsOutput + ReleaseIpamPoolAllocationOutput ec2.ReleaseIpamPoolAllocationOutput +} + func TestIPAMCustomAllocation_GetAll(t *testing.T) { t.Parallel() @@ -51,24 +42,24 @@ func TestIPAMCustomAllocation_GetAll(t *testing.T) { ipam := EC2IPAMCustomAllocation{ Client: mockedIPAMCustomAllocations{ DescribeIpamPoolsOutput: ec2.DescribeIpamPoolsOutput{ - IpamPools: []*ec2.IpamPool{ + IpamPools: []types.IpamPool{ { IpamPoolId: aws.String(testPool1), }, }, }, GetIpamPoolAllocationsOutput: ec2.GetIpamPoolAllocationsOutput{ - IpamPoolAllocations: []*ec2.IpamPoolAllocation{ + IpamPoolAllocations: []types.IpamPoolAllocation{ { Cidr: aws.String("10.0.0.0/24"), IpamPoolAllocationId: aws.String(testId1), - ResourceType: aws.String("custom"), + ResourceType: types.IpamPoolAllocationResourceTypeCustom, }, { Cidr: aws.String("10.0.0.16/24"), IpamPoolAllocationId: aws.String(testId2), - ResourceType: aws.String("custom"), + ResourceType: types.IpamPoolAllocationResourceTypeCustom, }, }, }, @@ -91,7 +82,7 @@ func TestIPAMCustomAllocation_GetAll(t *testing.T) { EC2IPAM: tc.configObj, }) require.NoError(t, err) - require.Equal(t, tc.expected, awsgo.StringValueSlice(ids)) + require.Equal(t, tc.expected, aws.ToStringSlice(ids)) }) } } @@ -109,24 +100,24 @@ func TestIPAMCustomAllocation_NukeAll(t *testing.T) { ipam := EC2IPAMCustomAllocation{ Client: mockedIPAMCustomAllocations{ DescribeIpamPoolsOutput: ec2.DescribeIpamPoolsOutput{ - IpamPools: []*ec2.IpamPool{ + IpamPools: []types.IpamPool{ { IpamPoolId: aws.String(testPool1), }, }, }, GetIpamPoolAllocationsOutput: ec2.GetIpamPoolAllocationsOutput{ - IpamPoolAllocations: []*ec2.IpamPoolAllocation{ + IpamPoolAllocations: []types.IpamPoolAllocation{ { Cidr: aws.String("10.0.0.0/24"), IpamPoolAllocationId: aws.String(testId1), - ResourceType: aws.String("custom"), + ResourceType: types.IpamPoolAllocationResourceTypeCustom, }, { Cidr: aws.String("10.0.0.16/24"), IpamPoolAllocationId: aws.String(testId2), - ResourceType: aws.String("custom"), + ResourceType: types.IpamPoolAllocationResourceTypeCustom, }, }, }, diff --git a/aws/resources/ec2_ipam_custom_allocation_types.go b/aws/resources/ec2_ipam_custom_allocation_types.go index e19f2a0e..37a4ada0 100644 --- a/aws/resources/ec2_ipam_custom_allocation_types.go +++ b/aws/resources/ec2_ipam_custom_allocation_types.go @@ -3,28 +3,34 @@ package resources import ( "context" - 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/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/go-commons/errors" ) -// IPAM Byoasn- represents all IPAMs +type EC2IPAMCustomAllocationAPI interface { + DescribeIpamPools(ctx context.Context, params *ec2.DescribeIpamPoolsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeIpamPoolsOutput, error) + GetIpamPoolAllocations(ctx context.Context, params *ec2.GetIpamPoolAllocationsInput, optFns ...func(*ec2.Options)) (*ec2.GetIpamPoolAllocationsOutput, error) + ReleaseIpamPoolAllocation(ctx context.Context, params *ec2.ReleaseIpamPoolAllocationInput, optFns ...func(*ec2.Options)) (*ec2.ReleaseIpamPoolAllocationOutput, error) +} + +// EC2IPAMCustomAllocation IPAM Byoasn- represents all IPAMs type EC2IPAMCustomAllocation struct { BaseAwsResource - Client ec2iface.EC2API + Client EC2IPAMCustomAllocationAPI Region string Allocations []string PoolAndAllocationMap map[string]string } -func (cs *EC2IPAMCustomAllocation) Init(session *session.Session) { - cs.Client = ec2.New(session) +func (cs *EC2IPAMCustomAllocation) InitV2(cfg aws.Config) { + cs.Client = ec2.NewFromConfig(cfg) cs.PoolAndAllocationMap = make(map[string]string) } +func (cs *EC2IPAMCustomAllocation) IsUsingV2() bool { return true } + // ResourceName - the simple name of the aws resource func (cs *EC2IPAMCustomAllocation) ResourceName() string { return "ipam-custom-allocation" @@ -46,13 +52,13 @@ func (cs *EC2IPAMCustomAllocation) GetAndSetIdentifiers(c context.Context, confi return nil, err } - cs.Allocations = awsgo.StringValueSlice(identifiers) + cs.Allocations = aws.ToStringSlice(identifiers) return cs.Allocations, nil } // Nuke - nuke 'em all!!! func (cs *EC2IPAMCustomAllocation) Nuke(identifiers []string) error { - if err := cs.nukeAll(awsgo.StringSlice(identifiers)); err != nil { + if err := cs.nukeAll(aws.StringSlice(identifiers)); err != nil { return errors.WithStackTrace(err) } diff --git a/aws/resources/ec2_ipam_pool.go b/aws/resources/ec2_ipam_pool.go index 67676165..ac9833ca 100644 --- a/aws/resources/ec2_ipam_pool.go +++ b/aws/resources/ec2_ipam_pool.go @@ -4,9 +4,9 @@ import ( "context" "time" - "github.com/aws/aws-sdk-go/aws" - awsgo "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" + "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" @@ -14,10 +14,10 @@ import ( "github.com/gruntwork-io/go-commons/errors" ) -func shouldIncludeIpamPoolID(ipam *ec2.IpamPool, firstSeenTime *time.Time, configObj config.Config) bool { +func shouldIncludeIpamPoolID(ipam *types.IpamPool, firstSeenTime *time.Time, configObj config.Config) bool { var ipamPoolName string // get the tags as map - tagMap := util.ConvertEC2TagsToMap(ipam.Tags) + tagMap := util.ConvertTypesTagsToMap(ipam.Tags) if name, ok := tagMap["Name"]; ok { ipamPoolName = name } @@ -31,44 +31,44 @@ func shouldIncludeIpamPoolID(ipam *ec2.IpamPool, firstSeenTime *time.Time, confi // Returns a formatted string of IPAM URLs func (ec2Pool *EC2IPAMPool) getAll(c context.Context, configObj config.Config) ([]*string, error) { - result := []*string{} + var result []*string var firstSeenTime *time.Time var err error - paginator := func(output *ec2.DescribeIpamPoolsOutput, lastPage bool) bool { - for _, pool := range output.IpamPools { - firstSeenTime, err = util.GetOrCreateFirstSeen(c, ec2Pool.Client, pool.IpamPoolId, util.ConvertEC2TagsToMap(pool.Tags)) - if err != nil { - logging.Error("unable to retrieve firstseen tag") - continue - } - if shouldIncludeIpamPoolID(pool, firstSeenTime, configObj) { - result = append(result, pool.IpamPoolId) - } - } - return !lastPage - } - params := &ec2.DescribeIpamPoolsInput{ - MaxResults: awsgo.Int64(10), - Filters: []*ec2.Filter{ + MaxResults: aws.Int32(10), + Filters: []types.Filter{ { - Name: awsgo.String("state"), - Values: awsgo.StringSlice([]string{"create-complete"}), + Name: aws.String("state"), + Values: []string{"create-complete"}, }, }, } - err = ec2Pool.Client.DescribeIpamPoolsPagesWithContext(ec2Pool.Context, params, paginator) - if err != nil { - return nil, errors.WithStackTrace(err) + poolsPaginator := ec2.NewDescribeIpamPoolsPaginator(ec2Pool.Client, params) + for poolsPaginator.HasMorePages() { + page, errPaginator := poolsPaginator.NextPage(c) + if errPaginator != nil { + return nil, errors.WithStackTrace(errPaginator) + } + + for _, pool := range page.IpamPools { + firstSeenTime, err = util.GetOrCreateFirstSeen(c, ec2Pool.Client, pool.IpamPoolId, util.ConvertTypesTagsToMap(pool.Tags)) + if err != nil { + logging.Error("unable to retrieve first seen tag") + continue + } + if shouldIncludeIpamPoolID(&pool, firstSeenTime, configObj) { + result = append(result, pool.IpamPoolId) + } + } } // checking the nukable permissions ec2Pool.VerifyNukablePermissions(result, func(id *string) error { - _, err := ec2Pool.Client.DeleteIpamPoolWithContext(ec2Pool.Context, &ec2.DeleteIpamPoolInput{ + _, err := ec2Pool.Client.DeleteIpamPool(ec2Pool.Context, &ec2.DeleteIpamPoolInput{ IpamPoolId: id, - DryRun: awsgo.Bool(true), + DryRun: aws.Bool(true), }) return err }) @@ -88,18 +88,18 @@ func (pool *EC2IPAMPool) nukeAll(ids []*string) error { for _, id := range ids { - if nukable, reason := pool.IsNukable(awsgo.StringValue(id)); !nukable { - logging.Debugf("[Skipping] %s nuke because %v", awsgo.StringValue(id), reason) + if nukable, reason := pool.IsNukable(aws.ToString(id)); !nukable { + logging.Debugf("[Skipping] %s nuke because %v", aws.ToString(id), reason) continue } - _, err := pool.Client.DeleteIpamPoolWithContext(pool.Context, &ec2.DeleteIpamPoolInput{ + _, err := pool.Client.DeleteIpamPool(pool.Context, &ec2.DeleteIpamPoolInput{ IpamPoolId: id, }) // Record status of this resource e := report.Entry{ - Identifier: aws.StringValue(id), + Identifier: aws.ToString(id), ResourceType: "IPAM Pool", Error: err, } diff --git a/aws/resources/ec2_ipam_pool_test.go b/aws/resources/ec2_ipam_pool_test.go index c8c79840..3e85ee67 100644 --- a/aws/resources/ec2_ipam_pool_test.go +++ b/aws/resources/ec2_ipam_pool_test.go @@ -7,26 +7,25 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/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/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/util" "github.com/stretchr/testify/require" ) type mockedIPAMPools struct { - ec2iface.EC2API + EC2IPAMPoolAPI DescribeIpamPoolsOutput ec2.DescribeIpamPoolsOutput DeleteIpamPoolOutput ec2.DeleteIpamPoolOutput } -func (m mockedIPAMPools) DescribeIpamPoolsPagesWithContext(_ awsgo.Context, _ *ec2.DescribeIpamPoolsInput, callback func(*ec2.DescribeIpamPoolsOutput, bool) bool, _ ...request.Option) error { - callback(&m.DescribeIpamPoolsOutput, true) - return nil +func (m mockedIPAMPools) DescribeIpamPools(ctx context.Context, params *ec2.DescribeIpamPoolsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeIpamPoolsOutput, error) { + return &m.DescribeIpamPoolsOutput, nil + } -func (m mockedIPAMPools) DeleteIpamPoolWithContext(_ awsgo.Context, _ *ec2.DeleteIpamPoolInput, _ ...request.Option) (*ec2.DeleteIpamPoolOutput, error) { + +func (m mockedIPAMPools) DeleteIpamPool(ctx context.Context, params *ec2.DeleteIpamPoolInput, optFns ...func(*ec2.Options)) (*ec2.DeleteIpamPoolOutput, error) { return &m.DeleteIpamPoolOutput, nil } @@ -47,30 +46,30 @@ func TestIPAMPool_GetAll(t *testing.T) { ipam := EC2IPAMPool{ Client: mockedIPAMPools{ DescribeIpamPoolsOutput: ec2.DescribeIpamPoolsOutput{ - IpamPools: []*ec2.IpamPool{ + IpamPools: []types.IpamPool{ { IpamPoolId: aws.String(testId1), - Tags: []*ec2.Tag{ + Tags: []types.Tag{ { - Key: awsgo.String("Name"), - Value: awsgo.String(testName1), + Key: aws.String("Name"), + Value: aws.String(testName1), }, { - Key: awsgo.String(util.FirstSeenTagKey), - Value: awsgo.String(util.FormatTimestamp(now)), + Key: aws.String(util.FirstSeenTagKey), + Value: aws.String(util.FormatTimestamp(now)), }, }, }, { IpamPoolId: aws.String(testId2), - Tags: []*ec2.Tag{ + Tags: []types.Tag{ { - Key: awsgo.String("Name"), - Value: awsgo.String(testName2), + Key: aws.String("Name"), + Value: aws.String(testName2), }, { - Key: awsgo.String(util.FirstSeenTagKey), - Value: awsgo.String(util.FormatTimestamp(now)), + Key: aws.String(util.FirstSeenTagKey), + Value: aws.String(util.FormatTimestamp(now)), }, }, }, @@ -114,7 +113,7 @@ func TestIPAMPool_GetAll(t *testing.T) { EC2IPAMPool: tc.configObj, }) require.NoError(t, err) - require.Equal(t, tc.expected, awsgo.StringValueSlice(ids)) + require.Equal(t, tc.expected, aws.ToStringSlice(ids)) }) } } diff --git a/aws/resources/ec2_ipam_pool_types.go b/aws/resources/ec2_ipam_pool_types.go index 1c55a7d2..5379a296 100644 --- a/aws/resources/ec2_ipam_pool_types.go +++ b/aws/resources/ec2_ipam_pool_types.go @@ -3,26 +3,31 @@ package resources import ( "context" - 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/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/go-commons/errors" ) -// IPAM Pool- represents all IPAMs +type EC2IPAMPoolAPI interface { + DescribeIpamPools(ctx context.Context, params *ec2.DescribeIpamPoolsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeIpamPoolsOutput, error) + DeleteIpamPool(ctx context.Context, params *ec2.DeleteIpamPoolInput, optFns ...func(*ec2.Options)) (*ec2.DeleteIpamPoolOutput, error) +} + +// EC2IPAMPool IPAM Pool- represents all IPAMs type EC2IPAMPool struct { BaseAwsResource - Client ec2iface.EC2API + Client EC2IPAMPoolAPI Region string Pools []string } -func (pool *EC2IPAMPool) Init(session *session.Session) { - pool.Client = ec2.New(session) +func (pool *EC2IPAMPool) InitV2(cfg aws.Config) { + pool.Client = ec2.NewFromConfig(cfg) } +func (pool *EC2IPAMPool) IsUsingV2() bool { return true } + // ResourceName - the simple name of the aws resource func (pool *EC2IPAMPool) ResourceName() string { return "ipam-pool" @@ -48,13 +53,13 @@ func (pool *EC2IPAMPool) GetAndSetIdentifiers(c context.Context, configObj confi return nil, err } - pool.Pools = awsgo.StringValueSlice(identifiers) + pool.Pools = aws.ToStringSlice(identifiers) return pool.Pools, nil } // Nuke - nuke 'em all!!! func (pool *EC2IPAMPool) Nuke(identifiers []string) error { - if err := pool.nukeAll(awsgo.StringSlice(identifiers)); err != nil { + if err := pool.nukeAll(aws.StringSlice(identifiers)); err != nil { return errors.WithStackTrace(err) } diff --git a/aws/resources/ec2_ipam_resource_discovery.go b/aws/resources/ec2_ipam_resource_discovery.go index 1204746b..f1135ec9 100644 --- a/aws/resources/ec2_ipam_resource_discovery.go +++ b/aws/resources/ec2_ipam_resource_discovery.go @@ -4,8 +4,9 @@ import ( "context" "time" - awsgo "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" + "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" @@ -13,10 +14,10 @@ import ( "github.com/gruntwork-io/go-commons/errors" ) -func shouldIncludeIpamResourceID(ipam *ec2.IpamResourceDiscovery, firstSeenTime *time.Time, configObj config.Config) bool { +func shouldIncludeIpamResourceID(ipam *types.IpamResourceDiscovery, firstSeenTime *time.Time, configObj config.Config) bool { var ipamResourceName string // get the tags as map - tagMap := util.ConvertEC2TagsToMap(ipam.Tags) + tagMap := util.ConvertTypesTagsToMap(ipam.Tags) if name, ok := tagMap["Name"]; ok { ipamResourceName = name } @@ -30,44 +31,45 @@ func shouldIncludeIpamResourceID(ipam *ec2.IpamResourceDiscovery, firstSeenTime // Returns a formatted string of IPAM Resource discovery func (discovery *EC2IPAMResourceDiscovery) getAll(c context.Context, configObj config.Config) ([]*string, error) { - result := []*string{} + var result []*string var firstSeenTime *time.Time var err error - paginator := func(output *ec2.DescribeIpamResourceDiscoveriesOutput, lastPage bool) bool { - for _, d := range output.IpamResourceDiscoveries { - firstSeenTime, err = util.GetOrCreateFirstSeen(c, discovery.Client, d.IpamResourceDiscoveryId, util.ConvertEC2TagsToMap(d.Tags)) + params := &ec2.DescribeIpamResourceDiscoveriesInput{ + MaxResults: aws.Int32(10), + Filters: []types.Filter{ + { + Name: aws.String("is-default"), + Values: []string{"false"}, + }, + }, + } + + discoveriesPaginator := ec2.NewDescribeIpamResourceDiscoveriesPaginator(discovery.Client, params) + for discoveriesPaginator.HasMorePages() { + page, errPaginator := discoveriesPaginator.NextPage(c) + if errPaginator != nil { + return nil, errors.WithStackTrace(errPaginator) + } + + for _, d := range page.IpamResourceDiscoveries { + firstSeenTime, err = util.GetOrCreateFirstSeen(c, discovery.Client, d.IpamResourceDiscoveryId, util.ConvertTypesTagsToMap(d.Tags)) if err != nil { logging.Error("unable to retrieve firstseen tag") continue } - if shouldIncludeIpamResourceID(d, firstSeenTime, configObj) { + if shouldIncludeIpamResourceID(&d, firstSeenTime, configObj) { result = append(result, d.IpamResourceDiscoveryId) } } - return !lastPage - } - - params := &ec2.DescribeIpamResourceDiscoveriesInput{ - MaxResults: awsgo.Int64(10), - Filters: []*ec2.Filter{ - { - Name: awsgo.String("is-default"), - Values: awsgo.StringSlice([]string{"false"}), - }, - }, - } - err = discovery.Client.DescribeIpamResourceDiscoveriesPagesWithContext(discovery.Context, params, paginator) - if err != nil { - return nil, errors.WithStackTrace(err) } // checking the nukable permissions discovery.VerifyNukablePermissions(result, func(id *string) error { - _, err := discovery.Client.DeleteIpamResourceDiscoveryWithContext(discovery.Context, &ec2.DeleteIpamResourceDiscoveryInput{ + _, err := discovery.Client.DeleteIpamResourceDiscovery(discovery.Context, &ec2.DeleteIpamResourceDiscoveryInput{ IpamResourceDiscoveryId: id, - DryRun: awsgo.Bool(true), + DryRun: aws.Bool(true), }) return err }) @@ -87,17 +89,17 @@ func (discovery *EC2IPAMResourceDiscovery) nukeAll(ids []*string) error { for _, id := range ids { - if nukable, reason := discovery.IsNukable(awsgo.StringValue(id)); !nukable { - logging.Debugf("[Skipping] %s nuke because %v", awsgo.StringValue(id), reason) + if nukable, reason := discovery.IsNukable(aws.ToString(id)); !nukable { + logging.Debugf("[Skipping] %s nuke because %v", aws.ToString(id), reason) continue } - _, err := discovery.Client.DeleteIpamResourceDiscoveryWithContext(discovery.Context, &ec2.DeleteIpamResourceDiscoveryInput{ + _, err := discovery.Client.DeleteIpamResourceDiscovery(discovery.Context, &ec2.DeleteIpamResourceDiscoveryInput{ IpamResourceDiscoveryId: id, }) // Record status of this resource e := report.Entry{ - Identifier: awsgo.StringValue(id), + Identifier: aws.ToString(id), ResourceType: "IPAM Resource Discovery", Error: err, } diff --git a/aws/resources/ec2_ipam_resource_discovery_test.go b/aws/resources/ec2_ipam_resource_discovery_test.go index 9a3d083f..0d2a7481 100644 --- a/aws/resources/ec2_ipam_resource_discovery_test.go +++ b/aws/resources/ec2_ipam_resource_discovery_test.go @@ -7,26 +7,24 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/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/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/util" "github.com/stretchr/testify/require" ) type mockedIPAMResourceDiscovery struct { - ec2iface.EC2API + EC2IPAMResourceDiscoveryAPI DescribeIpamResourceDiscoveriesOutput ec2.DescribeIpamResourceDiscoveriesOutput DeleteIpamResourceDiscoveryOutput ec2.DeleteIpamResourceDiscoveryOutput } -func (m mockedIPAMResourceDiscovery) DescribeIpamResourceDiscoveriesPagesWithContext(_ awsgo.Context, _ *ec2.DescribeIpamResourceDiscoveriesInput, callback func(*ec2.DescribeIpamResourceDiscoveriesOutput, bool) bool, _ ...request.Option) error { - callback(&m.DescribeIpamResourceDiscoveriesOutput, true) - return nil +func (m mockedIPAMResourceDiscovery) DescribeIpamResourceDiscoveries(ctx context.Context, params *ec2.DescribeIpamResourceDiscoveriesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeIpamResourceDiscoveriesOutput, error) { + return &m.DescribeIpamResourceDiscoveriesOutput, nil } -func (m mockedIPAMResourceDiscovery) DeleteIpamResourceDiscoveryWithContext(_ awsgo.Context, _ *ec2.DeleteIpamResourceDiscoveryInput, _ ...request.Option) (*ec2.DeleteIpamResourceDiscoveryOutput, error) { + +func (m mockedIPAMResourceDiscovery) DeleteIpamResourceDiscovery(ctx context.Context, params *ec2.DeleteIpamResourceDiscoveryInput, optFns ...func(*ec2.Options)) (*ec2.DeleteIpamResourceDiscoveryOutput, error) { return &m.DeleteIpamResourceDiscoveryOutput, nil } @@ -47,30 +45,30 @@ func TestIPAMRDiscovery_GetAll(t *testing.T) { ipam := EC2IPAMResourceDiscovery{ Client: mockedIPAMResourceDiscovery{ DescribeIpamResourceDiscoveriesOutput: ec2.DescribeIpamResourceDiscoveriesOutput{ - IpamResourceDiscoveries: []*ec2.IpamResourceDiscovery{ + IpamResourceDiscoveries: []types.IpamResourceDiscovery{ { IpamResourceDiscoveryId: aws.String(testId1), - Tags: []*ec2.Tag{ + Tags: []types.Tag{ { - Key: awsgo.String("Name"), - Value: awsgo.String(testName1), + Key: aws.String("Name"), + Value: aws.String(testName1), }, { - Key: awsgo.String(util.FirstSeenTagKey), - Value: awsgo.String(util.FormatTimestamp(now)), + Key: aws.String(util.FirstSeenTagKey), + Value: aws.String(util.FormatTimestamp(now)), }, }, }, { IpamResourceDiscoveryId: aws.String(testId2), - Tags: []*ec2.Tag{ + Tags: []types.Tag{ { - Key: awsgo.String("Name"), - Value: awsgo.String(testName2), + Key: aws.String("Name"), + Value: aws.String(testName2), }, { - Key: awsgo.String(util.FirstSeenTagKey), - Value: awsgo.String(util.FormatTimestamp(now)), + Key: aws.String(util.FirstSeenTagKey), + Value: aws.String(util.FormatTimestamp(now)), }, }, }, @@ -114,7 +112,7 @@ func TestIPAMRDiscovery_GetAll(t *testing.T) { EC2IPAMResourceDiscovery: tc.configObj, }) require.NoError(t, err) - require.Equal(t, tc.expected, awsgo.StringValueSlice(ids)) + require.Equal(t, tc.expected, aws.ToStringSlice(ids)) }) } } diff --git a/aws/resources/ec2_ipam_resource_discovery_types.go b/aws/resources/ec2_ipam_resource_discovery_types.go index 251d7a00..a5d12bb1 100644 --- a/aws/resources/ec2_ipam_resource_discovery_types.go +++ b/aws/resources/ec2_ipam_resource_discovery_types.go @@ -3,26 +3,31 @@ package resources import ( "context" - 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/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/go-commons/errors" ) -// IPAM - represents all IPAMs +type EC2IPAMResourceDiscoveryAPI interface { + DescribeIpamResourceDiscoveries(ctx context.Context, params *ec2.DescribeIpamResourceDiscoveriesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeIpamResourceDiscoveriesOutput, error) + DeleteIpamResourceDiscovery(ctx context.Context, params *ec2.DeleteIpamResourceDiscoveryInput, optFns ...func(*ec2.Options)) (*ec2.DeleteIpamResourceDiscoveryOutput, error) +} + +// EC2IPAMResourceDiscovery IPAM - represents all IPAMs type EC2IPAMResourceDiscovery struct { BaseAwsResource - Client ec2iface.EC2API + Client EC2IPAMResourceDiscoveryAPI Region string DiscoveryIDs []string } -func (ipam *EC2IPAMResourceDiscovery) Init(session *session.Session) { - ipam.Client = ec2.New(session) +func (ipam *EC2IPAMResourceDiscovery) InitV2(cfg aws.Config) { + ipam.Client = ec2.NewFromConfig(cfg) } +func (ipam *EC2IPAMResourceDiscovery) IsUsingV2() bool { return true } + // ResourceName - the simple name of the aws resource func (ipam *EC2IPAMResourceDiscovery) ResourceName() string { return "ipam-resource-discovery" @@ -48,13 +53,13 @@ func (ipam *EC2IPAMResourceDiscovery) GetAndSetIdentifiers(c context.Context, co return nil, err } - ipam.DiscoveryIDs = awsgo.StringValueSlice(identifiers) + ipam.DiscoveryIDs = aws.ToStringSlice(identifiers) return ipam.DiscoveryIDs, nil } // Nuke - nuke 'em all!!! func (ipam *EC2IPAMResourceDiscovery) Nuke(identifiers []string) error { - if err := ipam.nukeAll(awsgo.StringSlice(identifiers)); err != nil { + if err := ipam.nukeAll(aws.StringSlice(identifiers)); err != nil { return errors.WithStackTrace(err) } diff --git a/aws/resources/ec2_ipam_scope.go b/aws/resources/ec2_ipam_scope.go index a2b75487..eda39ff8 100644 --- a/aws/resources/ec2_ipam_scope.go +++ b/aws/resources/ec2_ipam_scope.go @@ -4,9 +4,9 @@ import ( "context" "time" - "github.com/aws/aws-sdk-go/aws" - awsgo "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" + "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" @@ -14,10 +14,10 @@ import ( "github.com/gruntwork-io/go-commons/errors" ) -func shouldIncludeIpamScopeID(ipam *ec2.IpamScope, firstSeenTime *time.Time, configObj config.Config) bool { +func shouldIncludeIpamScopeID(ipam *types.IpamScope, firstSeenTime *time.Time, configObj config.Config) bool { var ipamScopeName string // get the tags as map - tagMap := util.ConvertEC2TagsToMap(ipam.Tags) + tagMap := util.ConvertTypesTagsToMap(ipam.Tags) if name, ok := tagMap["Name"]; ok { ipamScopeName = name } @@ -31,47 +31,46 @@ func shouldIncludeIpamScopeID(ipam *ec2.IpamScope, firstSeenTime *time.Time, con // Returns a formatted string of IPAM URLs func (ec2Scope *EC2IpamScopes) getAll(c context.Context, configObj config.Config) ([]*string, error) { - result := []*string{} + var result []*string var firstSeenTime *time.Time var err error - paginator := func(output *ec2.DescribeIpamScopesOutput, lastPage bool) bool { - for _, scope := range output.IpamScopes { + params := &ec2.DescribeIpamScopesInput{ + MaxResults: aws.Int32(10), + Filters: []types.Filter{ + { + Name: aws.String("is-default"), + Values: []string{"false"}, + }, + }, + } + + scopesPaginator := ec2.NewDescribeIpamScopesPaginator(ec2Scope.Client, params) + for scopesPaginator.HasMorePages() { + page, errPaginator := scopesPaginator.NextPage(c) + if errPaginator != nil { + return nil, errors.WithStackTrace(errPaginator) + } - firstSeenTime, err = util.GetOrCreateFirstSeen(c, ec2Scope.Client, scope.IpamScopeId, util.ConvertEC2TagsToMap(scope.Tags)) + for _, scope := range page.IpamScopes { + firstSeenTime, err = util.GetOrCreateFirstSeen(c, ec2Scope.Client, scope.IpamScopeId, util.ConvertTypesTagsToMap(scope.Tags)) if err != nil { logging.Error("unable to retrieve firstseen tag") continue } // Check for include this ipam - if shouldIncludeIpamScopeID(scope, firstSeenTime, configObj) { + if shouldIncludeIpamScopeID(&scope, firstSeenTime, configObj) { result = append(result, scope.IpamScopeId) } } - return !lastPage - } - - params := &ec2.DescribeIpamScopesInput{ - MaxResults: awsgo.Int64(10), - Filters: []*ec2.Filter{ - { - Name: awsgo.String("is-default"), - Values: awsgo.StringSlice([]string{"false"}), - }, - }, - } - - err = ec2Scope.Client.DescribeIpamScopesPagesWithContext(ec2Scope.Context, params, paginator) - if err != nil { - return nil, errors.WithStackTrace(err) } // checking the nukable permissions ec2Scope.VerifyNukablePermissions(result, func(id *string) error { - _, err := ec2Scope.Client.DeleteIpamScopeWithContext(ec2Scope.Context, &ec2.DeleteIpamScopeInput{ + _, err := ec2Scope.Client.DeleteIpamScope(ec2Scope.Context, &ec2.DeleteIpamScopeInput{ IpamScopeId: id, - DryRun: awsgo.Bool(true), + DryRun: aws.Bool(true), }) return err }) @@ -90,18 +89,18 @@ func (scope *EC2IpamScopes) nukeAll(ids []*string) error { var deletedList []*string for _, id := range ids { - if nukable, reason := scope.IsNukable(awsgo.StringValue(id)); !nukable { - logging.Debugf("[Skipping] %s nuke because %v", awsgo.StringValue(id), reason) + if nukable, reason := scope.IsNukable(aws.ToString(id)); !nukable { + logging.Debugf("[Skipping] %s nuke because %v", aws.ToString(id), reason) continue } - _, err := scope.Client.DeleteIpamScopeWithContext(scope.Context, &ec2.DeleteIpamScopeInput{ + _, err := scope.Client.DeleteIpamScope(scope.Context, &ec2.DeleteIpamScopeInput{ IpamScopeId: id, }) // Record status of this resource e := report.Entry{ - Identifier: aws.StringValue(id), + Identifier: aws.ToString(id), ResourceType: "IPAM Scopes", Error: err, } diff --git a/aws/resources/ec2_ipam_scope_test.go b/aws/resources/ec2_ipam_scope_test.go index 1936a141..7d7d8d91 100644 --- a/aws/resources/ec2_ipam_scope_test.go +++ b/aws/resources/ec2_ipam_scope_test.go @@ -7,26 +7,24 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/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/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/util" "github.com/stretchr/testify/require" ) type mockedIPAMScope struct { - ec2iface.EC2API + EC2IpamScopesAPI DescribeIpamScopesOutput ec2.DescribeIpamScopesOutput DeleteIpamScopeOutput ec2.DeleteIpamScopeOutput } -func (m mockedIPAMScope) DescribeIpamScopesPagesWithContext(_ awsgo.Context, _ *ec2.DescribeIpamScopesInput, callback func(*ec2.DescribeIpamScopesOutput, bool) bool, _ ...request.Option) error { - callback(&m.DescribeIpamScopesOutput, true) - return nil +func (m mockedIPAMScope) DescribeIpamScopes(ctx context.Context, params *ec2.DescribeIpamScopesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeIpamScopesOutput, error) { + return &m.DescribeIpamScopesOutput, nil } -func (m mockedIPAMScope) DeleteIpamScopeWithContext(_ awsgo.Context, _ *ec2.DeleteIpamScopeInput, _ ...request.Option) (*ec2.DeleteIpamScopeOutput, error) { + +func (m mockedIPAMScope) DeleteIpamScope(ctx context.Context, params *ec2.DeleteIpamScopeInput, optFns ...func(*ec2.Options)) (*ec2.DeleteIpamScopeOutput, error) { return &m.DeleteIpamScopeOutput, nil } @@ -47,30 +45,30 @@ func TestIPAMScope_GetAll(t *testing.T) { ipam := EC2IpamScopes{ Client: mockedIPAMScope{ DescribeIpamScopesOutput: ec2.DescribeIpamScopesOutput{ - IpamScopes: []*ec2.IpamScope{ + IpamScopes: []types.IpamScope{ { IpamScopeId: &testId1, - Tags: []*ec2.Tag{ + Tags: []types.Tag{ { - Key: awsgo.String("Name"), - Value: awsgo.String(testName1), + Key: aws.String("Name"), + Value: aws.String(testName1), }, { - Key: awsgo.String(util.FirstSeenTagKey), - Value: awsgo.String(util.FormatTimestamp(now)), + Key: aws.String(util.FirstSeenTagKey), + Value: aws.String(util.FormatTimestamp(now)), }, }, }, { IpamScopeId: &testId2, - Tags: []*ec2.Tag{ + Tags: []types.Tag{ { - Key: awsgo.String("Name"), - Value: awsgo.String(testName2), + Key: aws.String("Name"), + Value: aws.String(testName2), }, { - Key: awsgo.String(util.FirstSeenTagKey), - Value: awsgo.String(util.FormatTimestamp(now)), + Key: aws.String(util.FirstSeenTagKey), + Value: aws.String(util.FormatTimestamp(now)), }, }, }, @@ -115,7 +113,7 @@ func TestIPAMScope_GetAll(t *testing.T) { EC2IPAMScope: tc.configObj, }) require.NoError(t, err) - require.Equal(t, tc.expected, awsgo.StringValueSlice(ids)) + require.Equal(t, tc.expected, aws.ToStringSlice(ids)) }) } } diff --git a/aws/resources/ec2_ipam_scope_types.go b/aws/resources/ec2_ipam_scope_types.go index 3b40a38c..20a907cf 100644 --- a/aws/resources/ec2_ipam_scope_types.go +++ b/aws/resources/ec2_ipam_scope_types.go @@ -3,26 +3,31 @@ package resources import ( "context" - 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/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/go-commons/errors" ) -// scope - represents all scopes +type EC2IpamScopesAPI interface { + DescribeIpamScopes(ctx context.Context, params *ec2.DescribeIpamScopesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeIpamScopesOutput, error) + DeleteIpamScope(ctx context.Context, params *ec2.DeleteIpamScopeInput, optFns ...func(*ec2.Options)) (*ec2.DeleteIpamScopeOutput, error) +} + +// EC2IpamScopes scope - represents all scopes type EC2IpamScopes struct { BaseAwsResource - Client ec2iface.EC2API + Client EC2IpamScopesAPI Region string ScopreIDs []string } -func (scope *EC2IpamScopes) Init(session *session.Session) { - scope.Client = ec2.New(session) +func (scope *EC2IpamScopes) InitV2(cfg aws.Config) { + scope.Client = ec2.NewFromConfig(cfg) } +func (scope *EC2IpamScopes) IsUsingV2() bool { return true } + // ResourceName - the simple name of the aws resource func (scope *EC2IpamScopes) ResourceName() string { return "ipam-scope" @@ -48,13 +53,13 @@ func (scope *EC2IpamScopes) GetAndSetIdentifiers(c context.Context, configObj co return nil, err } - scope.ScopreIDs = awsgo.StringValueSlice(identifiers) + scope.ScopreIDs = aws.ToStringSlice(identifiers) return scope.ScopreIDs, nil } // Nuke - nuke 'em all!!! func (scope *EC2IpamScopes) Nuke(identifiers []string) error { - if err := scope.nukeAll(awsgo.StringSlice(identifiers)); err != nil { + if err := scope.nukeAll(aws.StringSlice(identifiers)); err != nil { return errors.WithStackTrace(err) } diff --git a/aws/resources/ec2_ipam_test.go b/aws/resources/ec2_ipam_test.go index fa65e60d..da1885a9 100644 --- a/aws/resources/ec2_ipam_test.go +++ b/aws/resources/ec2_ipam_test.go @@ -7,56 +7,60 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/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/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/util" "github.com/stretchr/testify/require" ) type mockedIPAM struct { - ec2iface.EC2API - DescribeIpamsOutput ec2.DescribeIpamsOutput - DeleteIpamOutput ec2.DeleteIpamOutput - DescribeIpamScopesOutput ec2.DescribeIpamScopesOutput - DescribeIpamPoolsOutput ec2.DescribeIpamPoolsOutput - GetIpamPoolCidrsOutput ec2.GetIpamPoolCidrsOutput - DeprovisionIpamPoolCidrOuput ec2.DeprovisionIpamPoolCidrOutput - GetIpamPoolAllocationsOutput ec2.GetIpamPoolAllocationsOutput + EC2IPAMAPIaa + DescribeIpamsOutput ec2.DescribeIpamsOutput + DeleteIpamOutput ec2.DeleteIpamOutput + GetIpamPoolCidrsOutput ec2.GetIpamPoolCidrsOutput + DeprovisionIpamPoolCidrOutput ec2.DeprovisionIpamPoolCidrOutput + GetIpamPoolAllocationsOutput ec2.GetIpamPoolAllocationsOutput + ReleaseIpamPoolAllocationOutput ec2.ReleaseIpamPoolAllocationOutput + DescribeIpamScopesOutput ec2.DescribeIpamScopesOutput + DescribeIpamPoolsOutput ec2.DescribeIpamPoolsOutput + DeleteIpamPoolOutput ec2.DeleteIpamPoolOutput } -func (m mockedIPAM) DeleteIpamPoolWithContext(_ awsgo.Context, _ *ec2.DeleteIpamPoolInput, _ ...request.Option) (*ec2.DeleteIpamPoolOutput, error) { - return nil, nil +func (m mockedIPAM) DescribeIpams(ctx context.Context, params *ec2.DescribeIpamsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeIpamsOutput, error) { + return &m.DescribeIpamsOutput, nil } -func (m mockedIPAM) ReleaseIpamPoolAllocationWithContext(_ awsgo.Context, _ *ec2.ReleaseIpamPoolAllocationInput, _ ...request.Option) (*ec2.ReleaseIpamPoolAllocationOutput, error) { - return nil, nil + +func (m mockedIPAM) DeleteIpam(ctx context.Context, params *ec2.DeleteIpamInput, optFns ...func(*ec2.Options)) (*ec2.DeleteIpamOutput, error) { + return &m.DeleteIpamOutput, nil } -func (m mockedIPAM) GetIpamPoolAllocationsWithContext(_ awsgo.Context, _ *ec2.GetIpamPoolAllocationsInput, _ ...request.Option) (*ec2.GetIpamPoolAllocationsOutput, error) { - return &m.GetIpamPoolAllocationsOutput, nil + +func (m mockedIPAM) GetIpamPoolCidrs(ctx context.Context, params *ec2.GetIpamPoolCidrsInput, optFns ...func(*ec2.Options)) (*ec2.GetIpamPoolCidrsOutput, error) { + return &m.GetIpamPoolCidrsOutput, nil } -func (m mockedIPAM) DeprovisionIpamPoolCidrWithContext(_ awsgo.Context, _ *ec2.DeprovisionIpamPoolCidrInput, _ ...request.Option) (*ec2.DeprovisionIpamPoolCidrOutput, error) { - return &m.DeprovisionIpamPoolCidrOuput, nil + +func (m mockedIPAM) DeprovisionIpamPoolCidr(ctx context.Context, params *ec2.DeprovisionIpamPoolCidrInput, optFns ...func(*ec2.Options)) (*ec2.DeprovisionIpamPoolCidrOutput, error) { + return &m.DeprovisionIpamPoolCidrOutput, nil } -func (m mockedIPAM) GetIpamPoolCidrsWithContext(_ awsgo.Context, _ *ec2.GetIpamPoolCidrsInput, _ ...request.Option) (*ec2.GetIpamPoolCidrsOutput, error) { - return &m.GetIpamPoolCidrsOutput, nil + +func (m mockedIPAM) GetIpamPoolAllocations(ctx context.Context, params *ec2.GetIpamPoolAllocationsInput, optFns ...func(*ec2.Options)) (*ec2.GetIpamPoolAllocationsOutput, error) { + return &m.GetIpamPoolAllocationsOutput, nil } -func (m mockedIPAM) DescribeIpamScopesWithContext(_ awsgo.Context, _ *ec2.DescribeIpamScopesInput, _ ...request.Option) (*ec2.DescribeIpamScopesOutput, error) { + +func (m mockedIPAM) ReleaseIpamPoolAllocation(ctx context.Context, params *ec2.ReleaseIpamPoolAllocationInput, optFns ...func(*ec2.Options)) (*ec2.ReleaseIpamPoolAllocationOutput, error) { + return &m.ReleaseIpamPoolAllocationOutput, nil +} + +func (m mockedIPAM) DescribeIpamScopes(ctx context.Context, params *ec2.DescribeIpamScopesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeIpamScopesOutput, error) { return &m.DescribeIpamScopesOutput, nil } -func (m mockedIPAM) DescribeIpamPoolsWithContext(_ awsgo.Context, _ *ec2.DescribeIpamPoolsInput, _ ...request.Option) (*ec2.DescribeIpamPoolsOutput, error) { + +func (m mockedIPAM) DescribeIpamPools(ctx context.Context, params *ec2.DescribeIpamPoolsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeIpamPoolsOutput, error) { return &m.DescribeIpamPoolsOutput, nil } -func (m mockedIPAM) DescribeIpamsWithContext(_ awsgo.Context, _ *ec2.DescribeIpamsInput, _ ...request.Option) (*ec2.DescribeIpamsOutput, error) { - return &m.DescribeIpamsOutput, nil -} -func (m mockedIPAM) DescribeIpamsPagesWithContext(_ awsgo.Context, _ *ec2.DescribeIpamsInput, callback func(*ec2.DescribeIpamsOutput, bool) bool, _ ...request.Option) error { - callback(&m.DescribeIpamsOutput, true) - return nil -} -func (m mockedIPAM) DeleteIpamWithContext(_ awsgo.Context, _ *ec2.DeleteIpamInput, _ ...request.Option) (*ec2.DeleteIpamOutput, error) { - return &m.DeleteIpamOutput, nil + +func (m mockedIPAM) DeleteIpamPool(ctx context.Context, params *ec2.DeleteIpamPoolInput, optFns ...func(*ec2.Options)) (*ec2.DeleteIpamPoolOutput, error) { + return &m.DeleteIpamPoolOutput, nil } func TestIPAM_GetAll(t *testing.T) { @@ -76,30 +80,30 @@ func TestIPAM_GetAll(t *testing.T) { ipam := EC2IPAMs{ Client: mockedIPAM{ DescribeIpamsOutput: ec2.DescribeIpamsOutput{ - Ipams: []*ec2.Ipam{ + Ipams: []types.Ipam{ { IpamId: &testId1, - Tags: []*ec2.Tag{ + Tags: []types.Tag{ { - Key: awsgo.String("Name"), - Value: awsgo.String(testName1), + Key: aws.String("Name"), + Value: aws.String(testName1), }, { - Key: awsgo.String(util.FirstSeenTagKey), - Value: awsgo.String(util.FormatTimestamp(now)), + Key: aws.String(util.FirstSeenTagKey), + Value: aws.String(util.FormatTimestamp(now)), }, }, }, { IpamId: &testId2, - Tags: []*ec2.Tag{ + Tags: []types.Tag{ { - Key: awsgo.String("Name"), - Value: awsgo.String(testName2), + Key: aws.String("Name"), + Value: aws.String(testName2), }, { - Key: awsgo.String(util.FirstSeenTagKey), - Value: awsgo.String(util.FormatTimestamp(now)), + Key: aws.String(util.FirstSeenTagKey), + Value: aws.String(util.FormatTimestamp(now)), }, }, }, @@ -144,7 +148,7 @@ func TestIPAM_GetAll(t *testing.T) { EC2IPAM: tc.configObj, }) require.NoError(t, err) - require.Equal(t, tc.expected, awsgo.StringValueSlice(ids)) + require.Equal(t, tc.expected, aws.ToStringSlice(ids)) }) } } @@ -169,39 +173,39 @@ func TestIPAM_NukeAll(t *testing.T) { Client: mockedIPAM{ DeleteIpamOutput: ec2.DeleteIpamOutput{}, DescribeIpamsOutput: ec2.DescribeIpamsOutput{ - Ipams: []*ec2.Ipam{ + Ipams: []types.Ipam{ { IpamId: &testId1, PublicDefaultScopeId: &publicScope, - Tags: []*ec2.Tag{ + Tags: []types.Tag{ { - Key: awsgo.String("Name"), - Value: awsgo.String(testName1), + Key: aws.String("Name"), + Value: aws.String(testName1), }, { - Key: awsgo.String(util.FirstSeenTagKey), - Value: awsgo.String(util.FormatTimestamp(now)), + Key: aws.String(util.FirstSeenTagKey), + Value: aws.String(util.FormatTimestamp(now)), }, }, }, { IpamId: &testId2, PublicDefaultScopeId: &publicScope, - Tags: []*ec2.Tag{ + Tags: []types.Tag{ { - Key: awsgo.String("Name"), - Value: awsgo.String(testName2), + Key: aws.String("Name"), + Value: aws.String(testName2), }, { - Key: awsgo.String(util.FirstSeenTagKey), - Value: awsgo.String(util.FormatTimestamp(now)), + Key: aws.String(util.FirstSeenTagKey), + Value: aws.String(util.FormatTimestamp(now)), }, }, }, }, }, DescribeIpamScopesOutput: ec2.DescribeIpamScopesOutput{ - IpamScopes: []*ec2.IpamScope{ + IpamScopes: []types.IpamScope{ { IpamScopeId: aws.String(publicScope), IpamScopeArn: aws.String(publicScopeARN), @@ -209,23 +213,23 @@ func TestIPAM_NukeAll(t *testing.T) { }, }, DescribeIpamPoolsOutput: ec2.DescribeIpamPoolsOutput{ - IpamPools: []*ec2.IpamPool{ + IpamPools: []types.IpamPool{ { IpamPoolId: aws.String(testId1), }, }, }, GetIpamPoolCidrsOutput: ec2.GetIpamPoolCidrsOutput{ - IpamPoolCidrs: []*ec2.IpamPoolCidr{ + IpamPoolCidrs: []types.IpamPoolCidr{ { Cidr: aws.String("10.0.0.0/24"), }, }, }, GetIpamPoolAllocationsOutput: ec2.GetIpamPoolAllocationsOutput{ - IpamPoolAllocations: []*ec2.IpamPoolAllocation{ + IpamPoolAllocations: []types.IpamPoolAllocation{ { - ResourceType: aws.String("custom"), + ResourceType: types.IpamPoolAllocationResourceTypeCustom, IpamPoolAllocationId: aws.String("ipam-pool-alloc-001277b300c015f14"), }, }, diff --git a/aws/resources/ec2_ipam_types.go b/aws/resources/ec2_ipam_types.go index af584965..3e4e9ee3 100644 --- a/aws/resources/ec2_ipam_types.go +++ b/aws/resources/ec2_ipam_types.go @@ -3,26 +3,38 @@ package resources import ( "context" - 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/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/gruntwork-io/cloud-nuke/config" "github.com/gruntwork-io/go-commons/errors" ) +type EC2IPAMAPIaa interface { + DescribeIpams(ctx context.Context, params *ec2.DescribeIpamsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeIpamsOutput, error) + DeleteIpam(ctx context.Context, params *ec2.DeleteIpamInput, optFns ...func(*ec2.Options)) (*ec2.DeleteIpamOutput, error) + GetIpamPoolCidrs(ctx context.Context, params *ec2.GetIpamPoolCidrsInput, optFns ...func(*ec2.Options)) (*ec2.GetIpamPoolCidrsOutput, error) + DeprovisionIpamPoolCidr(ctx context.Context, params *ec2.DeprovisionIpamPoolCidrInput, optFns ...func(*ec2.Options)) (*ec2.DeprovisionIpamPoolCidrOutput, error) + GetIpamPoolAllocations(ctx context.Context, params *ec2.GetIpamPoolAllocationsInput, optFns ...func(*ec2.Options)) (*ec2.GetIpamPoolAllocationsOutput, error) + ReleaseIpamPoolAllocation(ctx context.Context, params *ec2.ReleaseIpamPoolAllocationInput, optFns ...func(*ec2.Options)) (*ec2.ReleaseIpamPoolAllocationOutput, error) + DescribeIpamScopes(ctx context.Context, params *ec2.DescribeIpamScopesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeIpamScopesOutput, error) + DescribeIpamPools(ctx context.Context, params *ec2.DescribeIpamPoolsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeIpamPoolsOutput, error) + DeleteIpamPool(ctx context.Context, params *ec2.DeleteIpamPoolInput, optFns ...func(*ec2.Options)) (*ec2.DeleteIpamPoolOutput, error) +} + // IPAM - represents all IPAMs type EC2IPAMs struct { BaseAwsResource - Client ec2iface.EC2API + Client EC2IPAMAPIaa Region string IDs []string } -func (ipam *EC2IPAMs) Init(session *session.Session) { - ipam.Client = ec2.New(session) +func (ipam *EC2IPAMs) InitV2(cfg aws.Config) { + ipam.Client = ec2.NewFromConfig(cfg) } +func (ipam *EC2IPAMs) IsUsingV2() bool { return true } + // ResourceName - the simple name of the aws resource func (ipam *EC2IPAMs) ResourceName() string { return "ipam" @@ -48,13 +60,13 @@ func (ipam *EC2IPAMs) GetAndSetIdentifiers(c context.Context, configObj config.C return nil, err } - ipam.IDs = awsgo.StringValueSlice(identifiers) + ipam.IDs = aws.ToStringSlice(identifiers) return ipam.IDs, nil } // Nuke - nuke 'em all!!! func (ipam *EC2IPAMs) Nuke(identifiers []string) error { - if err := ipam.nukeAll(awsgo.StringSlice(identifiers)); err != nil { + if err := ipam.nukeAll(aws.StringSlice(identifiers)); err != nil { return errors.WithStackTrace(err) } diff --git a/go.mod b/go.mod index 8db8ec06..f2477090 100644 --- a/go.mod +++ b/go.mod @@ -5,9 +5,9 @@ go 1.21 require ( github.com/aws/aws-sdk-go v1.49.13 github.com/aws/aws-sdk-go-v2 v1.32.4 - github.com/aws/aws-sdk-go-v2/config v1.28.3 - github.com/aws/aws-sdk-go-v2/credentials v1.17.44 - github.com/aws/aws-sdk-go-v2/service/accessanalyzer v1.34.5 + github.com/aws/aws-sdk-go-v2/config v1.28.4 + github.com/aws/aws-sdk-go-v2/credentials v1.17.45 + github.com/aws/aws-sdk-go-v2/service/accessanalyzer v1.36.0 github.com/aws/aws-sdk-go-v2/service/acm v1.30.5 github.com/aws/aws-sdk-go-v2/service/acmpca v1.37.6 github.com/aws/aws-sdk-go-v2/service/amp v1.30.2 @@ -16,14 +16,14 @@ require ( github.com/aws/aws-sdk-go-v2/service/apprunner v1.32.5 github.com/aws/aws-sdk-go-v2/service/autoscaling v1.48.0 github.com/aws/aws-sdk-go-v2/service/backup v1.39.6 - github.com/aws/aws-sdk-go-v2/service/cloudtrail v1.44.5 - github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.42.4 + github.com/aws/aws-sdk-go-v2/service/cloudtrail v1.45.0 + github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.43.0 github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.43.2 github.com/aws/aws-sdk-go-v2/service/codedeploy v1.29.5 github.com/aws/aws-sdk-go-v2/service/configservice v1.50.5 - github.com/aws/aws-sdk-go-v2/service/datasync v1.43.2 - github.com/aws/aws-sdk-go-v2/service/dynamodb v1.36.5 - github.com/aws/aws-sdk-go-v2/service/ec2 v1.187.1 + github.com/aws/aws-sdk-go-v2/service/datasync v1.43.3 + github.com/aws/aws-sdk-go-v2/service/dynamodb v1.37.0 + github.com/aws/aws-sdk-go-v2/service/ec2 v1.189.0 github.com/aws/aws-sdk-go-v2/service/ecr v1.36.5 github.com/aws/aws-sdk-go-v2/service/ecs v1.49.2 github.com/aws/aws-sdk-go-v2/service/efs v1.33.5 @@ -36,7 +36,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/firehose v1.35.0 github.com/aws/aws-sdk-go-v2/service/grafana v1.26.5 github.com/aws/aws-sdk-go-v2/service/guardduty v1.51.1 - github.com/aws/aws-sdk-go-v2/service/iam v1.37.4 + github.com/aws/aws-sdk-go-v2/service/iam v1.38.0 github.com/aws/aws-sdk-go-v2/service/kinesis v1.32.5 github.com/aws/aws-sdk-go-v2/service/kms v1.37.5 github.com/aws/aws-sdk-go-v2/service/lambda v1.66.0 @@ -46,7 +46,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/ses v1.28.4 github.com/aws/aws-sdk-go-v2/service/sns v1.33.4 github.com/aws/aws-sdk-go-v2/service/sqs v1.37.0 - github.com/aws/aws-sdk-go-v2/service/vpclattice v1.12.5 + github.com/aws/aws-sdk-go-v2/service/vpclattice v1.12.6 github.com/aws/smithy-go v1.22.0 github.com/charmbracelet/lipgloss v0.6.0 github.com/go-errors/errors v1.4.2 @@ -74,7 +74,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.4 // indirect github.com/aws/aws-sdk-go-v2/service/sso v1.24.5 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.4 // indirect - github.com/aws/aws-sdk-go-v2/service/sts v1.32.4 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.33.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 834b706f..9cd5e629 100644 --- a/go.sum +++ b/go.sum @@ -19,10 +19,10 @@ github.com/aws/aws-sdk-go-v2 v1.32.4 h1:S13INUiTxgrPueTmrm5DZ+MiAo99zYzHEFh1UNkO github.com/aws/aws-sdk-go-v2 v1.32.4/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 h1:pT3hpW0cOHRJx8Y0DfJUEQuqPild8jRGmSFmBgvydr0= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6/go.mod h1:j/I2++U0xX+cr44QjHay4Cvxj6FUbnxrgmqN3H1jTZA= -github.com/aws/aws-sdk-go-v2/config v1.28.3 h1:kL5uAptPcPKaJ4q0sDUjUIdueO18Q7JDzl64GpVwdOM= -github.com/aws/aws-sdk-go-v2/config v1.28.3/go.mod h1:SPEn1KA8YbgQnwiJ/OISU4fz7+F6Fe309Jf0QTsRCl4= -github.com/aws/aws-sdk-go-v2/credentials v1.17.44 h1:qqfs5kulLUHUEXlHEZXLJkgGoF3kkUeFUTVA585cFpU= -github.com/aws/aws-sdk-go-v2/credentials v1.17.44/go.mod h1:0Lm2YJ8etJdEdw23s+q/9wTpOeo2HhNE97XcRa7T8MA= +github.com/aws/aws-sdk-go-v2/config v1.28.4 h1:qgD0MKmkIzZR2DrAjWJcI9UkndjR+8f6sjUQvXh0mb0= +github.com/aws/aws-sdk-go-v2/config v1.28.4/go.mod h1:LgnWnNzHZw4MLplSyEGia0WgJ/kCGD86zGCjvNpehJs= +github.com/aws/aws-sdk-go-v2/credentials v1.17.45 h1:DUgm5lFso57E7150RBgu1JpVQoF8fAPretiDStIuVjg= +github.com/aws/aws-sdk-go-v2/credentials v1.17.45/go.mod h1:dnBpENcPC1ekZrGpSWspX+ZRGzhkvqngT2Qp5xBR1dY= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.19 h1:woXadbf0c7enQ2UGCi8gW/WuKmE0xIzxBF/eD94jMKQ= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.19/go.mod h1:zminj5ucw7w0r65bP6nhyOd3xL6veAUMc3ElGMoLVb4= github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.23 h1:A2w6m6Tmr+BNXjDsr7M90zkWjsu4JXHwrzPg235STs4= @@ -33,8 +33,8 @@ github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvK github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.23 h1:1SZBDiRzzs3sNhOMVApyWPduWYGAX0imGy06XiBnCAM= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.23/go.mod h1:i9TkxgbZmHVh2S0La6CAXtnyFhlCX/pJ0JsOvBAS6Mk= -github.com/aws/aws-sdk-go-v2/service/accessanalyzer v1.34.5 h1:7Yerkldbhj9wLYZElX0lai8Fi10Y/4tVjRy6aerV5ug= -github.com/aws/aws-sdk-go-v2/service/accessanalyzer v1.34.5/go.mod h1:7Om7kPFVbASCKvJaFkNN8htYhewIN6Xg2jLFvCv0FrI= +github.com/aws/aws-sdk-go-v2/service/accessanalyzer v1.36.0 h1:PLvB94nEvc52eRL0LH4MxU5wS811StcTcwuf77WcRgU= +github.com/aws/aws-sdk-go-v2/service/accessanalyzer v1.36.0/go.mod h1:7Om7kPFVbASCKvJaFkNN8htYhewIN6Xg2jLFvCv0FrI= github.com/aws/aws-sdk-go-v2/service/acm v1.30.5 h1:xT0pAxIVWjR9bFw2xrGpL1lt6eXmXaJ4nxXCYBegs00= github.com/aws/aws-sdk-go-v2/service/acm v1.30.5/go.mod h1:Fo90MZbAao/owZjAKO1dhazUlf2EFovI7bxOmoUFqoY= github.com/aws/aws-sdk-go-v2/service/acmpca v1.37.6 h1:vdQnPPcXUlVn+RK3USF42E1d0DNWksALKYClSSZ1dZs= @@ -51,22 +51,22 @@ github.com/aws/aws-sdk-go-v2/service/autoscaling v1.48.0 h1:jqGxMEnsD0NHc2Id2H5T github.com/aws/aws-sdk-go-v2/service/autoscaling v1.48.0/go.mod h1:DkO2AXbNiahaTv8J/LAwx3ddx/I1Dzxx+YpVB9ONUEU= github.com/aws/aws-sdk-go-v2/service/backup v1.39.6 h1:9pJEHqk5XAm+H+mAfj0pld1Xn0Fx2N5ql6hlz+GoEyQ= github.com/aws/aws-sdk-go-v2/service/backup v1.39.6/go.mod h1:ojOfXYWv9GyPbT9Q4AA/UzSG0b7DhqDi+vvLARlE5oE= -github.com/aws/aws-sdk-go-v2/service/cloudtrail v1.44.5 h1:6ThDGpCuve3xc5GIk88EuB1YJk135KpWpGGYkPO54Tc= -github.com/aws/aws-sdk-go-v2/service/cloudtrail v1.44.5/go.mod h1:dMy3o3W5gG5aOON5Y5EMMWeQDby9nFOeU7egskS4rrk= -github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.42.4 h1:c60zN18a3zQsBWdwE/v5xhK2Mtl1HG1gj9BLIEFxjWc= -github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.42.4/go.mod h1:fkETEwhdw2tOqu5m0Xa3wimV3PLDaiGqNrVZ3MJ7zOc= +github.com/aws/aws-sdk-go-v2/service/cloudtrail v1.45.0 h1:QuOJQueXZjk+R89u9+uJiCK5c/v3x3RuI7Nx3oo6Y4Y= +github.com/aws/aws-sdk-go-v2/service/cloudtrail v1.45.0/go.mod h1:dMy3o3W5gG5aOON5Y5EMMWeQDby9nFOeU7egskS4rrk= +github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.43.0 h1:r1sp92LSk4Gx8l0gScEjzSN+4iiImDvNayY9JYPNtNI= +github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.43.0/go.mod h1:fkETEwhdw2tOqu5m0Xa3wimV3PLDaiGqNrVZ3MJ7zOc= github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.43.2 h1:QaFEWSbTr3n31uaRyMPX2wCuzUGIS+VYM1xv5+I2FRo= github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.43.2/go.mod h1:dLKWdVHc4B1v+N6SLYkCUQjE4urPT4abG98sHbR5jnw= github.com/aws/aws-sdk-go-v2/service/codedeploy v1.29.5 h1:o047pZS9LNdXDPA2Kzw44l7Zk5sn/cghuoIYRhIGFCc= github.com/aws/aws-sdk-go-v2/service/codedeploy v1.29.5/go.mod h1:BcnpinS3IUvN6GuAU65hSne1d4ZD333EC95KRqdDHhU= github.com/aws/aws-sdk-go-v2/service/configservice v1.50.5 h1:u7UiUqnCDH7qSLKBf4UYqa6yZwo1EZtDJRvgOquQHVY= github.com/aws/aws-sdk-go-v2/service/configservice v1.50.5/go.mod h1:BaHMRvvaiB0zR500n0jvC2Die+bfaXRLUWR7mo5f6vQ= -github.com/aws/aws-sdk-go-v2/service/datasync v1.43.2 h1:IQTguEPJ6FNiN0+khEJNak0yGvZxlS/KqfoiRWPZTpM= -github.com/aws/aws-sdk-go-v2/service/datasync v1.43.2/go.mod h1:qdRLt3qUPw7lbIyF9YwNotDqkK18LYE1ANDXdsZ2gwk= -github.com/aws/aws-sdk-go-v2/service/dynamodb v1.36.5 h1:VWun/99wjelZZ+d0DGeSrffiCBJhC481geypGc6rfn0= -github.com/aws/aws-sdk-go-v2/service/dynamodb v1.36.5/go.mod h1:P+1rrWglInpWvnBpN0pH8jIIhkLkBaolkRVG4X9Kous= -github.com/aws/aws-sdk-go-v2/service/ec2 v1.187.1 h1:g6N2LDa3UuNR8CZvTYuXUKzfCD6S1iqRIsDFkbtwu0Y= -github.com/aws/aws-sdk-go-v2/service/ec2 v1.187.1/go.mod h1:0A17IIeys01WfjDKehspGP+Cyo/YH/eNADIbEbRS9yM= +github.com/aws/aws-sdk-go-v2/service/datasync v1.43.3 h1:z2UnsYWCgTxZCZ2NvokLKfJcNST3xAQ8bmIO+usueTA= +github.com/aws/aws-sdk-go-v2/service/datasync v1.43.3/go.mod h1:qdRLt3qUPw7lbIyF9YwNotDqkK18LYE1ANDXdsZ2gwk= +github.com/aws/aws-sdk-go-v2/service/dynamodb v1.37.0 h1:qgDx1ChCsz5tSxok9hxWES30bt4koYM1Xub4ONuNYDU= +github.com/aws/aws-sdk-go-v2/service/dynamodb v1.37.0/go.mod h1:P+1rrWglInpWvnBpN0pH8jIIhkLkBaolkRVG4X9Kous= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.189.0 h1:eBriSsQa4r7aiKF2wv1EGYbK3X1VnjAYvdOlepBUi8s= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.189.0/go.mod h1:0A17IIeys01WfjDKehspGP+Cyo/YH/eNADIbEbRS9yM= github.com/aws/aws-sdk-go-v2/service/ecr v1.36.5 h1:FMF/uaTcIdhvOwZXJfzpwanx2m4Dd6IcN4vDnAn7NAA= github.com/aws/aws-sdk-go-v2/service/ecr v1.36.5/go.mod h1:xhf509Ba+rG5whtO7w46O0raVzu1Og3Aba80LSvHbbQ= github.com/aws/aws-sdk-go-v2/service/ecs v1.49.2 h1:LpxJEwzfI5pen6CbNem8mwPAYBwjoQ/hLHVAqhAEFDo= @@ -91,8 +91,8 @@ github.com/aws/aws-sdk-go-v2/service/grafana v1.26.5 h1:xgJiP0R7hXAO03rh9h8iupmM github.com/aws/aws-sdk-go-v2/service/grafana v1.26.5/go.mod h1:QOCIdJ0zLzzcUDbBNtFT+IrzFFHD0909mxlPdXh53lg= github.com/aws/aws-sdk-go-v2/service/guardduty v1.51.1 h1:nAK988z7ZsAYHZtVD8IYV1HVI3ZcE2atQCoBEO5xEQE= github.com/aws/aws-sdk-go-v2/service/guardduty v1.51.1/go.mod h1:ISU8hcBgCVmpZTUmD2ONSQO+0dGpIjyCU1r+yIy7ha0= -github.com/aws/aws-sdk-go-v2/service/iam v1.37.4 h1:MrH2MJRzxPGXtavvL1JtDLFJzXN+4ObO090jzauqcPk= -github.com/aws/aws-sdk-go-v2/service/iam v1.37.4/go.mod h1:WJARDpnEOhixhh41f+kTTr67y28OvjIUVht++rfcILY= +github.com/aws/aws-sdk-go-v2/service/iam v1.38.0 h1:x2zxTpgLPylAKVZ1Lf7qiQkQHA7L5njP4eB01DrTlCw= +github.com/aws/aws-sdk-go-v2/service/iam v1.38.0/go.mod h1:WJARDpnEOhixhh41f+kTTr67y28OvjIUVht++rfcILY= 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/endpoint-discovery v1.10.4 h1:rWKH6IiWDRIxmsTJUB/wEY+EIPp+P3C78Vidl+HXp6w= @@ -121,10 +121,10 @@ github.com/aws/aws-sdk-go-v2/service/sso v1.24.5 h1:HJwZwRt2Z2Tdec+m+fPjvdmkq2s9 github.com/aws/aws-sdk-go-v2/service/sso v1.24.5/go.mod h1:wrMCEwjFPms+V86TCQQeOxQF/If4vT44FGIOFiMC2ck= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.4 h1:zcx9LiGWZ6i6pjdcoE9oXAB6mUdeyC36Ia/QEiIvYdg= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.4/go.mod h1:Tp/ly1cTjRLGBBmNccFumbZ8oqpZlpdhFf80SrRh4is= -github.com/aws/aws-sdk-go-v2/service/sts v1.32.4 h1:yDxvkz3/uOKfxnv8YhzOi9m+2OGIxF+on3KOISbK5IU= -github.com/aws/aws-sdk-go-v2/service/sts v1.32.4/go.mod h1:9XEUty5v5UAsMiFOBJrNibZgwCeOma73jgGwwhgffa8= -github.com/aws/aws-sdk-go-v2/service/vpclattice v1.12.5 h1:SR2VyTp+n8uHWJ5gI7aNtgkJc1JVKxv+Xrgu9A/KF0I= -github.com/aws/aws-sdk-go-v2/service/vpclattice v1.12.5/go.mod h1:t3Ljhmx5GEzD6OGd5ajMgs8L0Wza2Ppe5FE9uqFHLDo= +github.com/aws/aws-sdk-go-v2/service/sts v1.33.0 h1:s7LRgBqhwLaxcocnAniBJp7gaAB+4I4vHzqUqjH18yc= +github.com/aws/aws-sdk-go-v2/service/sts v1.33.0/go.mod h1:9XEUty5v5UAsMiFOBJrNibZgwCeOma73jgGwwhgffa8= +github.com/aws/aws-sdk-go-v2/service/vpclattice v1.12.6 h1:Cmi4vh1fCmcWxkHdswNgCmHRUrs/adOoerYcXJl2vtw= +github.com/aws/aws-sdk-go-v2/service/vpclattice v1.12.6/go.mod h1:t3Ljhmx5GEzD6OGd5ajMgs8L0Wza2Ppe5FE9uqFHLDo= 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= diff --git a/v2_migration_report/output.md b/v2_migration_report/output.md index f721f7ea..2ccda856 100644 --- a/v2_migration_report/output.md +++ b/v2_migration_report/output.md @@ -60,12 +60,12 @@ run `go generate ./...` to refresh this report. | iam-role | :white_check_mark: | | iam-service-linked-role | :white_check_mark: | | internet-gateway | | -| ipam | | -| ipam-byoasn | | -| ipam-custom-allocation | | -| ipam-pool | | -| ipam-resource-discovery | | -| ipam-scope | | +| ipam | :white_check_mark: | +| ipam-byoasn | :white_check_mark: | +| ipam-custom-allocation | :white_check_mark: | +| ipam-pool | :white_check_mark: | +| ipam-resource-discovery | :white_check_mark: | +| ipam-scope | :white_check_mark: | | kinesis-firehose | :white_check_mark: | | kinesis-stream | :white_check_mark: | | kmscustomerkeys | :white_check_mark: |