From 34c6a6aee107558f6f481ae7b1eb80d5b70f2d55 Mon Sep 17 00:00:00 2001 From: Julio Diez Date: Wed, 8 Mar 2023 16:41:02 +0100 Subject: [PATCH] Make creation of the hub optional --- modules/net-ncc/main.tf | 7 ++++--- modules/net-ncc/variables.tf | 13 ++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/net-ncc/main.tf b/modules/net-ncc/main.tf index 02db91d7..e4d08881 100644 --- a/modules/net-ncc/main.tf +++ b/modules/net-ncc/main.tf @@ -25,14 +25,15 @@ locals { } resource "google_network_connectivity_hub" "hub" { + count = var.hub.create ? 1 : 0 project = var.project_id - name = var.name - description = var.description + name = var.hub.name + description = var.hub.description } resource "google_network_connectivity_spoke" "spoke-ra" { project = var.project_id - hub = google_network_connectivity_hub.hub.id + hub = try(google_network_connectivity_hub.hub[0].name, var.hub.name) location = var.region name = var.name linked_router_appliance_instances { diff --git a/modules/net-ncc/variables.tf b/modules/net-ncc/variables.tf index a11bde75..976f5120 100644 --- a/modules/net-ncc/variables.tf +++ b/modules/net-ncc/variables.tf @@ -34,10 +34,13 @@ variable "data_transfer" { default = false } -variable "description" { - description = "An optional description of the NCC hub." - type = string - default = "Terraform-managed." +variable "hub" { + description = "The name of the NCC hub to create or use." + type = object({ + create = optional(bool, false) + name = string + description = optional(string) + }) } variable "ip_intf1" { @@ -59,7 +62,7 @@ variable "keepalive" { } variable "name" { - description = "The name of the NCC hub being created." + description = "The name of the NCC spoke." type = string }