【问题标题】:Terraform set GCP name tag Incorrect attribute value type errorTerraform 设置 GCP 名称标签不正确的属性值类型错误
【发布时间】:2021-03-16 14:10:36
【问题描述】:

当我尝试启动一个名称标签设置为变量的新 GCP 实例时,我收到此错误:

terraform apply

Error: Incorrect attribute value type

  on main.tf line 32, in resource "google_compute_instance" "default":
  32:   tags = {
  33:     Name = var.instance_name
  34:   }

Inappropriate value for attribute "tags": set of string required.

这就是我在main.tf 中定义资源的方式:

// A single Compute Engine instance
resource "google_compute_instance" "default" {
  name         = var.instance_name
  machine_type = "f1-micro"
  zone         = "us-west1-a"

  tags = {
    Name = "${var.instance_name}"
  }

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-9"
    }

这就是我在variables.tf 中设置变量的方式:

variable "instance_name" {
  description = "Value of the Name tag for the EC2 instance"
  type        = string
  default     = "mysql-1"
}

我做错了什么?

【问题讨论】:

标签: google-cloud-platform terraform-provider-gcp


【解决方案1】:

tags = [var.instance_name] 应该可以工作。 tags 不能是地图,请参阅 docs

根据您的目标,您可以改为通过labels 实现“标记”:

labels = {
  Name = var.instance_name
}

【讨论】:

  • 非常感谢。如何一次做多个标签?
  • @TimDunphy tags = [var.instance_name, "something", "else"]
猜你喜欢
  • 2021-12-24
  • 2019-12-21
  • 2021-01-16
  • 2020-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-25
相关资源
最近更新 更多