Skip to content

Commit abf66a2

Browse files
robo-caphyder
authored andcommitted
Add support to customize subnet name and extend rules on the pods and cp NSG
1 parent 9bd7d26 commit abf66a2

File tree

6 files changed

+42
-16
lines changed

6 files changed

+42
-16
lines changed

module-network.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ module "network" {
113113

114114
allow_node_port_access = var.allow_node_port_access
115115
allow_pod_internet_access = var.allow_pod_internet_access
116+
allow_rules_cp = var.allow_rules_cp
116117
allow_rules_internal_lb = var.allow_rules_internal_lb
118+
allow_rules_pods = var.allow_rules_pods
117119
allow_rules_public_lb = var.allow_rules_public_lb
118120
allow_rules_workers = var.allow_rules_workers
119121
allow_worker_internet_access = var.allow_worker_internet_access

modules/network/nsg-controlplane.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ locals {
7474
protocol = local.tcp_protocol, port = local.apiserver_port, source = allowed_cidr, source_type = local.rule_type_cidr
7575
}
7676
},
77+
var.allow_rules_cp
7778
) : {}
7879
}
7980

modules/network/nsg-pods.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ locals {
5353
protocol = local.all_protocols, port = local.all_ports, destination = local.anywhere, destination_type = local.rule_type_cidr,
5454
}
5555
} : {},
56+
var.allow_rules_pods
5657
) : {}
5758
}
5859

modules/network/subnets.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,13 @@ resource "oci_core_subnet" "oke" {
126126
compartment_id = var.compartment_id
127127
vcn_id = var.vcn_id
128128
cidr_block = lookup(local.subnet_cidrs_all, each.key)
129-
display_name = format("%v-%v", each.key, var.state_id)
129+
display_name = ( lookup(var.subnets, each.key, null) != null ?
130+
( lookup(var.subnets[each.key], "display_name", null) != null ?
131+
var.subnets[each.key]["display_name"] :
132+
format("%v-%v", each.key, var.state_id)
133+
) :
134+
format("%v-%v", each.key, var.state_id)
135+
)
130136
dns_label = lookup(local.subnet_dns_labels, each.key, null)
131137
prohibit_public_ip_on_vnic = !tobool(lookup(each.value, "is_public", false))
132138
route_table_id = !tobool(lookup(each.value, "is_public", false)) ? var.nat_route_table_id : var.ig_route_table_id
@@ -136,7 +142,7 @@ resource "oci_core_subnet" "oke" {
136142

137143
lifecycle {
138144
ignore_changes = [
139-
freeform_tags, defined_tags, display_name,
145+
freeform_tags, defined_tags,
140146
cidr_block, dns_label, security_list_ids, vcn_id, route_table_id,
141147
]
142148
}

modules/network/variables.tf

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ variable "use_defined_tags" { type = bool }
1414
# Network
1515
variable "allow_node_port_access" { type = bool }
1616
variable "allow_pod_internet_access" { type = bool }
17+
variable "allow_rules_cp" { type = any }
1718
variable "allow_rules_internal_lb" { type = any }
19+
variable "allow_rules_pods" { type = any }
1820
variable "allow_rules_public_lb" { type = any }
1921
variable "allow_rules_workers" { type = any }
2022
variable "allow_worker_internet_access" { type = bool }
@@ -40,12 +42,13 @@ variable "worker_is_public" { type = bool }
4042

4143
variable "subnets" {
4244
type = map(object({
43-
create = optional(string)
44-
id = optional(string)
45-
newbits = optional(string)
46-
netnum = optional(string)
47-
cidr = optional(string)
48-
dns_label = optional(string)
45+
create = optional(string)
46+
id = optional(string)
47+
newbits = optional(string)
48+
netnum = optional(string)
49+
cidr = optional(string)
50+
display_name = optional(string)
51+
dns_label = optional(string)
4952
}))
5053
}
5154

variables-network.tf

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,13 @@ variable "subnets" {
139139
}
140140
description = "Configuration for standard subnets. The 'create' parameter of each entry defaults to 'auto', creating subnets when other enabled components are expected to utilize them, and may be configured with 'never' or 'always' to force disabled/enabled."
141141
type = map(object({
142-
create = optional(string)
143-
id = optional(string)
144-
newbits = optional(string)
145-
netnum = optional(string)
146-
cidr = optional(string)
147-
dns_label = optional(string)
142+
create = optional(string)
143+
id = optional(string)
144+
newbits = optional(string)
145+
netnum = optional(string)
146+
cidr = optional(string)
147+
display_name = optional(string)
148+
dns_label = optional(string)
148149
}))
149150
validation {
150151
condition = alltrue([
@@ -154,10 +155,10 @@ variable "subnets" {
154155
}
155156
validation {
156157
condition = alltrue([
157-
for v in flatten([for k, v in var.subnets : keys(v)]) : contains(["create", "id", "cidr", "netnum", "newbits", "dns_label"], v)
158+
for v in flatten([for k, v in var.subnets : keys(v)]) : contains(["create", "id", "cidr", "netnum", "newbits", "display_name", "dns_label"], v)
158159
])
159160
error_message = format("Invalid subnet configuration keys: %s", jsonencode(distinct([
160-
for v in flatten([for k, v in var.subnets : keys(v)]) : v if !contains(["create", "id", "cidr", "netnum", "newbits", "dns_label"], v)
161+
for v in flatten([for k, v in var.subnets : keys(v)]) : v if !contains(["create", "id", "cidr", "netnum", "newbits", "display_name", "dns_label"], v)
161162
])))
162163
}
163164
}
@@ -250,12 +251,24 @@ variable "allow_bastion_cluster_access" {
250251
type = bool
251252
}
252253

254+
variable "allow_rules_cp" {
255+
default = {}
256+
description = "A map of additional rules to allow traffic for the OKE control plane."
257+
type = any
258+
}
259+
253260
variable "allow_rules_internal_lb" {
254261
default = {}
255262
description = "A map of additional rules to allow incoming traffic for internal load balancers."
256263
type = any
257264
}
258265

266+
variable "allow_rules_pods" {
267+
default = {}
268+
description = "A map of additional rules to allow traffic for the pods."
269+
type = any
270+
}
271+
259272
variable "allow_rules_public_lb" {
260273
default = {}
261274
description = "A map of additional rules to allow incoming traffic for public load balancers."

0 commit comments

Comments
 (0)