-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Changes from 4 commits
b3d7aa1
a60c987
232f52b
788590c
d46b452
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -32,6 +33,21 @@ func NewAuthenticatedSession(region string) (*session.Session, error) { | |
func NewAuthenticatedSessionFromDefaultCredentials(region string) (*session.Session, error) { | ||
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, "")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.