gruntwork-io / terratest

Terratest is a Go library that makes it easier to write automated tests for your infrastructure code.
https://terratest.gruntwork.io/
Apache License 2.0
7.53k stars 1.33k forks source link

Add SSO configuration support to Terratest #1460

Open kkrav3ts opened 2 weeks ago

kkrav3ts commented 2 weeks ago

Describe the solution you'd like In order to run tests in CLI, I need to be logged in first. I use IAM Identity Center (SSO, not Legacy):

[default]
sso_session = gw-sso
sso_account_id = 123456789012
sso_role_name = AdminRole
region = us-east-1
output = json

[sso-session gw-sso]
sso_region = us-east-1
sso_start_url = https://company-abc.awsapps.com/start

Being successfully logged in, I run tests and get:

TestNetworkFirewall 2024-11-01T21:03:29+02:00 region.go:109: Looking up all AWS regions available in this account
--- FAIL: TestNetworkFirewall (0.00s)
    region.go:66: profile "default" is configured to use SSO but is missing required configuration: sso_region, sso_start_url
FAIL
FAIL    github.com/gruntwork-io/terraform-aws-vpc/test/vpc-app-natgw-eips       0.061s
FAIL

Basically, I'd wanted to ask to implement support for new implementation of IAM Identity Center (SSO) login: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html

Describe alternatives you've considered With using Legacy IAM Identity Center, everything works fine:

[default]
sso_start_url = https://company-abc.awsapps.com/start
sso_region = us-east-1
sso_account_id = 123456789012
sso_role_name = AdminRole
region = us-east-1
output = json

Additional context None

kkrav3ts commented 1 week ago

@ZachGoldberg alas I am not able to do it myself as it requires better Go understanding and Terratest structure. So I created this ticket to request assistance. Is it possible to re-assign it to someone who is good with Go and Terratest?

wakeful commented 1 week ago

Hey,

It seems the issue you're facing is related to the underlying AWS SDK used by Terratest.

I was able to reproduce your issue on the master branch using my configuration.

[profile FullAdmin-1234567890]
sso_session = shadow
sso_account_id = 1234567890
sso_role_name = FullAdmin
region = eu-west-1
output = json

[sso-session shadow]
sso_start_url = https://1234567890.awsapps.com/start
sso_region = eu-west-1
sso_registration_scopes = sso:account:access

On the master branch, it fails, but it works fine in my fork with SDK v2.

Could I ask you to try run a test with the AWS SDK v2 branch? We are currently working on merging and upgrading the AWS SDK to v2 in this PR #1451

You can point to my fork for now.

go mod init github.com/your-org/new-project
go mod edit -replace github.com/gruntwork-io/terratest@v0.47.2=github.com/wakeful/terratest@v0.48.1
go get github.com/gruntwork-io/terratest/modules/aws@v0.47.2
kkrav3ts commented 5 days ago

@wakeful yes, it works as expected. Thanks!