【发布时间】: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"
}
我做错了什么?
【问题讨论】:
-
tags = [var.instance_name]应该可以工作。tags不能是地图,请查看文档:registry.terraform.io/providers/hashicorp/google/latest/docs/… -
好的,知道了。那行得通,谢谢!将该评论作为答案,我会接受。
标签: google-cloud-platform terraform-provider-gcp