【发布时间】:2021-12-17 13:50:19
【问题描述】:
如何使用 GCP 在 terraform 上添加或删除块代码 access_config { }。
我有变量:
external_ip = false
如果外部 IP 值为 false 代码:
resource "google_compute_instance_from_template" "default_name_index" {
name = "${length(var.instances[change_with_index].instance_backup_ip) == 1 ? var.instances[change_with_index].instance_backup_name : format("%s-%s", var.instances[change_with_index].instance_backup_name, count.index + 1)}"
count = length(var.instances[change_with_index].instance_backup_ip)
source_instance_template = "projects/${var.provider_project}/global/instanceTemplates/${replace(var.instances[change_with_index].instance_name, "-app-image", "")}-${var.release_version}"
network_interface {
network = var.instances[change_with_index].instance_network
subnetwork = var.instances[change_with_index].instance_subnetwork
network_ip = var.instances[change_with_index].instance_backup_ip[count.index]
}
}
如果 external_ip 的值为 true 代码:
resource "google_compute_instance_from_template" "default_name_index" {
name = "${length(var.instances[change_with_index].instance_backup_ip) == 1 ? var.instances[change_with_index].instance_backup_name : format("%s-%s", var.instances[change_with_index].instance_backup_name, count.index + 1)}"
count = length(var.instances[change_with_index].instance_backup_ip)
source_instance_template = "projects/${var.provider_project}/global/instanceTemplates/${replace(var.instances[change_with_index].instance_name, "-app-image", "")}-${var.release_version}"
network_interface {
network = var.instances[change_with_index].instance_network
subnetwork = var.instances[change_with_index].instance_subnetwork
network_ip = var.instances[change_with_index].instance_backup_ip[count.index]
#access_config will add in here
access_config
{
}
}
}
谢谢你帮助我。
【问题讨论】:
标签: google-cloud-platform terraform terraform-provider-gcp