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

pka*_*mol 0 amazon-web-services terraform

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

vars.tf

variable "AWS_ACCESS_KEY" {}    
variable "AWS_SECRET_KEY" {}
Run Code Online (Sandbox Code Playgroud)

terraform.tfvars

AWS_ACCESS_KEY="xxxxxxxxx"
AWS_SECRET_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Run Code Online (Sandbox Code Playgroud)

然而,

$ 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.
Run Code Online (Sandbox Code Playgroud)

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

spi*_*eap 5

虽然AWS提供程序在您将提供程序定义为自动获取环境变量时provider "aws" {},但它不会使用相同的魔法进行查找tfvars.

为了使用vars.tf你需要的变量,你需要将它们添加到你的提供者定义[1]:

provider "aws" {
  access_key = "${var.access_key}"
  secret_key = "${var.secret_key}"
}
Run Code Online (Sandbox Code Playgroud)

如果您愿意,也可以使用共享凭证文件.