Skip to content

Commit

Permalink
Bump aws-sdk-go and fix issue with global region for alternative part…
Browse files Browse the repository at this point in the history
…itions (#350)

* Bump aws-sdk-go and fix issue with global region for alternative partitions

* Fix build failure

* Pass through -p 1 flag to tests
  • Loading branch information
yorinasub17 authored Aug 12, 2022
1 parent e926aa8 commit 3f5a923
Show file tree
Hide file tree
Showing 6 changed files with 635 additions and 23 deletions.
7 changes: 5 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defaults: &defaults
docker:
- image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.16-tf1.0-tg31.1-pck1.7
- image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.17-tf1.2-tg37.4-pck1.8-ci50.1
version: 2.1
jobs:
test:
Expand All @@ -10,7 +10,10 @@ jobs:
- run:
command: |
mkdir -p /tmp/logs
run-go-tests --timeout 45m | tee /tmp/logs/all.log
# Run the tests. Note that we set the "-p 1" flag to tell Go to run tests in each package sequentially. Without
# this, Go buffers all log output until all packages are done, which with slower running tests can cause CircleCI
# to kill the build after more than 45 minutes without log output.
run-go-tests --extra-flags '-p 1' --timeout 45m | tee /tmp/logs/all.log
no_output_timeout: 45m
- run:
name: parse test output
Expand Down
30 changes: 18 additions & 12 deletions aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ var GovCloudRegions = []string{

const (
GlobalRegion string = "global"
// us-east-1 is the region that is available in every account
defaultRegion string = "us-east-1"
)

func newSession(region string) *session.Session {
Expand Down Expand Up @@ -211,6 +209,7 @@ func GetAllResources(targetRegions []string, excludeAfter time.Time, resourceTyp
totalRegions := len(targetRegions)
resourcesCache := map[string]map[string][]*string{}

defaultRegion := targetRegions[0]
for _, region := range targetRegions {
// The "global" region case is handled outside this loop
if region == GlobalRegion {
Expand Down Expand Up @@ -775,12 +774,9 @@ func GetAllResources(targetRegions []string, excludeAfter time.Time, resourceTyp

// As there is no actual region named global we have to pick a valid one just to create the session
sessionRegion := defaultRegion
session, err := session.NewSession(&awsgo.Config{
Region: awsgo.String(sessionRegion),
},
)
session, err := newAWSSession(sessionRegion)
if err != nil {
return nil, errors.WithStackTrace(err)
return nil, err
}

globalResources := AwsRegionResource{}
Expand Down Expand Up @@ -931,6 +927,7 @@ func nukeAllResourcesInRegion(account *AwsAccountResources, region string, sessi

// NukeAllResources - Nukes all aws resources
func NukeAllResources(account *AwsAccountResources, regions []string) error {
defaultRegion := regions[0]
for _, region := range regions {
// region that will be used to create a session
sessionRegion := region
Expand All @@ -940,12 +937,9 @@ func NukeAllResources(account *AwsAccountResources, regions []string) error {
sessionRegion = defaultRegion
}

session, err := session.NewSession(&awsgo.Config{
Region: awsgo.String(sessionRegion),
},
)
session, err := newAWSSession(sessionRegion)
if err != nil {
return errors.WithStackTrace(err)
return err
}

err = nukeAllResourcesInRegion(account, region, session)
Expand All @@ -958,3 +952,15 @@ func NukeAllResources(account *AwsAccountResources, regions []string) error {

return nil
}

func newAWSSession(awsRegion string) (*session.Session, error) {
sessionOptions := session.Options{
SharedConfigState: session.SharedConfigEnable,
}
sess, err := session.NewSessionWithOptions(sessionOptions)
if err != nil {
return nil, errors.WithStackTrace(err)
}
sess.Config.Region = aws.String(awsRegion)
return sess, nil
}
Loading

0 comments on commit 3f5a923

Please sign in to comment.