【问题标题】:Want information regarding terraform List type variable想要关于 terraform List 类型变量的信息
【发布时间】:2020-03-19 09:54:40
【问题描述】:

我声明我的列表类型变量如下

variable service_account_email {
  description = "The email of the service account for the instance template."
  default     = "default"
}

variable service_account_scopes {
  description = "List of scopes for the instance template service account"
  type        = "list"

  default = [
    "https://www.googleapis.com/auth/compute",
    "https://www.googleapis.com/auth/logging.write",
    "https://www.googleapis.com/auth/monitoring.write",
    "https://www.googleapis.com/auth/devstorage.full_control",
  ]
}

但在尝试使用如下变量时,出现如下错误:

service_account {
    email  = "${var.service_account_email}"
    scopes = ["${var.service_account_scopes}"]
  }

错误:属性值类型不正确

在 pure_testing\main.tf 第 22 行,在资源中 “google_compute_instance”“默认”:22:范围 = ["${var.service_account_scopes}"]

属性“范围”的值不合适:元素 0:字符串 必填。

如果我做错了,请你帮我澄清一下 terraform 中列表变量的概念。

提前致谢。

【问题讨论】:

    标签: terraform terraform-provider-gcp


    【解决方案1】:

    您正在尝试将嵌套列表传递给资源。

    去掉scopes = ...部分的方括号应该没问题。

    【讨论】:

    • 删除 [] 后出现如下错误错误:service_account: 属性最多支持 1 个项目,配置声明了 2 个
    • 您需要显示完整配置,但该错误听起来像是您已两次声明 service_account 块。
    • 是的,你是对的,我已经声明了 service_account 2 次,非常感谢你的帮助。我还需要一个帮助(请你帮我理解 Terraform 中的数据概念),再次感谢 :)
    猜你喜欢
    • 2015-03-05
    • 2015-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-06
    • 1970-01-01
    • 2021-01-31
    • 2016-06-01
    相关资源
    最近更新 更多