Terraform is a interesting (in my opinion) tool to implement Infrastructure-as-Code. When I first used it to write production script at yesterday, I met a error report:
Error: error validating provider credentials: error calling sts:GetCallerIdentity: NoCredentialProviders: no valid providers in chain. Deprecated. For verbose messaging see aws.Config.CredentialsChainVerboseErrors
After a while of searching on Google, I got the cause: it can’t find my AWS credential in my computer.
Actually I have ‘~/.aws/credentials’ file, and the ‘access_key_id’, ‘secret_access_key’ are already in it. Like this:
[default] aws_access_key_id = ABCDEFG aws_secret_access_key = A1B2C3D4abcABC
So why can’t Terraform get the credential? The reason is in the ‘provider’ section:
provider "aws" { region = var.region profile = var.aws_profile }
I set the ‘profile’ to ‘analytics’ at first, so the Terraform tried to find something looks like ‘[analytics]’ in ‘~/.aws/credentials’ file, and it failed. The correct way is just set ‘profile’ in ‘provider’ section to ‘default’.
but what happen when have many accounts (profiles) to administrate?
I think we could add all accounts into ‘~/.aws/credentials’ and choose(uncomment) one to use when applying Terraform
Thank you so much for sharirng this. how to fix this issue isn’t listed anywhere.