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 Nov 16, 2024
1 parent fc4dca1 commit 468b41b
Show file tree
Hide file tree
Showing 45 changed files with 941 additions and 875 deletions.
25 changes: 8 additions & 17 deletions examples/terraform-packer-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ provider "aws" {
# ---------------------------------------------------------------------------------------------------------------------

resource "aws_instance" "example" {
ami = var.ami_id
instance_type = var.instance_type
user_data = data.template_file.user_data.rendered
ami = var.ami_id
instance_type = var.instance_type

user_data = templatefile("${path.module}/user-data/user-data.sh", {
instance_text = var.instance_text
instance_port = var.instance_port
})

vpc_security_group_ids = [aws_security_group.example.id]

tags = {
Expand All @@ -51,17 +56,3 @@ resource "aws_security_group" "example" {
cidr_blocks = ["0.0.0.0/0"]
}
}

# ---------------------------------------------------------------------------------------------------------------------
# CREATE THE USER DATA SCRIPT THAT WILL RUN DURING BOOT ON THE EC2 INSTANCE
# ---------------------------------------------------------------------------------------------------------------------

data "template_file" "user_data" {
template = file("${path.module}/user-data/user-data.sh")

vars = {
instance_text = var.instance_text
instance_port = var.instance_port
}
}

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.3
github.com/aws/aws-sdk-go-v2/config v1.28.1
github.com/aws/aws-sdk-go-v2/credentials v1.17.42
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.35
github.com/aws/aws-sdk-go-v2/service/acm v1.30.3
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.47.0
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.43.0
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.36.3
github.com/aws/aws-sdk-go-v2/service/ec2 v1.187.0
github.com/aws/aws-sdk-go-v2/service/ecr v1.36.3
github.com/aws/aws-sdk-go-v2/service/ecs v1.49.0
github.com/aws/aws-sdk-go-v2/service/iam v1.37.3
github.com/aws/aws-sdk-go-v2/service/kms v1.37.3
github.com/aws/aws-sdk-go-v2/service/lambda v1.64.1
github.com/aws/aws-sdk-go-v2/service/rds v1.89.0
github.com/aws/aws-sdk-go-v2/service/route53 v1.46.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.66.2
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.34.3
github.com/aws/aws-sdk-go-v2/service/sns v1.33.3
github.com/aws/aws-sdk-go-v2/service/sqs v1.36.3
github.com/aws/aws-sdk-go-v2/service/ssm v1.55.3
github.com/aws/aws-sdk-go-v2/service/sts v1.32.3
github.com/gonvenience/ytbx v1.4.4
github.com/homeport/dyff v1.6.0
github.com/jackc/pgx/v5 v5.7.1
Expand All @@ -70,6 +91,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.18 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.22 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.22 // 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.22 // 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.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.10.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.24.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.3 // 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 @@ -85,6 +120,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.3 h1:T0dRlFBKcdaUPGNtkBSwHZxrtis8CQU17UpNBZYd0wk=
github.com/aws/aws-sdk-go-v2 v1.32.3/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.1 h1:oxIvOUXy8x0U3fR//0eq+RdCKimWI900+SV+10xsCBw=
github.com/aws/aws-sdk-go-v2/config v1.28.1/go.mod h1:bRQcttQJiARbd5JZxw6wG0yIK3eLeSCPdg6uqmmlIiI=
github.com/aws/aws-sdk-go-v2/credentials v1.17.42 h1:sBP0RPjBU4neGpIYyx8mkU2QqLPl5u9cmdTWVzIpHkM=
github.com/aws/aws-sdk-go-v2/credentials v1.17.42/go.mod h1:FwZBfU530dJ26rv9saAbxa9Ej3eF/AK0OAY86k13n4M=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.18 h1:68jFVtt3NulEzojFesM/WVarlFpCaXLKaBxDpzkQ9OQ=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.18/go.mod h1:Fjnn5jQVIo6VyedMc0/EhPpfNlPl7dHV916O6B+49aE=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.35 h1:ihPPdcCVSN0IvBByXwqVp28/l4VosBZ6sDulcvU2J7w=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.35/go.mod h1:JkgEhs3SVF51Dj3m1Bj+yL8IznpxzkwlA3jLg3x7Kls=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.22 h1:Jw50LwEkVjuVzE1NzkhNKkBf9cRN7MtE1F/b2cOKTUM=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.22/go.mod h1:Y/SmAyPcOTmpeVaWSzSKiILfXTVJwrGmYZhcRbhWuEY=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.22 h1:981MHwBaRZM7+9QSR6XamDzF/o7ouUGxFzr+nVSIhrs=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.22/go.mod h1:1RA1+aBEfn+CAB/Mh0MB6LsdCYCnjZm7tKXtnk499ZQ=
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.22 h1:yV+hCAHZZYJQcwAaszoBNwLbPItHvApxT0kVIw6jRgs=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.22/go.mod h1:kbR1TL8llqB1eGnVbybcA4/wgScxdylOdyAd51yxPdw=
github.com/aws/aws-sdk-go-v2/service/acm v1.30.3 h1:/7wq5haORYzJUkAbD9Hh4/SGiwupLhPdGqIzf+taLOA=
github.com/aws/aws-sdk-go-v2/service/acm v1.30.3/go.mod h1:A4UY3eQPhio6VPEfBhrkafy4rSIjQ/aOggqKZYNHv+c=
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.47.0 h1:3yvZKeDa/slOTk8Gym4ym9u7AKhYAvy0Y00oRE+HRvE=
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.47.0/go.mod h1:SDmFD5Xuoa8dHPOLakoiURaUXei4zcqrkZ0/myZch/A=
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.43.0 h1:nrCD0LVzOlmD4KLxvrZf1E/4K+jj1gBp7ljLQLGZZkk=
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.43.0/go.mod h1:t/Gxp3yK6TAkcJzsxHLkkaxcNGuLvgFphZiWuSp8qHk=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.36.3 h1:pS5ka5Z026eG29K3cce+yxG39i5COQARcgheeK9NKQE=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.36.3/go.mod h1:MBT8rSGSZjJiV6X7rlrVGoIt+mCoaw0VbpdVtsrsJfk=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.187.0 h1:cA4hWo269CN5RY7Arqt8BfzXF0KIN8DSNo/KcqHKkWk=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.187.0/go.mod h1:ossaD9Z1ugYb6sq9QIqQLEOorCGcqUoxlhud9M9yE70=
github.com/aws/aws-sdk-go-v2/service/ecr v1.36.3 h1:bqmoQEKpWFRDRxOv4lC5yZLc+N1cogZHPLeQACfVUJo=
github.com/aws/aws-sdk-go-v2/service/ecr v1.36.3/go.mod h1:KwOqlt4MOBK9EpOGkj8RU9fqfTEae5AOUHi1pDEZ3OQ=
github.com/aws/aws-sdk-go-v2/service/ecs v1.49.0 h1:xhCV6zY5ZFzfyAUOiBXK6wh0HVQTBkvNwA/eiz89ZWY=
github.com/aws/aws-sdk-go-v2/service/ecs v1.49.0/go.mod h1:RXYd/Ts+sFnjDrVdAZsAfHVkYxQUxhC+l2zrSpSgCGc=
github.com/aws/aws-sdk-go-v2/service/iam v1.37.3 h1:uuoXyOwX2ReYgHJW0W84cKDUrvQNQA2l9KhkXUgT+R4=
github.com/aws/aws-sdk-go-v2/service/iam v1.37.3/go.mod h1:RCrjvkN/ZpVAzW3ZmIlyflv7MUM45YlWx3v+6MaVX2w=
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.3 h1:kT6BcZsmMtNkP/iYMcRG+mIEA/IbeiUimXtGmqF39y0=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.3/go.mod h1:Z8uGua2k4PPaGOYn66pK02rhMrot3Xk3tpBuUFPomZU=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.10.3 h1:wudRPcZMKytcywXERkR6PLqD8gPx754ZyIOo0iVg488=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.10.3/go.mod h1:yRo5Kj5+m/ScVIZpQOquQvDtSrDM1JLRCnvglBcdNmw=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.3 h1:qcxX0JYlgWH3hpPUnd6U0ikcl6LLA9sLkXE2w1fpMvY=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.3/go.mod h1:cLSNEmI45soc+Ef8K/L+8sEA3A3pYFEYf5B5UI+6bH4=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.3 h1:ZC7Y/XgKUxwqcdhO5LE8P6oGP1eh6xlQReWNKfhvJno=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.3/go.mod h1:WqfO7M9l9yUAw0HcHaikwRd/H6gzYdz7vjejCA5e2oY=
github.com/aws/aws-sdk-go-v2/service/kms v1.37.3 h1:VpyBA6KP6JgzwokQps8ArQPGy9rFej8adwuuQGcduH8=
github.com/aws/aws-sdk-go-v2/service/kms v1.37.3/go.mod h1:TT/9V4PcmSPpd8LPUNJ8hBHJmpqcfhx6MrbWTkvyR+4=
github.com/aws/aws-sdk-go-v2/service/lambda v1.64.1 h1:0njE+T0N80Kl2bPfK85Lnz1+dD/xskJduTqfRyREpvY=
github.com/aws/aws-sdk-go-v2/service/lambda v1.64.1/go.mod h1:hr+VpAzvznKumy8q8TFEJfx3Xx+zfK2gDrrWjBqLLPw=
github.com/aws/aws-sdk-go-v2/service/rds v1.89.0 h1:4x0WbBa+i/AS0AFlj7yvx3n+GuK3XR58J6t61pW6h8U=
github.com/aws/aws-sdk-go-v2/service/rds v1.89.0/go.mod h1:WB+SVZKu1IBpsy3GrpR2EBnqB6A05Bd0r4RDLRqMbdk=
github.com/aws/aws-sdk-go-v2/service/route53 v1.46.0 h1:AaOWmXBSDSIEsTzx8Y2nYAxckgmBPNiRU5mjn/a9ynI=
github.com/aws/aws-sdk-go-v2/service/route53 v1.46.0/go.mod h1:IN9bx4yLAa3a3J7A41skQefcYObNv6ARAd2i5WxvGKg=
github.com/aws/aws-sdk-go-v2/service/s3 v1.66.2 h1:p9TNFL8bFUMd+38YIpTAXpoxyz0MxC7FlbFEH4P4E1U=
github.com/aws/aws-sdk-go-v2/service/s3 v1.66.2/go.mod h1:fNjyo0Coen9QTwQLWeV6WO2Nytwiu+cCcWaTdKCAqqE=
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.34.3 h1:CyA6J82ePPoh1Nj8ErOR2e/JRlzfFzWpGwGMFzFjwZg=
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.34.3/go.mod h1:EliITPlGcBz0FRiVl7lRLtzI1cnDybFcfLYMZedOInE=
github.com/aws/aws-sdk-go-v2/service/sns v1.33.3 h1:coZW/SqpINT0VWG8vRWWY9TWUof8TDdxublw2Xur0Zc=
github.com/aws/aws-sdk-go-v2/service/sns v1.33.3/go.mod h1:J/G2xuhwNBlDvEi0WR/bnBbac4KSgpkERna/IXEF52w=
github.com/aws/aws-sdk-go-v2/service/sqs v1.36.3 h1:H1bCg79Q4PDtxQH8Fn5kASQlbVv2WGP5o5IEFEBNOAs=
github.com/aws/aws-sdk-go-v2/service/sqs v1.36.3/go.mod h1:W6Uy6OWgxF9RZuHoikthB6f+A0oYXqnfWmFl5m7E2G4=
github.com/aws/aws-sdk-go-v2/service/ssm v1.55.3 h1:nbFGlCxyyFe2cgg8WNQQtzDRVczO4+1dL4hd3TDU6MM=
github.com/aws/aws-sdk-go-v2/service/ssm v1.55.3/go.mod h1:nzUlOBAMlQx9zKwtI10FOzJa2phU6bmFbXhD6LLbr/A=
github.com/aws/aws-sdk-go-v2/service/sso v1.24.3 h1:UTpsIf0loCIWEbrqdLb+0RxnTXfWh2vhw4nQmFi4nPc=
github.com/aws/aws-sdk-go-v2/service/sso v1.24.3/go.mod h1:FZ9j3PFHHAR+w0BSEjK955w5YD2UwB/l/H0yAK3MJvI=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.3 h1:2YCmIXv3tmiItw0LlYf6v7gEHebLY45kBEnPezbUKyU=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.3/go.mod h1:u19stRyNPxGhj6dRm+Cdgu6N75qnbW7+QN0q0dsAk58=
github.com/aws/aws-sdk-go-v2/service/sts v1.32.3 h1:wVnQ6tigGsRqSWDEEyH6lSAJ9OyFUsSnbaUWChuSGzs=
github.com/aws/aws-sdk-go-v2/service/sts v1.32.3/go.mod h1:VZa9yTFyj4o10YGsmDO4gbQJUvvhY72fhumT8W4LqsE=
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 468b41b

Please sign in to comment.