想要有关Terraform List类型变量的信息

时间:2019-11-23 15:39:33

标签: terraform terraform-provider-gcp

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

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:scopes =   [“ $ {var.service_account_scopes}”]

     

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

如果我做错了,请您帮我在terraform中阐明列表变量的概念。

谢谢。

1 个答案:

答案 0 :(得分:1)

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

scopes = ...部分删除方括号,应该没问题。