Skip to content

Commit

Permalink
Updated awsConfig if static crendentials aren't set. BTW regression t…
Browse files Browse the repository at this point in the history
…ests run successfully
  • Loading branch information
MRinalducci committed Feb 24, 2018
1 parent a0bbbd6 commit edf0efc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 13 additions & 3 deletions aws_helper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@ import (
// Returns an AWS session object for the given region (required), profile name (optional), and IAM role to assume
// (optional), ensuring that the credentials are available
func CreateAwsSession(awsRegion, awsEndpoint string, awsAccessKey string, awsSecretKey string, awsProfile string, iamRoleArn string, terragruntOptions *options.TerragruntOptions) (*session.Session, error) {
sess, err := session.NewSessionWithOptions(session.Options{
Config: aws.Config{
var awsConfig aws.Config
if awsAccessKey != "" && awsSecretKey != "" {
awsConfig = aws.Config{
Region: aws.String(awsRegion),
Endpoint: aws.String(awsEndpoint),
Credentials: credentials.NewStaticCredentials(awsAccessKey, awsSecretKey, ""),
},
}
} else {
awsConfig = aws.Config{
Region: aws.String(awsRegion),
Endpoint: aws.String(awsEndpoint),
}
}

sess, err := session.NewSessionWithOptions(session.Options{
Config: awsConfig,
Profile: awsProfile,
SharedConfigState: session.SharedConfigEnable,
})
Expand Down
6 changes: 3 additions & 3 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ func validateS3BucketExists(t *testing.T, awsRegion string, bucketName string) {
t.Fatalf("Error creating mockOptions: %v", err)
}

s3Client, err := remote.CreateS3Client(awsRegion, "", "", mockOptions)
s3Client, err := remote.CreateS3Client(awsRegion, "", "", "", "", "", mockOptions)
if err != nil {
t.Fatalf("Error creating S3 client: %v", err)
}
Expand All @@ -639,7 +639,7 @@ func deleteS3Bucket(t *testing.T, awsRegion string, bucketName string) {
t.Fatalf("Error creating mockOptions: %v", err)
}

s3Client, err := remote.CreateS3Client(awsRegion, "", "", mockOptions)
s3Client, err := remote.CreateS3Client(awsRegion, "", "", "", "", "", mockOptions)
if err != nil {
t.Fatalf("Error creating S3 client: %v", err)
}
Expand Down Expand Up @@ -681,7 +681,7 @@ func createDynamoDbClient(awsRegion, awsProfile string, iamRoleArn string) (*dyn
return nil, err
}

session, err := aws_helper.CreateAwsSession(awsRegion, awsProfile, iamRoleArn, mockOptions)
session, err := aws_helper.CreateAwsSession(awsRegion, "", "", "", awsProfile, iamRoleArn, mockOptions)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit edf0efc

Please sign in to comment.