diff --git a/main.tf b/main.tf index fe41fe1..87a2673 100644 --- a/main.tf +++ b/main.tf @@ -1,26 +1,15 @@ locals { - gcp_compute_router_name = coalesce(var.gcp_compute_router_name, lower(format("router-%s", random_string.this.result))) - gcp_compute_router_id = var.gcp_compute_create_router ? google_compute_router.this[0].id : data.google_compute_router.this[0].id + gcp_compute_router_name = lower(format("router-%s", random_string.this.result)) + gcp_compute_router_id = var.gcp_compute_create_router ? google_compute_router.this[0].id : var.gcp_compute_router_id gcp_region = coalesce(var.gcp_region, data.google_client_config.this.region) gcp_project = coalesce(var.gcp_project, data.google_client_config.this.project) - gcp_network = data.google_compute_network.this.id + gcp_network = var.gcp_compute_network_id gcp_bgp_addresses = try(jsondecode(data.local_file.this[0].content), null) gcp_bgp_addresses_file_path = "${path.module}/gcp_peering_addresses.json" } data "google_client_config" "this" {} -data "google_compute_network" "this" { - name = var.gcp_compute_network_name -} - -data "google_compute_router" "this" { - count = var.gcp_compute_create_router ? 0 : 1 - - name = local.gcp_compute_router_name - network = local.gcp_network -} - resource "google_compute_router" "this" { count = var.gcp_compute_create_router ? 1 : 0 diff --git a/outputs.tf b/outputs.tf index 0ae1570..cc1a081 100644 --- a/outputs.tf +++ b/outputs.tf @@ -59,7 +59,7 @@ output "gcp_cloud_router_id" { output "gcp_cloud_router_name" { description = "Google Cloud Router Name." - value = var.gcp_compute_create_router ? google_compute_router.this[0].name : data.google_compute_router.this[0].name + value = var.gcp_compute_create_router ? google_compute_router.this[0].name : "" } output "gcp_cloud_router_ip_address" { diff --git a/variables.tf b/variables.tf index 68a73c1..39b1d4a 100644 --- a/variables.tf +++ b/variables.tf @@ -140,10 +140,10 @@ variable "gcp_project" { default = "" } -variable "gcp_compute_network_name" { +variable "gcp_compute_network_id" { type = string - description = "The name of an existing Google Cloud VPC network. If unspecified, default regional network will be used." - default = "default" + description = "The ID of an existing Google Cloud VPC network. If unspecified, default regional network will be used." + default = "" } variable "gcp_compute_create_router" { @@ -152,9 +152,9 @@ variable "gcp_compute_create_router" { default = true } -variable "gcp_compute_router_name" { +variable "gcp_compute_router_id" { type = string - description = "The name for Google Cloud router. If unspecified, it will be auto-generated. Required if 'gcp_compute_create_router' is false." + description = "The ID for Google Cloud router. If unspecified, it will be auto-generated. Required if 'gcp_compute_create_router' is false." default = "" }