diff --git a/modules/ncc-spoke-ra/README.md b/modules/ncc-spoke-ra/README.md
index 64d37843..0b193407 100644
--- a/modules/ncc-spoke-ra/README.md
+++ b/modules/ncc-spoke-ra/README.md
@@ -40,7 +40,7 @@ module "spoke-ra" {
```hcl
module "spoke-ra-a" {
source = "./fabric/modules/ncc-spoke-ra"
- hub = { name = "ncc-hub" }
+ hub = { id = "projects/my-project/locations/global/hubs/ncc-hub" }
name = "spoke-ra-a"
project_id = "my-project"
region = "europe-west1"
@@ -64,7 +64,7 @@ module "spoke-ra-a" {
module "spoke-ra-b" {
source = "./fabric/modules/ncc-spoke-ra"
- hub = { name = "ncc-hub" }
+ hub = { id = "projects/my-project/locations/global/hubs/ncc-hub" }
name = "spoke-ra-b"
project_id = "my-project"
region = "europe-west3"
@@ -93,7 +93,7 @@ module "spoke-ra-b" {
```hcl
module "spoke-ra" {
source = "./fabric/modules/ncc-spoke-ra"
- hub = { name = "ncc-hub" }
+ hub = { id = "projects/my-project/locations/global/hubs/ncc-hub" }
name = "spoke-ra"
project_id = "my-project"
region = "europe-west1"
@@ -132,13 +132,13 @@ module "spoke-ra" {
| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
-| [hub](variables.tf#L23) | The name of the NCC hub to create or use. | object({…})
| ✓ | |
-| [name](variables.tf#L32) | The name of the NCC spoke. | string
| ✓ | |
-| [project_id](variables.tf#L37) | The ID of the project where the NCC hub & spokes will be created. | string
| ✓ | |
-| [region](variables.tf#L42) | Region where the spoke is located. | string
| ✓ | |
-| [router_appliances](variables.tf#L47) | List of router appliances this spoke is associated with. | list(object({…}))
| ✓ | |
-| [router_config](variables.tf#L55) | Configuration of the Cloud Router. | object({…})
| ✓ | |
-| [vpc_config](variables.tf#L71) | Network and subnetwork for the CR interfaces. | object({…})
| ✓ | |
+| [hub](variables.tf#L23) | The NCC hub. You should either provide an existing hub id or a hub name if create is true. | object({…})
| ✓ | |
+| [name](variables.tf#L37) | The name of the NCC spoke. | string
| ✓ | |
+| [project_id](variables.tf#L42) | The ID of the project where the NCC hub & spokes will be created. | string
| ✓ | |
+| [region](variables.tf#L47) | Region where the spoke is located. | string
| ✓ | |
+| [router_appliances](variables.tf#L52) | List of router appliances this spoke is associated with. | list(object({…}))
| ✓ | |
+| [router_config](variables.tf#L60) | Configuration of the Cloud Router. | object({…})
| ✓ | |
+| [vpc_config](variables.tf#L76) | Network and subnetwork for the CR interfaces. | object({…})
| ✓ | |
| [data_transfer](variables.tf#L17) | Site-to-site data transfer feature, available only in some regions. | bool
| | false
|
## Outputs
diff --git a/modules/ncc-spoke-ra/main.tf b/modules/ncc-spoke-ra/main.tf
index 72ac20fa..a1255498 100644
--- a/modules/ncc-spoke-ra/main.tf
+++ b/modules/ncc-spoke-ra/main.tf
@@ -35,7 +35,7 @@ resource "google_network_connectivity_hub" "hub" {
resource "google_network_connectivity_spoke" "spoke-ra" {
project = var.project_id
- hub = try(google_network_connectivity_hub.hub[0].name, var.hub.name)
+ hub = try(google_network_connectivity_hub.hub[0].id, var.hub.id)
location = var.region
name = var.name
linked_router_appliance_instances {
diff --git a/modules/ncc-spoke-ra/variables.tf b/modules/ncc-spoke-ra/variables.tf
index 17286651..4b01ea16 100644
--- a/modules/ncc-spoke-ra/variables.tf
+++ b/modules/ncc-spoke-ra/variables.tf
@@ -21,12 +21,17 @@ variable "data_transfer" {
}
variable "hub" {
- description = "The name of the NCC hub to create or use."
+ description = "The NCC hub. You should either provide an existing hub id or a hub name if create is true."
type = object({
create = optional(bool, false)
description = optional(string)
- name = string
+ id = optional(string)
+ name = optional(string)
})
+ validation {
+ condition = var.hub.create && var.hub.name != null || var.hub.create == false && var.hub.id != null
+ error_message = "Name is required for configuring new ncc hub while referencing existing hub requires id."
+ }
}
variable "name" {