Terraform不接受来自vars / tfvars文件的AWS凭据

时间:2018-06-13 08:23:04

标签: amazon-web-services terraform

在我的terraform目录中,我有几个.tf个文件,其中包括:

vars.tf

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

terraform.tfvars

AWS_ACCESS_KEY="xxxxxxxxx"
AWS_SECRET_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

然而,

$ 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.

我是否也需要将它们设置为env vars?

1 个答案:

答案 0 :(得分:5)

虽然当您将提供程序定义为provider "aws" {}时,AWS提供程序会自动选择您的环境变量,但它不会对查找tfvars应用相同的魔力。

要使用vars.tf中的变量,您需要将这些变量添加到您的提供商定义[1]中:

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

如果您愿意,也可以使用shared credentials file