【问题标题】:Use variables in Terraform on google cloud在谷歌云上的 Terraform 中使用变量
【发布时间】:2018-06-29 12:16:16
【问题描述】:

这是setup.tf

data "google_compute_network" "selected" {
  name = "${var.network}"
}

这是非常基本的。我只想在 Google Cloud 中创建一个网络。 我运行这个:

terraform apply -var 'network=net1'

但我仍然收到如下错误:

Error: resource 'data.google_compute_network.selected' config: unknown variable referenced: 'network'; define it with a 'variable' block

当我没有像预期的那样在作品中使用变量时。

【问题讨论】:

    标签: google-cloud-platform terraform


    【解决方案1】:

    我想您应该定义变量以获取 terraform 而不是抱怨它。

        variable "network" {
          description = "your description goes here"
          type = "string/map/list/boolean"
          default = "default value here"
        }
    

    您可以将它放在主文件中,也可以放在名为 input.tf 的单独文件中,但它必须存在于同一目录中。

    terraform apply -var 'your-var=your-value' 将覆盖变量部分的默认值。

    地形文档:https://www.terraform.io/docs/configuration/variables.html

    【讨论】:

      猜你喜欢
      • 2019-11-10
      • 1970-01-01
      • 2019-10-21
      • 1970-01-01
      • 2021-01-30
      • 1970-01-01
      • 2022-09-24
      • 2017-06-28
      • 1970-01-01
      相关资源
      最近更新 更多