Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new LocalStack AWS session via env var #1211

Closed
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion modules/aws/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (
)

const (
AuthAssumeRoleEnvVar = "TERRATEST_IAM_ROLE" // OS environment variable name through which Assume Role ARN may be passed for authentication
AuthAssumeRoleEnvVar = "TERRATEST_IAM_ROLE" // OS environment variable name through which Assume Role ARN may be passed for authentication
LocalStackEnvVar = "TERRATEST_LOCALSTACK" // OS environment variable name through which LocalStack may be enabled
)

// NewAuthenticatedSession creates an AWS session following to standard AWS authentication workflow.
Expand All @@ -32,6 +33,21 @@ func NewAuthenticatedSession(region string) (*session.Session, error) {
func NewAuthenticatedSessionFromDefaultCredentials(region string) (*session.Session, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Could you please update the comment above this function to describe this behavior?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

awsConfig := aws.NewConfig().WithRegion(region)

if localStackUrl, ok := os.LookupEnv(LocalStackEnvVar); ok {
awsAccessKeyId := "test"
awsSecretAccessKey := "test"

if AWS_ACCESS_KEY_ID, ok := os.LookupEnv("AWS_ACCESS_KEY_ID"); ok {
awsAccessKeyId = AWS_ACCESS_KEY_ID
}

if AWS_SECRET_ACCESS_KEY, ok := os.LookupEnv("AWS_SECRET_ACCESS_KEY"); ok {
awsSecretAccessKey = AWS_SECRET_ACCESS_KEY
}

awsConfig = awsConfig.WithEndpoint(localStackUrl).WithDisableSSL(true).WithCredentials(credentials.NewStaticCredentials(awsAccessKeyId, awsSecretAccessKey, ""))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, will be helpful to have a test case to keep track that handling of TERRATEST_LOCALSTACK will continue to work

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately, that would require a lot more than you think as there aren't any tests for this for good reason. I don't think there is a reasonable way to invoke the auth to begin with

}

sessionOptions := session.Options{
Config: *awsConfig,
SharedConfigState: session.SharedConfigEnable,
Expand Down