【问题标题】:Input Environment Variables not being read未读取输入环境变量
【发布时间】:2019-11-30 22:43:11
【问题描述】:

我正在尝试在我的 terraform main.tf 文件中使用环境变量。我在我的开发环境中运行了以下命令:

TF_VAR_source_ami=ami-048e57a7474e7284d
echo $TF_VAR_source_ami
ami-048e57a7474e7284d

这是 main.tf 的内容:

variable "source_ami" {
  type        = "string"
  description = "AMI to copy this account"
}

data "aws_ami" "ami_to_be_shared" {
  owners      = ["self"]
  most_recent = true

  filter {
    name   = "image-id"
    values = ["${var.source_ami}"]
  }
}

output "ami_creation_date" {
  value = "${data.aws_ami.ami_to_be_shared.tags.AMICoreEngDate}"
}

当我运行terraform plan 时,它会提示我输入var.source_ami 但是,当我运行terraform apply -var="source_ami=ami-048 e57a7474e7284d" 时它可以工作。

我也尝试过声明没有类型和描述的变量。

附加信息:

感谢您的帮助!

【问题讨论】:

    标签: terraform cloud9


    【解决方案1】:

    你需要导出变量。

    export TF_VAR_source_ami=ami-048e57a7474e7284d
    

    或作为一行运行

    TF_VAR_source_ami=ami-048e57a7474e7284d terraform plan
    

    进一步阅读此Defining a variable with or without export

    【讨论】:

      猜你喜欢
      • 2018-07-15
      • 2014-08-06
      • 2020-12-02
      • 2015-03-29
      • 2017-10-05
      • 2019-07-27
      • 1970-01-01
      • 2019-01-21
      • 1970-01-01
      相关资源
      最近更新 更多