【问题标题】:Getting Module Loading or Input variable error获取模块加载或输入变量错误
【发布时间】:2019-09-18 10:32:36
【问题描述】:

我在 module/variables.tf 中配置了以下变量

variable "instance_name" {
    type = string
    default = "instance-1"
    description = "Name of the instance."
}

我在同一个模块module/main.tf中引用变量如下

resource "google_compute_instance" "cloud_instance" {
    name = var.instance_name
}

但是,当我运行 terraform init 时,我收到以下错误-

Error: Error parsing /module/main.tf: At 15:12: Unknown token: 15:12 IDENT var.instance_name

知道为什么会这样吗?

【问题讨论】:

  • 您运行的是什么版本的 Terraform?如果它是 0.12 之前的版本(现在只是一个测试版),那么应该是 name = "${var.instance_name}"

标签: terraform terraform-provider-gcp


【解决方案1】:

您需要参考以下变量以确保扩展正常工作 -

resource "google_compute_instance" "cloud_instance" {
    name = "${var.instance_name}"
}

【讨论】:

    【解决方案2】:

    使用 terraform 0.12.9 - 我在 initplanvalidate 上没有收到此错误,仅在 0.12upgrade 上。 文档还显示,如果变量不在字符串中,则可以在不使用引号和花括号的情况下传递它。

    那么哪个是正确的?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-15
      • 2017-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多