I have existing infrastructure in Terraform and have been using it for a while. Recently I had swapped the AWS credentials of my local laptop (the creds stored in ~/.aws/credentials
) and it stopped working until I re-set those credentials back.
The problem is that I'm declaring the creds in the Terraform source itself but it doesn't seem to be using them at all.
terraform {
backend "s3" {
bucket = "example_tf_states"
key = "global/vpc/us_east_1/example_state.tfstate"
encrypt = true
region = "us-east-1"
}
}
provider "aws" {
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "${var.region}"
}
variable "access_key" {
default = "<hidden_for_stack_exchange_post>"
}
variable "secret_key" {
default = "<hidden_for_stack_exchange_post>"
}
variable "region" {
default = "us-east-1"
}
The access ID permissions are 100% good.
I am using the same account ID and secret key both for the aws configure
settings that go into ~/.aws/credentials
as I am in the above Terraform variable declarations.
Everything works fine as long as the creds are in ~/.aws/credentials
but as soon as the OS level credentials are gone (ie rm ~/.aws/credentials
) I get the following when trying to run Terraform operations, such as terraform plan
:
Failed to load backend:
Error configuring the backend "s3": No valid credential sources found for AWS Provider.
Please see https://terraform.io/docs/providers/aws/index.html for more information on
providing credentials for the AWS Provider
Please update the configuration in your Terraform files to fix this error.
If you'd like to update the configuration interactively without storing
the values in your configuration, run "terraform init".
If I re-populate the ~/.aws/credentials
by running aws configure
it will work fine again.
I'm not understanding -- if my provider
setting is explicitly declaring the credentials to use inside the Terraform source code, why does my OS-level AWS configuration matter at all?
How can I make Terraform only use the creds defined in my Terraform configuration and ignore what's in my OS user profile?
Edit, it's Terraform v0.11.7
Edit: Please note that I'm trying to solve the issue on why the statically declared creds are not being utilized in the provider declaration. Not looking for alternative methods or workarounds. Thanks.