在我的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?
答案 0 :(得分:5)
虽然当您将提供程序定义为provider "aws" {}
时,AWS提供程序会自动选择您的环境变量,但它不会对查找tfvars
应用相同的魔力。
要使用vars.tf
中的变量,您需要将这些变量添加到您的提供商定义[1]中:
provider "aws" {
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
}
如果您愿意,也可以使用shared credentials file。