pkaramol
pkaramol

Reputation: 19332

Terraform not accepting AWS credentials from vars/tfvars files

In my terraform directory I have several .tf files among which:

vars.tf

variable "AWS_ACCESS_KEY" {}    
variable "AWS_SECRET_KEY" {}

and terraform.tfvars

AWS_ACCESS_KEY="xxxxxxxxx"
AWS_SECRET_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

however,

$ terraform init

Initializing the 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
then run this command again.

Do I need to set them as env vars too?

Upvotes: 0

Views: 2573

Answers (1)

spikeheap
spikeheap

Reputation: 3887

Although the AWS provider picks up your environment variables automatically when you define the provider as provider "aws" {}, it doesn't apply the same magic to looking up tfvars.

In order to use the variables from vars.tf you'll need to add those to your provider definition[1]:

provider "aws" {
  access_key = "${var.access_key}"
  secret_key = "${var.secret_key}"
}

You can also use a shared credentials file if you'd prefer.

Upvotes: 5

Related Questions