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



在我的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.

我还需要将它们设置为环境变量吗?

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

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

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

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

最新更新