In the “aws-get-started/aws-create” tutorial, it asks me to authenticate via an access key and a secret access key. In my normal AWS CLI operations, I have authentication set up to use “aws login,” entering my IAM user-ID and password, and my MFA through my default browser. Can Terraform use this authentication method as well, and if so, how?
Short answer: not directly. aws login caches short-term credentials plus a refresh token under ~/.aws/login/cache and marks the profile with login_session, and whether a tool can consume that depends on the SDK it is built on. In the AWS SDKs-and-Tools reference the login credentials provider is listed as not supported by the SDK for Go V2, and the Terraform AWS provider’s authentication is built on exactly that SDK. What does work is anything the provider reads from the shared config and credentials files (~/.aws/config, ~/.aws/credentials) or from environment variables: the access key and secret from the tutorial, a named profile, assume-role, or an external credential_process. So for the tutorial the access-key route is the intended one; the aws login flow stays on the CLI side for now.
Yes, Terraform can use that same sign in, because the AWS provider follows the same credential chain as the AWS CLI. Run aws login first and finish the browser and MFA steps, then run Terraform without setting static access keys and it should pick up the credentials from your default profile. If that session expires, run aws login again before your next plan or apply.
That’s the SSO flow. Plain aws login is different. The AWS SDKs-and-Tools reference lists the login credentials provider as not supported by the SDK for Go V2. Terraform’s AWS provider is built on that SDK. aws sso login works because the SSO provider is supported there. So Terraform won’t read the ~/.aws/login cache, but it picks up an SSO session or anything from the shared config and credentials files.
Thanks. As it happens, I have an access key defined on my IAM for the AWS account I’m using (for some other purpose; it’s been quite some time since it was last used), and to my surprise, it has sufficient authority to complete the live tutorial on Create infrastructure | Terraform | HashiCorp Developer . The EC2 instance has spun up, and is now running.
On the other hand, the sandbox tutorial at the bottom of the page is broken: it seems that localstack now requires a license key, and won’t start without one. I’ve already reported this both in my thread about the sandbox tutorial and in feedback. Hopefully somebody will notice.
glad you got it working, otherwise I was going to suggest you might need to do your normal mfa login flow and then mint session creds and use that keypair depending on how your organization is set up. I know that has been the case at places I have worked before, even built a tool to acquire them and rewrite the aws credentials file with them without losing any existing creds.