Skip to content

Commit

Permalink
migrate to AWS SDKv2, updating only singnatures and making sure tests…
Browse files Browse the repository at this point in the history
… are passing. #1432
  • Loading branch information
wakeful committed Oct 15, 2024
1 parent 6fd2ca3 commit 22a3870
Show file tree
Hide file tree
Showing 42 changed files with 928 additions and 814 deletions.
40 changes: 38 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
github.com/aws/aws-lambda-go v1.13.3
github.com/aws/aws-sdk-go v1.44.122
github.com/aws/aws-sdk-go v1.44.122 // indirect
github.com/ghodss/yaml v1.0.0
github.com/go-errors/errors v1.0.2-0.20180813162953-d98b870cc4e0 // indirect
github.com/go-sql-driver/mysql v1.4.1
Expand Down Expand Up @@ -48,7 +48,28 @@ require (

require (
cloud.google.com/go/cloudbuild v1.9.0
github.com/gogo/protobuf v1.3.2
github.com/aws/aws-sdk-go-v2 v1.32.0
github.com/aws/aws-sdk-go-v2/config v1.27.41
github.com/aws/aws-sdk-go-v2/credentials v1.17.39
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.28
github.com/aws/aws-sdk-go-v2/service/acm v1.30.0
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.45.0
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.41.0
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.36.0
github.com/aws/aws-sdk-go-v2/service/ec2 v1.181.0
github.com/aws/aws-sdk-go-v2/service/ecr v1.36.0
github.com/aws/aws-sdk-go-v2/service/ecs v1.47.0
github.com/aws/aws-sdk-go-v2/service/iam v1.37.0
github.com/aws/aws-sdk-go-v2/service/kms v1.37.0
github.com/aws/aws-sdk-go-v2/service/lambda v1.63.0
github.com/aws/aws-sdk-go-v2/service/rds v1.87.0
github.com/aws/aws-sdk-go-v2/service/route53 v1.45.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.65.0
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.34.0
github.com/aws/aws-sdk-go-v2/service/sns v1.33.0
github.com/aws/aws-sdk-go-v2/service/sqs v1.36.0
github.com/aws/aws-sdk-go-v2/service/ssm v1.55.0
github.com/aws/aws-sdk-go-v2/service/sts v1.32.0
github.com/gonvenience/ytbx v1.4.4
github.com/homeport/dyff v1.6.0
github.com/slack-go/slack v0.10.3
Expand All @@ -69,6 +90,20 @@ require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.15 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.19 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.19 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.19 // 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/checksum v1.4.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.10.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.24.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.0 // indirect
github.com/aws/smithy-go v1.22.0 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
Expand All @@ -84,6 +119,7 @@ require (
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/gonvenience/bunt v1.3.5 // indirect
Expand Down
72 changes: 72 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,78 @@ github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQ
github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
github.com/aws/aws-sdk-go v1.44.122 h1:p6mw01WBaNpbdP2xrisz5tIkcNwzj/HysobNoaAHjgo=
github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
github.com/aws/aws-sdk-go-v2 v1.32.0 h1:GuHp7GvMN74PXD5C97KT5D87UhIy4bQPkflQKbfkndg=
github.com/aws/aws-sdk-go-v2 v1.32.0/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.27.41 h1:esG3WpmEuNJ6F4kVFLumN8nCfA5VBav1KKb3JPx83O4=
github.com/aws/aws-sdk-go-v2/config v1.27.41/go.mod h1:haUg09ebP+ClvPjU3EB/xe0HF9PguO19PD2fdjM2X14=
github.com/aws/aws-sdk-go-v2/credentials v1.17.39 h1:tmVexAhoGqJxNE2oc4/SJqL+Jz1x1iCPt5ts9XcqZCU=
github.com/aws/aws-sdk-go-v2/credentials v1.17.39/go.mod h1:zgOdbDI9epE608PdboJ87CYvPIejAgFevazeJW6iauQ=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.15 h1:kGjlNc2IXXcxPDcfMyCshNCjVgxUhC/vTJv7NvC9wKk=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.15/go.mod h1:rk/HmqPo+dX0Uv0Q1+4w3QKFdICEGSsTYz1hRWvH8UI=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.28 h1:yUPy1fwOKNZ9L52E9TCMomU+mKXNCgqi17dtYIdSolk=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.28/go.mod h1:bJJP1cGMO0fPBgCjqHAWbc0WRbKrxrWU4hQfc/0ciAA=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.19 h1:Q/k5wCeJkSWs+62kDfOillkNIJ5NqmE3iOfm48g/W8c=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.19/go.mod h1:Wns1C66VvtA2Bv/cUBuKZKQKdjo7EVMhp90aAa+8oTI=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.19 h1:AYLE0lUfKvN6icFTR/p+NmD1amYKTbqHQ1Nm+jwE6BM=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.19/go.mod h1:1giLakj64GjuH1NBzF/DXqly5DWHtMTaOzRZ53nFX0I=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ=
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.19 h1:FKdiFzTxlTRO71p0C7VrLbkkdW8qfMKF5+ej6bTmkT0=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.19/go.mod h1:abO3pCj7WLQPTllnSeYImqFfkGrmJV0JovWo/gqT5N0=
github.com/aws/aws-sdk-go-v2/service/acm v1.30.0 h1:HXgZe/xLkwE3HkVZ4E5BUB9UdiJb0SRDAh0rY37mAts=
github.com/aws/aws-sdk-go-v2/service/acm v1.30.0/go.mod h1:yG7E9LncLQA1HBPqrLdRTpWFNkmrT2VpS+pPZYR1tQM=
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.45.0 h1:wf5tH7iaOBAy5UkhwnNhx+7BdbedEqTHzGTd7toh5RQ=
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.45.0/go.mod h1:TVp3het8D/Zqq7Wl8UfQe8OQtEUxZMu2Z4vw6/46ud0=
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.41.0 h1:mzUSh7kG5FGJGq+89oqdw9A7sg+85DB/L7dyYC4JXi4=
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.41.0/go.mod h1:zQUEHpmQ9ZOi2fH2KKKj3wZ5Has9RexDeYbGEzrf+QA=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.36.0 h1:PGMSBO1pE60sOFtXn1wAeW78dZPm/TLdQaAH75on0PU=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.36.0/go.mod h1:H55uOPvyanrZuglrbwznvoeEuPftohECjADdw9q9gQk=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.181.0 h1:YzSOMQYRZQKuLz/bD6illIGwJfa1WFfeFAZM5Zr5LB8=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.181.0/go.mod h1:CudaKF0Yu5+ZfKMiiPdtJ/kOOBty7CIEJUhESP52e9M=
github.com/aws/aws-sdk-go-v2/service/ecr v1.36.0 h1:OVg61nfvhkvneY2btZ50sdYHsvhJs46dqtuBiURZo2A=
github.com/aws/aws-sdk-go-v2/service/ecr v1.36.0/go.mod h1:kdKXMMVpJd/N59EYI8aneYNsQNqCd99iSg2bEmQHaUI=
github.com/aws/aws-sdk-go-v2/service/ecs v1.47.0 h1:PEqhN8gdtZzjTP08srXYXpHOS1GCMP9QoxbBzalzftM=
github.com/aws/aws-sdk-go-v2/service/ecs v1.47.0/go.mod h1:7m+7DlR7ndneH1yGMGFoiA9Gi5qdKQVRUrARWikfp1M=
github.com/aws/aws-sdk-go-v2/service/iam v1.37.0 h1:FLdmwEJUDWdAflqxRNkIKNZki8dFmi5SUeTjAjxrdJU=
github.com/aws/aws-sdk-go-v2/service/iam v1.37.0/go.mod h1:Xctz/06SeHDUc3ZheMxXekSZ2rx0RX9SVhV5JeQgoqY=
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/checksum v1.4.0 h1:FQNWhRuSq8QwW74GtU0MrveNhZbqvHsA4dkA9w8fTDQ=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.0/go.mod h1:j/zZ3zmWfGCK91K73YsfHP53BSTLSjL/y6YN39XbBLM=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.10.0 h1:6a3DyPi2Yl0MnUoYG3hA5oKhEnUubbMoayWoQ/7cQEc=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.10.0/go.mod h1:ZBgfcYPfH0uj3671EVyBcReSif2qlTKe9xQkiRqY3lg=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.0 h1:AdbiDUgQZmM28rDIZbiSwFxz8+3B94aOXxzs6oH+EA0=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.0/go.mod h1:uV476Bd80tiDTX4X2redMtagQUg65aU/gzPojSJ4kSI=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.0 h1:1NKXS8XfhMM0bg5wVYa/eOH8AM2f6JijugbKEyQFTIg=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.0/go.mod h1:ph931DUfVfgrhZR7py9olSvHCiRpvaGxNvlWBcXxFds=
github.com/aws/aws-sdk-go-v2/service/kms v1.37.0 h1:ovrHGOiNu4S0GSMeexZlsMhBkUb3bCE3iOktFZ7rmBU=
github.com/aws/aws-sdk-go-v2/service/kms v1.37.0/go.mod h1:YLqfMkq9GWbICgqT5XMIzT8I2+MxVKodTnNBo3BONgE=
github.com/aws/aws-sdk-go-v2/service/lambda v1.63.0 h1:3ufRg9NrAhfDIXXSoxVOpDrId73Ktllue3SwM7NqDcw=
github.com/aws/aws-sdk-go-v2/service/lambda v1.63.0/go.mod h1:86odDKRQ6thVf+/ZdW1Wi/VAZQBm/svee62bSQkuzgM=
github.com/aws/aws-sdk-go-v2/service/rds v1.87.0 h1:f7u5jzUHaIIn5F121ortA0g2yDDWiPeTw2lWrgk9+ZA=
github.com/aws/aws-sdk-go-v2/service/rds v1.87.0/go.mod h1:agnQGhYbHXxPM2+zZH4WZIpki6IDU6zFGzfOlnu+1Ow=
github.com/aws/aws-sdk-go-v2/service/route53 v1.45.0 h1:rwDRzOudNWFLRmpHIC6zZjGKovvgdfobPgXn/aXTdcs=
github.com/aws/aws-sdk-go-v2/service/route53 v1.45.0/go.mod h1:NAmFsZ4aGISCGa2nX+EGxPQGukb/z+XwriLW0i+EHKs=
github.com/aws/aws-sdk-go-v2/service/s3 v1.65.0 h1:2dSm7frMrw2tdJ0QvyccQNJyPGaP24dyDgZ6h1QJMGU=
github.com/aws/aws-sdk-go-v2/service/s3 v1.65.0/go.mod h1:4XSVpw66upN8wND3JZA29eXl2NOZvfFVq7DIP6xvfuQ=
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.34.0 h1:POvqkPd+H/B6No9py/7c//RRVbSp75wtN8nsd/LGHw0=
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.34.0/go.mod h1:G2a06OQdRNbG8bfvdYSFpA9CBuaTQrmnrIyGuU6OgXU=
github.com/aws/aws-sdk-go-v2/service/sns v1.33.0 h1:QuttYvND/OmttAImqJtsZXYJ6bEoUC2qLi29lhw1lss=
github.com/aws/aws-sdk-go-v2/service/sns v1.33.0/go.mod h1:bZXJof3RK1G0NKSmE3NQGBFDIpQD/ayLu7ffN1cCW/E=
github.com/aws/aws-sdk-go-v2/service/sqs v1.36.0 h1:t+b3U3fmUiuXyeBhp9c3BpaEQS7bzp/CoGCuj8DW6r8=
github.com/aws/aws-sdk-go-v2/service/sqs v1.36.0/go.mod h1:ICKQNsIj2Q6IXn5nF+ADptwAM9jX5JFWbnIfRR+6SqE=
github.com/aws/aws-sdk-go-v2/service/ssm v1.55.0 h1:tXrDYWutZsSAtqilgdOkn/DMLdIhTZoyA5J7NgwNfyc=
github.com/aws/aws-sdk-go-v2/service/ssm v1.55.0/go.mod h1:Brz7JZ/wuntsPXH0D0dgZsb/IKr1+slD0eL+k967oLo=
github.com/aws/aws-sdk-go-v2/service/sso v1.24.0 h1:71FvP6XFj53NK+YiAEGVzeiccLVeFnHOCvMig0zOHsE=
github.com/aws/aws-sdk-go-v2/service/sso v1.24.0/go.mod h1:UVJqtKXSd9YppRKgdBIkyv7qgbSGv5DchM3yX0BN2mU=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.0 h1:Uco4o19bi3AmBapImNzuMk+rfzlui52BDyVK1UfJeRA=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.0/go.mod h1:+HLFhCpnG08hBee8bUdfd1mBK+rFKPt4O5igR9lXDfk=
github.com/aws/aws-sdk-go-v2/service/sts v1.32.0 h1:GiQUjZM2KUZX68o/LpZ1xqxYMuvoxpRrOwYARYog3vc=
github.com/aws/aws-sdk-go-v2/service/sts v1.32.0/go.mod h1:dKnu7M4MAS2SDlng1ytxd03H+y0LoUfEQ5E2VaaSw/4=
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/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down
13 changes: 7 additions & 6 deletions modules/aws/account.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package aws

import (
"context"
"errors"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sts"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/sts"

"github.com/gruntwork-io/terratest/modules/testing"
)
Expand All @@ -26,12 +27,12 @@ func GetAccountIdE(t testing.TestingT) (string, error) {
return "", err
}

identity, err := stsClient.GetCallerIdentity(&sts.GetCallerIdentityInput{})
identity, err := stsClient.GetCallerIdentity(context.Background(), &sts.GetCallerIdentityInput{})
if err != nil {
return "", err
}

return aws.StringValue(identity.Account), nil
return aws.ToString(identity.Account), nil
}

// An IAM arn is of the format arn:aws:iam::123456789012:user/test. The account id is the number after arn:aws:iam::,
Expand All @@ -47,10 +48,10 @@ func extractAccountIDFromARN(arn string) (string, error) {
}

// NewStsClientE creates a new STS client.
func NewStsClientE(t testing.TestingT, region string) (*sts.STS, error) {
func NewStsClientE(t testing.TestingT, region string) (*sts.Client, error) {
sess, err := NewAuthenticatedSession(region)
if err != nil {
return nil, err
}
return sts.New(sess), nil
return sts.NewFromConfig(*sess), nil
}
12 changes: 7 additions & 5 deletions modules/aws/acm.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package aws

import (
"github.com/aws/aws-sdk-go/service/acm"
"context"

"github.com/aws/aws-sdk-go-v2/service/acm"

"github.com/gruntwork-io/terratest/modules/testing"
)
Expand All @@ -22,7 +24,7 @@ func GetAcmCertificateArnE(t testing.TestingT, awsRegion string, certDomainName
return "", err
}

result, err := acmClient.ListCertificates(&acm.ListCertificatesInput{})
result, err := acmClient.ListCertificates(context.Background(), &acm.ListCertificatesInput{})
if err != nil {
return "", err
}
Expand All @@ -37,7 +39,7 @@ func GetAcmCertificateArnE(t testing.TestingT, awsRegion string, certDomainName
}

// NewAcmClient create a new ACM client.
func NewAcmClient(t testing.TestingT, region string) *acm.ACM {
func NewAcmClient(t testing.TestingT, region string) *acm.Client {
client, err := NewAcmClientE(t, region)
if err != nil {
t.Fatal(err)
Expand All @@ -46,11 +48,11 @@ func NewAcmClient(t testing.TestingT, region string) *acm.ACM {
}

// NewAcmClientE creates a new ACM client.
func NewAcmClientE(t testing.TestingT, awsRegion string) (*acm.ACM, error) {
func NewAcmClientE(t testing.TestingT, awsRegion string) (*acm.Client, error) {
sess, err := NewAuthenticatedSession(awsRegion)
if err != nil {
return nil, err
}

return acm.New(sess), nil
return acm.NewFromConfig(*sess), nil
}
30 changes: 16 additions & 14 deletions modules/aws/ami.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package aws

import (
"context"
"fmt"
"sort"
"time"

"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/terratest/modules/logger"
"github.com/gruntwork-io/terratest/modules/testing"
)
Expand Down Expand Up @@ -57,17 +59,17 @@ func GetEbsSnapshotsForAmi(t testing.TestingT, region string, ami string) []stri
return snapshots
}

// GetEbsSnapshotsForAmi retrieves the EBS snapshots which back the given AMI
// GetEbsSnapshotsForAmiE retrieves the EBS snapshots which back the given AMI
func GetEbsSnapshotsForAmiE(t testing.TestingT, region string, ami string) ([]string, error) {
logger.Default.Logf(t, "Retrieving EBS snapshots backing AMI %s", ami)
ec2Client, err := NewEc2ClientE(t, region)
if err != nil {
return nil, err
}

images, err := ec2Client.DescribeImages(&ec2.DescribeImagesInput{
ImageIds: []*string{
aws.String(ami),
images, err := ec2Client.DescribeImages(context.Background(), &ec2.DescribeImagesInput{
ImageIds: []string{
ami,
},
})
if err != nil {
Expand All @@ -78,7 +80,7 @@ func GetEbsSnapshotsForAmiE(t testing.TestingT, region string, ami string) ([]st
for _, image := range images.Images {
for _, mapping := range image.BlockDeviceMappings {
if mapping.Ebs != nil && mapping.Ebs.SnapshotId != nil {
snapshots = append(snapshots, aws.StringValue(mapping.Ebs.SnapshotId))
snapshots = append(snapshots, aws.ToString(mapping.Ebs.SnapshotId))
}
}
}
Expand Down Expand Up @@ -106,18 +108,18 @@ func GetMostRecentAmiIdE(t testing.TestingT, region string, ownerId string, filt
return "", err
}

ec2Filters := []*ec2.Filter{}
var ec2Filters []types.Filter
for name, values := range filters {
ec2Filters = append(ec2Filters, &ec2.Filter{Name: aws.String(name), Values: aws.StringSlice(values)})
ec2Filters = append(ec2Filters, types.Filter{Name: aws.String(name), Values: values})
}

input := ec2.DescribeImagesInput{
Filters: ec2Filters,
IncludeDeprecated: aws.Bool(true),
Owners: []*string{aws.String(ownerId)},
Owners: []string{ownerId},
}

out, err := ec2Client.DescribeImages(&input)
out, err := ec2Client.DescribeImages(context.Background(), &input)
if err != nil {
return "", err
}
Expand All @@ -127,11 +129,11 @@ func GetMostRecentAmiIdE(t testing.TestingT, region string, ownerId string, filt
}

mostRecentImage := mostRecentAMI(out.Images)
return aws.StringValue(mostRecentImage.ImageId), nil
return aws.ToString(mostRecentImage.ImageId), nil
}

// Image sorting code borrowed from: https://github.com/hashicorp/packer/blob/7f4112ba229309cfc0ebaa10ded2abdfaf1b22c8/builder/amazon/common/step_source_ami_info.go
type imageSort []*ec2.Image
type imageSort []types.Image

func (a imageSort) Len() int { return len(a) }
func (a imageSort) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
Expand All @@ -142,7 +144,7 @@ func (a imageSort) Less(i, j int) bool {
}

// mostRecentAMI returns the most recent AMI out of a slice of images.
func mostRecentAMI(images []*ec2.Image) *ec2.Image {
func mostRecentAMI(images []types.Image) types.Image {
sortedImages := images
sort.Sort(imageSort(sortedImages))
return sortedImages[len(sortedImages)-1]
Expand Down
Loading

0 comments on commit 22a3870

Please sign in to comment.