我创建了一个使用for_each参数生成VM列表的资源。我很难将这个资源引用到我的web_private_group。
resource "google_compute_instance_group" "web_private_group" {
name = "${format("%s","${var.gcp_resource_name}-${var.gcp_env}-vm-group")}"
description = "Web servers instance group"
zone = var.gcp_zone_1
network = google_compute_network.vpc.self_link
# I've added some attempts I've tried that do not work...
instances = [
//google_compute_instance.compute_engines.self_link
//[for o in google_compute_instance.compute_engines : o.self_link]
{for k, o in google_compute_instance.compute_engines : k => o.self_link}
//google_compute_instance.web_private_2.self_link
]
named_port {
name = "http"
port = "80"
}
named_port {
name = "https"
port = "443"
}
}
# Create Google Cloud VMs
resource "google_compute_instance" "compute_engines" {
for_each = var.vm_instances
name = "${format("%s","${var.gcp_resource_name}-${var.gcp_env}-each.value")}"
machine_type = "e2-micro"
zone = var.gcp_zone_1
tags = ["ssh","http"]
boot_disk {
initialize_params {
image = "debian-10"
}
}
}
variable "vm_instances" {
description = "list of VM's"
type = set(string)
default = ["vm1", "vm2", "vm3"]
} 如何正确地将compute_engines链接到web_private_group块中的web_private_group资源?
编辑:为了进一步澄清,我如何声明在我的compute_engines资源中存在多个实例的事实?
发布于 2022-01-08 20:48:14
您可能只需要按照以下方式使用splat表达式:
instances = values(google_compute_instance.compute_engines)[*].id此外,还可以使用for表达式:
instances = [for res in google_compute_instance.compute_engines: res.id]https://stackoverflow.com/questions/70635670
复制相似问题