Skip to content

Commit

Permalink
Add support to customize subnet name
Browse files Browse the repository at this point in the history
  • Loading branch information
robo-cap committed Feb 18, 2025
1 parent 9bd7d26 commit 7ed7407
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions modules/network/subnets.tf
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ resource "oci_core_subnet" "oke" {
compartment_id = var.compartment_id
vcn_id = var.vcn_id
cidr_block = lookup(local.subnet_cidrs_all, each.key)
display_name = format("%v-%v", each.key, var.state_id)
display_name = lookup(var.subnets, each.key, null) != null ? lookup(var.subnets[each.key], "display_name", format("%v-%v", each.key, var.state_id)) : format("%v-%v", each.key, var.state_id)
dns_label = lookup(local.subnet_dns_labels, each.key, null)
prohibit_public_ip_on_vnic = !tobool(lookup(each.value, "is_public", false))
route_table_id = !tobool(lookup(each.value, "is_public", false)) ? var.nat_route_table_id : var.ig_route_table_id
Expand All @@ -136,7 +136,7 @@ resource "oci_core_subnet" "oke" {

lifecycle {
ignore_changes = [
freeform_tags, defined_tags, display_name,
freeform_tags, defined_tags,
cidr_block, dns_label, security_list_ids, vcn_id, route_table_id,
]
}
Expand Down
13 changes: 7 additions & 6 deletions modules/network/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ variable "worker_is_public" { type = bool }

variable "subnets" {
type = map(object({
create = optional(string)
id = optional(string)
newbits = optional(string)
netnum = optional(string)
cidr = optional(string)
dns_label = optional(string)
create = optional(string)
id = optional(string)
newbits = optional(string)
netnum = optional(string)
cidr = optional(string)
display_name = optional(string)
dns_label = optional(string)
}))
}

Expand Down
17 changes: 9 additions & 8 deletions variables-network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,13 @@ variable "subnets" {
}
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."
type = map(object({
create = optional(string)
id = optional(string)
newbits = optional(string)
netnum = optional(string)
cidr = optional(string)
dns_label = optional(string)
create = optional(string)
id = optional(string)
newbits = optional(string)
netnum = optional(string)
cidr = optional(string)
display_name = optional(string)
dns_label = optional(string)
}))
validation {
condition = alltrue([
Expand All @@ -154,10 +155,10 @@ variable "subnets" {
}
validation {
condition = alltrue([
for v in flatten([for k, v in var.subnets : keys(v)]) : contains(["create", "id", "cidr", "netnum", "newbits", "dns_label"], v)
for v in flatten([for k, v in var.subnets : keys(v)]) : contains(["create", "id", "cidr", "netnum", "newbits", "display_name", "dns_label"], v)
])
error_message = format("Invalid subnet configuration keys: %s", jsonencode(distinct([
for v in flatten([for k, v in var.subnets : keys(v)]) : v if !contains(["create", "id", "cidr", "netnum", "newbits", "dns_label"], v)
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)
])))
}
}
Expand Down

0 comments on commit 7ed7407

Please sign in to comment.