terraform-provider-aws: [Bug]: Lack of support for sso-session in .aws/config
Terraform Core Version
1.3.6
AWS Provider Version
4.45.0
Affected Resource(s)
No response
Expected Behavior
Terraform should work as normal using AWS credentials as defined in .aws/config.
Actual Behavior
Error: configuring Terraform AWS Provider: loading configuration: profile "profile" is configured to use SSO but is missing required configuration: sso_region, sso_start_url
Relevant Error/Panic Output Snippet
No response
Terraform Configuration Files
.aws/config
[profile profile]
sso_session = xxx
sso_account_id = xxx
sso_role_name = AdministratorAccess
region = eu-west-1
[sso-session session]
sso_start_url = https://xxx.awsapps.com/start
sso_region = eu-west-1
sso_registration_scopes = sso:account:access
Terraform
provider "aws" {
region = "eu-west-1"
}
resource "aws_s3_bucket" "b" {
}
Steps to Reproduce
- Configure awscli using
aws sso configureor manually create.aws/configto use an sso-session. terraform initAWS_PROFILE=profile terraform plan
Debug Output
No response
Panic Output
No response
Important Factoids
No response
References
I believe this is an issue caused by the aws-sdk-go rather than this Terraform provider, however don’t understand enough about go to know which version of the SDK is in use. aws/aws-sdk-go#4649 remains open whereas aws/aws-sdk-go-v2#1903 fixes this in the v2 SDK.
Would you like to implement a fix?
No
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 242
- Comments: 28 (1 by maintainers)
What worked for me was this reddit post: https://www.reddit.com/r/aws/comments/zk456d/new_aws_cli_and_sso_sessions_profiles_and_legacy/
In short:
sso-sessionsection (or sections if you had multiple)sso-sessionreference under theprofilesectionaws configure sso --profile <profile-name># I usually go for defaultsso session name, leave it blankterraformshould start workingAny updates on this? Still not working with v4.48
Weird, issues seems to be critical and fundamental. Can’t execute any terraform actions on my newly configured accounts that are managed by new AWS Identity Center
To mention a workaround: You do not need to add:
sso_region,sso_start_urlYou just have to create a IAM User with appropriate permissions and programmatic access and add these credentials to.aws/credentialsmake sure that
profilename matches in the both.aws/credentialsand.aws/config. Provider will workI can confirm the following works as a temporary fix:
[sso-session ...]sectionsso_sessionparameter from the profilesso_start_urlandsso_regionregionparameter if not already thereWorking example:
How is this not resolved yet? Isn’t the GO SDK supposed to handle this automatically?
Or you can use the
Command line or programmatic accessfrom your role and copy that content to the credentials file. You can barely change the profile name to your needs and can use it as long, as the session is valid. But this is all only a workaround, especially with an eye on the session getting invalid after the configured amount of time and one have to copy the temp credentials over again 😃.The support for
sso-sessionforaws-sdk-gohas been merged and is now in a release. https://github.com/aws/aws-sdk-go/releases/tag/v1.44.298As pointed out here https://github.com/hashicorp/terraform-provider-aws/issues/28263#issuecomment-1428052544 the provider is now fixed after dependency updates https://github.com/hashicorp/terraform-provider-aws/pull/29302
Would be great if we could also update the backend accordingly
This is still happening in v4.46.0, which has the update (https://github.com/hashicorp/terraform-provider-aws/commit/b3dcf93ddabb4cf692aa7620cb8ec4aebaf0a52a) to the aws-sdk-go-v2 version (v1.17.2) that has the upstream fix.
From what I can see in
go.modfile, specified versions of affected dependencies do not contain SSO enhancements:New SSO enhancements were added in versions v1.18.0 and v1.13.0 correspondingly.
For posterity, this probably got fixed by the bump in https://github.com/hashicorp/terraform-provider-aws/pull/32426.
@kurtismash pls correct me if I’m wrong 😉
Any chance for this to end up in a release soon?
This still needs to make it into a
terraformrelease. The S3 backend code doesn’t use the AWS provider, it has a parallel S3 code path. The provider works, but if you use an S3 state backend you’ll still have problems until they update the SDK there.Having new SSO support in the v1 SDK will make that easier, though.
Keep an eye on https://github.com/hashicorp/terraform/issues/32465 (there appears to be an open PR for this now)
For those that are finding when you get a reference to
$HOME/.aws/sso/cache/<id>.jsonnot found, you must perform an AWS SSO login first.I recommend to create multiple pairs of your profiles, one with the legacy non-refreshing token specifically for terraform, and use another for your normal operations. This will allow you to use the AWS CLI with the refreshing tokens and have the terraform backend explicitly select the legacy profile.
~/.aws/configIn your backend, configure your profile to be the legacy above.
And have your aws env set to the refresher token:
I was having the same problem, and including all information within the profile itself helped in my case as well.
Why are Terraform and AWS provider not able to use the session information? Using an sso-session to provide the region and start_url is the recommended way to set up sso: Configuring the AWS CLI to use AWS IAM Identity Center (successor to AWS Single Sign-On)
I believe what @brettryan mentions will work as a workaround, but what is needed is the terraform-provider-aws to support refreshable authentication tokens and to refresh those tokens when they expire.
@yermulnik It is fixed in bf5aed5bc8b73db62b3fe1b6d4e76dd4408a16b0, when the SDK version is upgraded to a version which support new format SSO. For supported version, please refers to https://github.com/hashicorp/terraform-provider-aws/issues/28263#issuecomment-1367036724
It is fixed at v4.54.0. However, if you use s3 backend, the legacy configuration is still required, the issue on Terraform is still open
Hey, yeah with the solution @michidk suggested here, you can configure the awscli profiles the legacy way. Thats working so far, also with the aws provider. But who knows how long until sso-sessions will be enforced and the legacy way will be deprecated 😃
You can work around this in two ways:
sso_start_urlin each profileaws-sso-credsYou need to both
sso_start_urlandsso_regionfor your profile. And then runaws sso login --profile <profile name>“set the sso_start_url in each profile” does’t work for me
Still get: % terraform plan ╷ │ Error: configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.
@tonyhhyip Out of curiosity: is there any exact PR we can refer to? I couldn’t find anything relevant to AWS SSO in v4.54.0 release message 🤷🏻
@boyadzhievb I also had to remove the
sso_sessionkey/value from my profile.documentation for “legacy” configuration here: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html#sso-configure-profile-manual
Community Note
Voting for Prioritization
Volunteering to Work on This Issue