我正在尝试在我的 Terraform 模板中使用环境变量。
即使在采购后 .env
文件并通过运行 echo $env_variable
进行双重检查,还是不行。
这仅适用于我在变量文件中手动指定密码...
变量文件:
variable "password" {}
.env 文件:
#!/bin/bash
export PASS="passwordfoo"
然后我运行以下命令
terraform init
terraform plan \
-var "password=$PASS" \
当我尝试时
terraform apply
它提示我:terraform apply
var.password
Enter a value:
我希望它可以毫无问题地运行。
我遵循了 HashiCorp 自己提供的步骤:
reference links .
最佳答案
terraform 没有按照您的方式获取系统环境变量 export PASS="passwordfoo"
更改 .env
如下面的代码和来源,它应该直接工作,你不需要提要为 -var "password=$PASS"
#!/bin/bash
export TF_VAR_password="passwordfoo"
引用:
https://www.terraform.io/docs/configuration/variables.html#environment-variables
关于environment-variables - 如何在 Terraform 中使用环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55414503/