Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion examples/network_connectivity_center/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,32 @@ module "network_connectivity_center" {
ncc_hub_labels = {
"module" = "ncc"
}
ncc_hub_preset_topology = "STAR"
ncc_groups = {
"center" = {
name = "center"
labels = {
"module" = "ncc"
}
}
"edge" = {
name = "edge"
auto_accept_projects = [
"foo",
"bar"
]
}
}
spoke_labels = {
"created-by" = "terraform-google-ncc-example"
}

vpc_spokes = {
"vpc-1" = {
uri = module.vpc_spoke_vpc.network_id
labels = {
"spoke-type" = "vpc"
}
group = "edge"
}
"producer-conn" = {
uri = google_compute_network.producer_connected_network.id
Expand All @@ -49,6 +65,7 @@ module "network_connectivity_center" {
"198.51.100.0/24",
"10.10.0.0/16"
]
group = "center"
}
}
}
Expand All @@ -59,6 +76,7 @@ module "network_connectivity_center" {
uris = [for k, v in module.local_to_remote_vpn.tunnel_self_links : v]
site_to_site_data_transfer = true
location = var.vpn_region
group = "center"
}
}
router_appliance_spokes = {
Expand All @@ -72,6 +90,7 @@ module "network_connectivity_center" {
]
location = var.instance_region
site_to_site_data_transfer = false
group = "center"
}
}
}
Expand Down
29 changes: 24 additions & 5 deletions modules/network-connectivity-center/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,31 @@ locals {
for k, v in google_network_connectivity_spoke.producer_vpc_network_spoke :
k => v
}
groups = {
for k, v in google_network_connectivity_group.group :
k => v
}
}

resource "google_network_connectivity_hub" "hub" {
name = var.ncc_hub_name
project = var.project_id
description = var.ncc_hub_description
export_psc = var.export_psc
labels = var.ncc_hub_labels
name = var.ncc_hub_name
project = var.project_id
description = var.ncc_hub_description
export_psc = var.export_psc
labels = var.ncc_hub_labels
policy_mode = var.ncc_hub_policy_mode
preset_topology = var.ncc_hub_policy_mode == "PRESET" ? var.ncc_hub_preset_topology : (var.ncc_hub_policy_mode == "CUSTOM" ? "PRESET_TOPOLOGY_UNSPECIFIED" : "MESH")
}

resource "google_network_connectivity_group" "group" {
for_each = var.ncc_groups
name = each.value.name
hub = google_network_connectivity_hub.hub.id
project = var.project_id
auto_accept {
auto_accept_projects = each.value.auto_accept_projects
}
}

resource "google_network_connectivity_spoke" "vpc_spoke" {
for_each = var.vpc_spokes
Expand All @@ -50,6 +65,7 @@ resource "google_network_connectivity_spoke" "vpc_spoke" {
description = each.value.description
hub = google_network_connectivity_hub.hub.id
labels = merge(var.spoke_labels, each.value.labels)
group = each.value.group

linked_vpc_network {
uri = each.value.uri
Expand All @@ -66,6 +82,7 @@ resource "google_network_connectivity_spoke" "producer_vpc_network_spoke" {
description = each.value.description
hub = google_network_connectivity_hub.hub.id
labels = merge(var.spoke_labels, each.value.labels)
group = each.value.group

linked_producer_vpc_network {
network = each.value.network_name
Expand All @@ -84,6 +101,7 @@ resource "google_network_connectivity_spoke" "hybrid_spoke" {
description = each.value.description
hub = google_network_connectivity_hub.hub.id
labels = merge(var.spoke_labels, each.value.labels)
group = each.value.group

dynamic "linked_interconnect_attachments" {
for_each = each.value.type == "interconnect" ? [1] : []
Expand Down Expand Up @@ -112,6 +130,7 @@ resource "google_network_connectivity_spoke" "router_appliance_spoke" {
description = each.value.description
hub = google_network_connectivity_hub.hub.id
labels = merge(var.spoke_labels, each.value.labels)
group = each.value.group

linked_router_appliance_instances {
dynamic "instances" {
Expand Down
4 changes: 4 additions & 0 deletions modules/network-connectivity-center/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ output "spokes" {
},
])
}

output "groups" {
value = local.groups
}
27 changes: 27 additions & 0 deletions modules/network-connectivity-center/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ variable "ncc_hub_labels" {
default = {}
}

variable "ncc_hub_preset_topology" {
description = "The topology implemented in the hub"
type = string
default = ""
}

variable "ncc_hub_policy_mode" {
description = "The policy mode of the hub"
type = string
default = "PRESET"
}

variable "ncc_groups" {
description = "Groups for Hubs using the star topolgy"
type = map(object({
name = string
labels = optional(map(string))
description = optional(string)
auto_accept_projects = optional(list(string), [])
}))
default = {}
}

variable "export_psc" {
description = "Whether Private Service Connect transitivity is enabled for the hub"
type = bool
Expand All @@ -49,6 +72,7 @@ variable "vpc_spokes" {
include_export_ranges = optional(set(string), [])
description = optional(string)
labels = optional(map(string))
group = optional(string)

link_producer_vpc_network = optional(object({
network_name = string
Expand All @@ -57,6 +81,7 @@ variable "vpc_spokes" {
exclude_export_ranges = optional(list(string))
description = optional(string)
labels = optional(map(string))
group = optional(string)
}))
}))
default = {}
Expand All @@ -83,6 +108,7 @@ variable "hybrid_spokes" {
description = optional(string)
labels = optional(map(string))
include_import_ranges = optional(list(string), [])
group = optional(string)
}))
default = {}
}
Expand All @@ -99,6 +125,7 @@ variable "router_appliance_spokes" {
description = optional(string)
labels = optional(map(string))
include_import_ranges = optional(list(string), [])
group = optional(string)
}))
default = {}
}
Expand Down