Skip to content

Commit c177a8b

Browse files
feat(TPG>7.8)!: added ncc preset topology (#642)
Co-authored-by: Imran Nayer <[email protected]>
1 parent 0f4ad32 commit c177a8b

File tree

11 files changed

+149
-43
lines changed

11 files changed

+149
-43
lines changed

docs/upgrading_to_v13.0.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Upgrading to v13.0.0
2+
3+
The v13.0 release contains backwards-incompatible changes.
4+
5+
This update requires upgrading:
6+
- minimum provider version of `hashicorp/google` to `7.8` for network-connectivity-center sub-module.

examples/network_connectivity_center/main.tf

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@
1616

1717
module "network_connectivity_center" {
1818
source = "terraform-google-modules/network/google//modules/network-connectivity-center"
19-
version = "~> 12.0"
19+
version = "~> 13.0"
20+
2021

2122
project_id = var.project_id
2223
ncc_hub_name = var.ncc_hub_name
2324
ncc_hub_labels = {
2425
"module" = "ncc"
2526
}
26-
spoke_labels = {
27-
"created-by" = "terraform-google-ncc-example"
28-
}
29-
3027
vpc_spokes = {
3128
"vpc-1" = {
3229
uri = module.vpc_spoke_vpc.network_id
@@ -76,6 +73,36 @@ module "network_connectivity_center" {
7673
}
7774
}
7875

76+
module "network_connectivity_center_star" {
77+
source = "terraform-google-modules/network/google//modules/network-connectivity-center"
78+
version = "~> 13.0"
79+
80+
project_id = var.project_id
81+
ncc_hub_name = "${var.ncc_hub_name}-star"
82+
ncc_hub_labels = {
83+
"module" = "ncc"
84+
}
85+
ncc_hub_preset_topology = "STAR"
86+
ncc_groups = {
87+
"center" = {
88+
name = "center"
89+
labels = {
90+
"module" = "ncc"
91+
}
92+
}
93+
"edge" = {
94+
name = "edge"
95+
auto_accept_projects = [
96+
"foo",
97+
"bar"
98+
]
99+
}
100+
}
101+
spoke_labels = {
102+
"created-by" = "terraform-google-ncc-example"
103+
}
104+
}
105+
79106
################################
80107
# VPC Spoke #
81108
################################

examples/network_connectivity_center/outputs.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ output "vpc_spokes" {
2929
value = module.network_connectivity_center.vpc_spokes
3030
}
3131

32-
3332
output "hybrid_spokes" {
3433
description = "All hybrid spoke objects"
3534
value = module.network_connectivity_center.hybrid_spokes
@@ -44,3 +43,13 @@ output "spokes" {
4443
description = "All spoke objects prefixed with the type of spoke (vpc, hybrid, appliance)"
4544
value = module.network_connectivity_center.spokes
4645
}
46+
47+
output "ncc_hub_name_star" {
48+
description = "Name of the NCC Hub (required for testing)"
49+
value = element(reverse(split("/", module.network_connectivity_center_star.ncc_hub.name)), 0)
50+
}
51+
52+
output "groups" {
53+
description = "All spoke objects prefixed with the type of spoke (vpc, hybrid, appliance)"
54+
value = module.network_connectivity_center_star.groups
55+
}

examples/network_connectivity_center/versions.tf

Lines changed: 0 additions & 27 deletions
This file was deleted.

modules/network-connectivity-center/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,23 @@ An extensive example that also contains the creation and attachment of multiple
2323
| Name | Description | Type | Default | Required |
2424
|------|-------------|------|---------|:--------:|
2525
| export\_psc | Whether Private Service Connect transitivity is enabled for the hub | `bool` | `false` | no |
26-
| hybrid\_spokes | VLAN attachments and VPN Tunnels that are associated with the spoke. Type must be one of `interconnect` and `vpn`. | <pre>map(object({<br> location = string<br> uris = set(string)<br> site_to_site_data_transfer = optional(bool, false)<br> type = string<br> description = optional(string)<br> labels = optional(map(string))<br> include_import_ranges = optional(list(string), [])<br> }))</pre> | `{}` | no |
26+
| hybrid\_spokes | VLAN attachments and VPN Tunnels that are associated with the spoke. Type must be one of `interconnect` and `vpn`. | <pre>map(object({<br> location = string<br> uris = set(string)<br> site_to_site_data_transfer = optional(bool, false)<br> type = string<br> description = optional(string)<br> labels = optional(map(string))<br> include_import_ranges = optional(list(string), [])<br> group = optional(string)<br> }))</pre> | `{}` | no |
27+
| ncc\_groups | Groups for Hubs using the star topolgy | <pre>map(object({<br> name = string<br> labels = optional(map(string))<br> description = optional(string)<br> auto_accept_projects = optional(list(string), [])<br> }))</pre> | `{}` | no |
2728
| ncc\_hub\_description | The description of the NCC Hub | `string` | `null` | no |
2829
| ncc\_hub\_labels | These labels will be added the NCC hub | `map(string)` | `{}` | no |
2930
| ncc\_hub\_name | The Name of the NCC Hub | `string` | n/a | yes |
31+
| ncc\_hub\_policy\_mode | The policy mode of the hub. Type must be one of `PRESET` or `CUSTOM`. | `string` | `"PRESET"` | no |
32+
| ncc\_hub\_preset\_topology | The topology implemented in the hub. Type must be one of `STAR`, `MESH` or `HYBRID_INSPECTION`. | `string` | `null` | no |
3033
| project\_id | Project ID of the project that holds the network. | `string` | n/a | yes |
31-
| router\_appliance\_spokes | Router appliance instances that are associated with the spoke. | <pre>map(object({<br> instances = set(object({<br> virtual_machine = string<br> ip_address = string<br> }))<br> location = string<br> site_to_site_data_transfer = optional(bool, false)<br> description = optional(string)<br> labels = optional(map(string))<br> include_import_ranges = optional(list(string), [])<br> }))</pre> | `{}` | no |
34+
| router\_appliance\_spokes | Router appliance instances that are associated with the spoke. | <pre>map(object({<br> instances = set(object({<br> virtual_machine = string<br> ip_address = string<br> }))<br> location = string<br> site_to_site_data_transfer = optional(bool, false)<br> description = optional(string)<br> labels = optional(map(string))<br> include_import_ranges = optional(list(string), [])<br> group = optional(string)<br> }))</pre> | `{}` | no |
3235
| spoke\_labels | These labels will be added to all NCC spokes | `map(string)` | `{}` | no |
33-
| vpc\_spokes | VPC network that is associated with the spoke. link\_producer\_vpc\_network: Producer VPC network that is peered with vpc network | <pre>map(object({<br> uri = string<br> exclude_export_ranges = optional(set(string), [])<br> include_export_ranges = optional(set(string), [])<br> description = optional(string)<br> labels = optional(map(string))<br><br> link_producer_vpc_network = optional(object({<br> network_name = string<br> peering = string<br> include_export_ranges = optional(list(string))<br> exclude_export_ranges = optional(list(string))<br> description = optional(string)<br> labels = optional(map(string))<br> }))<br> }))</pre> | `{}` | no |
36+
| vpc\_spokes | VPC network that is associated with the spoke. link\_producer\_vpc\_network: Producer VPC network that is peered with vpc network | <pre>map(object({<br> uri = string<br> exclude_export_ranges = optional(set(string), [])<br> include_export_ranges = optional(set(string), [])<br> description = optional(string)<br> labels = optional(map(string))<br> group = optional(string)<br><br> link_producer_vpc_network = optional(object({<br> network_name = string<br> peering = string<br> include_export_ranges = optional(list(string))<br> exclude_export_ranges = optional(list(string))<br> description = optional(string)<br> labels = optional(map(string))<br> group = optional(string)<br> }))<br> }))</pre> | `{}` | no |
3437

3538
## Outputs
3639

3740
| Name | Description |
3841
|------|-------------|
42+
| groups | All group objects |
3943
| hybrid\_spokes | All hybrid spoke objects |
4044
| ncc\_hub | The NCC Hub object |
4145
| producer\_vpc\_network\_spoke | All producer network vpc spoke objects |

modules/network-connectivity-center/main.tf

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,31 @@ locals {
3131
for k, v in google_network_connectivity_spoke.producer_vpc_network_spoke :
3232
k => v
3333
}
34+
groups = {
35+
for k, v in google_network_connectivity_group.group :
36+
k => v
37+
}
3438
}
3539

3640
resource "google_network_connectivity_hub" "hub" {
37-
name = var.ncc_hub_name
38-
project = var.project_id
39-
description = var.ncc_hub_description
40-
export_psc = var.export_psc
41-
labels = var.ncc_hub_labels
41+
name = var.ncc_hub_name
42+
project = var.project_id
43+
description = var.ncc_hub_description
44+
export_psc = var.export_psc
45+
labels = var.ncc_hub_labels
46+
policy_mode = var.ncc_hub_policy_mode
47+
preset_topology = var.ncc_hub_policy_mode == "PRESET" ? var.ncc_hub_preset_topology : (var.ncc_hub_policy_mode == "CUSTOM" ? "PRESET_TOPOLOGY_UNSPECIFIED" : "MESH")
4248
}
4349

50+
resource "google_network_connectivity_group" "group" {
51+
for_each = var.ncc_groups
52+
name = each.value.name
53+
hub = google_network_connectivity_hub.hub.id
54+
project = var.project_id
55+
auto_accept {
56+
auto_accept_projects = each.value.auto_accept_projects
57+
}
58+
}
4459

4560
resource "google_network_connectivity_spoke" "vpc_spoke" {
4661
for_each = var.vpc_spokes
@@ -50,6 +65,7 @@ resource "google_network_connectivity_spoke" "vpc_spoke" {
5065
description = each.value.description
5166
hub = google_network_connectivity_hub.hub.id
5267
labels = merge(var.spoke_labels, each.value.labels)
68+
group = each.value.group
5369

5470
linked_vpc_network {
5571
uri = each.value.uri
@@ -66,6 +82,7 @@ resource "google_network_connectivity_spoke" "producer_vpc_network_spoke" {
6682
description = each.value.description
6783
hub = google_network_connectivity_hub.hub.id
6884
labels = merge(var.spoke_labels, each.value.labels)
85+
group = each.value.group
6986

7087
linked_producer_vpc_network {
7188
network = each.value.network_name
@@ -84,6 +101,7 @@ resource "google_network_connectivity_spoke" "hybrid_spoke" {
84101
description = each.value.description
85102
hub = google_network_connectivity_hub.hub.id
86103
labels = merge(var.spoke_labels, each.value.labels)
104+
group = each.value.group
87105

88106
dynamic "linked_interconnect_attachments" {
89107
for_each = each.value.type == "interconnect" ? [1] : []
@@ -112,6 +130,7 @@ resource "google_network_connectivity_spoke" "router_appliance_spoke" {
112130
description = each.value.description
113131
hub = google_network_connectivity_hub.hub.id
114132
labels = merge(var.spoke_labels, each.value.labels)
133+
group = each.value.group
115134

116135
linked_router_appliance_instances {
117136
dynamic "instances" {

modules/network-connectivity-center/metadata.yaml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,23 @@ spec:
105105
description: These labels will be added the NCC hub
106106
varType: map(string)
107107
defaultValue: {}
108+
- name: ncc_hub_preset_topology
109+
description: The topology implemented in the hub. Type must be one of `STAR`, `MESH` or `HYBRID_INSPECTION`.
110+
varType: string
111+
- name: ncc_hub_policy_mode
112+
description: The policy mode of the hub. Type must be one of `PRESET` or `CUSTOM`.
113+
varType: string
114+
defaultValue: PRESET
115+
- name: ncc_groups
116+
description: Groups for Hubs using the star topolgy
117+
varType: |-
118+
map(object({
119+
name = string
120+
labels = optional(map(string))
121+
description = optional(string)
122+
auto_accept_projects = optional(list(string), [])
123+
}))
124+
defaultValue: {}
108125
- name: export_psc
109126
description: Whether Private Service Connect transitivity is enabled for the hub
110127
varType: bool
@@ -118,6 +135,7 @@ spec:
118135
include_export_ranges = optional(set(string), [])
119136
description = optional(string)
120137
labels = optional(map(string))
138+
group = optional(string)
121139
122140
link_producer_vpc_network = optional(object({
123141
network_name = string
@@ -126,6 +144,7 @@ spec:
126144
exclude_export_ranges = optional(list(string))
127145
description = optional(string)
128146
labels = optional(map(string))
147+
group = optional(string)
129148
}))
130149
}))
131150
defaultValue: {}
@@ -140,6 +159,7 @@ spec:
140159
description = optional(string)
141160
labels = optional(map(string))
142161
include_import_ranges = optional(list(string), [])
162+
group = optional(string)
143163
}))
144164
defaultValue: {}
145165
- name: router_appliance_spokes
@@ -155,13 +175,16 @@ spec:
155175
description = optional(string)
156176
labels = optional(map(string))
157177
include_import_ranges = optional(list(string), [])
178+
group = optional(string)
158179
}))
159180
defaultValue: {}
160181
- name: spoke_labels
161182
description: These labels will be added to all NCC spokes
162183
varType: map(string)
163184
defaultValue: {}
164185
outputs:
186+
- name: groups
187+
description: All group objects
165188
- name: hybrid_spokes
166189
description: All hybrid spoke objects
167190
- name: ncc_hub
@@ -204,4 +227,4 @@ spec:
204227
- servicenetworking.googleapis.com
205228
providerVersions:
206229
- source: hashicorp/google
207-
version: ">= 6.49, < 8"
230+
version: ">= 6.9, < 8"

modules/network-connectivity-center/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,8 @@ output "spokes" {
6060
},
6161
])
6262
}
63+
64+
output "groups" {
65+
description = "All group objects"
66+
value = local.groups
67+
}

modules/network-connectivity-center/variables.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,29 @@ variable "ncc_hub_labels" {
3535
default = {}
3636
}
3737

38+
variable "ncc_hub_preset_topology" {
39+
description = "The topology implemented in the hub. Type must be one of `STAR`, `MESH` or `HYBRID_INSPECTION`."
40+
type = string
41+
default = null
42+
}
43+
44+
variable "ncc_hub_policy_mode" {
45+
description = "The policy mode of the hub. Type must be one of `PRESET` or `CUSTOM`."
46+
type = string
47+
default = "PRESET"
48+
}
49+
50+
variable "ncc_groups" {
51+
description = "Groups for Hubs using the star topolgy"
52+
type = map(object({
53+
name = string
54+
labels = optional(map(string))
55+
description = optional(string)
56+
auto_accept_projects = optional(list(string), [])
57+
}))
58+
default = {}
59+
}
60+
3861
variable "export_psc" {
3962
description = "Whether Private Service Connect transitivity is enabled for the hub"
4063
type = bool
@@ -49,6 +72,7 @@ variable "vpc_spokes" {
4972
include_export_ranges = optional(set(string), [])
5073
description = optional(string)
5174
labels = optional(map(string))
75+
group = optional(string)
5276

5377
link_producer_vpc_network = optional(object({
5478
network_name = string
@@ -57,6 +81,7 @@ variable "vpc_spokes" {
5781
exclude_export_ranges = optional(list(string))
5882
description = optional(string)
5983
labels = optional(map(string))
84+
group = optional(string)
6085
}))
6186
}))
6287
default = {}
@@ -83,6 +108,7 @@ variable "hybrid_spokes" {
83108
description = optional(string)
84109
labels = optional(map(string))
85110
include_import_ranges = optional(list(string), [])
111+
group = optional(string)
86112
}))
87113
default = {}
88114
}
@@ -99,6 +125,7 @@ variable "router_appliance_spokes" {
99125
description = optional(string)
100126
labels = optional(map(string))
101127
include_import_ranges = optional(list(string), [])
128+
group = optional(string)
102129
}))
103130
default = {}
104131
}

modules/network-connectivity-center/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ terraform {
2020
required_providers {
2121
google = {
2222
source = "hashicorp/google"
23-
version = ">= 6.49, < 8"
23+
version = ">= 7.8, < 8"
2424

2525
}
2626
}

0 commit comments

Comments
 (0)