diff --git a/main.tf b/main.tf index fd3946d..eda2c74 100644 --- a/main.tf +++ b/main.tf @@ -25,11 +25,14 @@ resource "google_dns_managed_zone" "peering" { visibility = "private" force_destroy = var.force_destroy - private_visibility_config { - dynamic "networks" { - for_each = var.private_visibility_config_networks - content { - network_url = networks.value + dynamic "private_visibility_config" { + for_each = length(var.private_visibility_config_networks) > 0 ? [1] : [] + content { + dynamic "networks" { + for_each = var.private_visibility_config_networks + content { + network_url = networks.value + } } } } @@ -52,11 +55,14 @@ resource "google_dns_managed_zone" "forwarding" { visibility = "private" force_destroy = var.force_destroy - private_visibility_config { - dynamic "networks" { - for_each = var.private_visibility_config_networks - content { - network_url = networks.value + dynamic "private_visibility_config" { + for_each = length(var.private_visibility_config_networks) > 0 ? [1] : [] + content { + dynamic "networks" { + for_each = var.private_visibility_config_networks + content { + network_url = networks.value + } } } } @@ -66,7 +72,7 @@ resource "google_dns_managed_zone" "forwarding" { for_each = var.target_name_server_addresses content { ipv4_address = target_name_servers.value.ipv4_address - forwarding_path = target_name_servers.value.forwarding_path + forwarding_path = lookup(target_name_servers.value, "forwarding_path", "default") } } } @@ -82,11 +88,14 @@ resource "google_dns_managed_zone" "private" { visibility = "private" force_destroy = var.force_destroy - private_visibility_config { - dynamic "networks" { - for_each = var.private_visibility_config_networks - content { - network_url = networks.value + dynamic "private_visibility_config" { + for_each = length(var.private_visibility_config_networks) > 0 ? [1] : [] + content { + dynamic "networks" { + for_each = var.private_visibility_config_networks + content { + network_url = networks.value + } } } } @@ -142,11 +151,14 @@ resource "google_dns_managed_zone" "reverse_lookup" { force_destroy = var.force_destroy reverse_lookup = true - private_visibility_config { - dynamic "networks" { - for_each = var.private_visibility_config_networks - content { - network_url = networks.value + dynamic "private_visibility_config" { + for_each = length(var.private_visibility_config_networks) > 0 ? [1] : [] + content { + dynamic "networks" { + for_each = var.private_visibility_config_networks + content { + network_url = networks.value + } } } }