Skip to content

Commit cad676e

Browse files
authored
feat: Added a new property to the subnet input variable map, disable_auto_addr_prefix, that if set to "true" will not automatically create a new matching address prefix for the subnet, no matter the condition. (#741)
1 parent f5a7deb commit cad676e

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ To attach access management tags to resources in this module, you need the follo
180180
| <a name="input_routing_table_name"></a> [routing\_table\_name](#input\_routing\_table\_name) | The name to give the provisioned routing tables. If not set, the module generates a name based on the `prefix` and `name` variables. | `string` | `null` | no |
181181
| <a name="input_security_group_rules"></a> [security\_group\_rules](#input\_security\_group\_rules) | A list of security group rules to be added to the default vpc security group (default empty) | <pre>list(<br> object({<br> name = string<br> direction = string<br> remote = string<br> tcp = optional(<br> object({<br> port_max = optional(number)<br> port_min = optional(number)<br> })<br> )<br> udp = optional(<br> object({<br> port_max = optional(number)<br> port_min = optional(number)<br> })<br> )<br> icmp = optional(<br> object({<br> type = optional(number)<br> code = optional(number)<br> })<br> )<br> })<br> )</pre> | `[]` | no |
182182
| <a name="input_skip_custom_resolver_hub_creation"></a> [skip\_custom\_resolver\_hub\_creation](#input\_skip\_custom\_resolver\_hub\_creation) | Indicates whether to skip the configuration of a custom resolver in the hub VPC. Only relevant if enable\_hub is set to true. | `bool` | `false` | no |
183-
| <a name="input_subnets"></a> [subnets](#input\_subnets) | List of subnets for the vpc. For each item in each array, a subnet will be created. Items can be either CIDR blocks or total ipv4 addressess. Public gateways will be enabled only in zones where a gateway has been created | <pre>object({<br> zone-1 = list(object({<br> name = string<br> cidr = string<br> public_gateway = optional(bool)<br> acl_name = string<br> }))<br> zone-2 = optional(list(object({<br> name = string<br> cidr = string<br> public_gateway = optional(bool)<br> acl_name = string<br> })))<br> zone-3 = optional(list(object({<br> name = string<br> cidr = string<br> public_gateway = optional(bool)<br> acl_name = string<br> })))<br> })</pre> | <pre>{<br> "zone-1": [<br> {<br> "acl_name": "vpc-acl",<br> "cidr": "10.10.10.0/24",<br> "name": "subnet-a",<br> "public_gateway": true<br> }<br> ],<br> "zone-2": [<br> {<br> "acl_name": "vpc-acl",<br> "cidr": "10.20.10.0/24",<br> "name": "subnet-b",<br> "public_gateway": true<br> }<br> ],<br> "zone-3": [<br> {<br> "acl_name": "vpc-acl",<br> "cidr": "10.30.10.0/24",<br> "name": "subnet-c",<br> "public_gateway": false<br> }<br> ]<br>}</pre> | no |
183+
| <a name="input_subnets"></a> [subnets](#input\_subnets) | List of subnets for the vpc. For each item in each array, a subnet will be created. Items can be either CIDR blocks or total ipv4 addressess. Public gateways will be enabled only in zones where a gateway has been created | <pre>object({<br> zone-1 = list(object({<br> name = string<br> cidr = string<br> public_gateway = optional(bool)<br> acl_name = string<br> no_addr_prefix = optional(bool, false) # do not automatically add address prefix for subnet, overrides other conditions if set to true<br> }))<br> zone-2 = optional(list(object({<br> name = string<br> cidr = string<br> public_gateway = optional(bool)<br> acl_name = string<br> no_addr_prefix = optional(bool, false) # do not automatically add address prefix for subnet, overrides other conditions if set to true<br> })))<br> zone-3 = optional(list(object({<br> name = string<br> cidr = string<br> public_gateway = optional(bool)<br> acl_name = string<br> no_addr_prefix = optional(bool, false) # do not automatically add address prefix for subnet, overrides other conditions if set to true<br> })))<br> })</pre> | <pre>{<br> "zone-1": [<br> {<br> "acl_name": "vpc-acl",<br> "cidr": "10.10.10.0/24",<br> "name": "subnet-a",<br> "no_addr_prefix": false,<br> "public_gateway": true<br> }<br> ],<br> "zone-2": [<br> {<br> "acl_name": "vpc-acl",<br> "cidr": "10.20.10.0/24",<br> "name": "subnet-b",<br> "no_addr_prefix": false,<br> "public_gateway": true<br> }<br> ],<br> "zone-3": [<br> {<br> "acl_name": "vpc-acl",<br> "cidr": "10.30.10.0/24",<br> "name": "subnet-c",<br> "no_addr_prefix": false,<br> "public_gateway": false<br> }<br> ]<br>}</pre> | no |
184184
| <a name="input_tags"></a> [tags](#input\_tags) | List of Tags for the resource created | `list(string)` | `null` | no |
185185
| <a name="input_update_delegated_resolver"></a> [update\_delegated\_resolver](#input\_update\_delegated\_resolver) | If set to true, and if the vpc is configured to be a spoke for DNS resolution (enable\_hub\_vpc\_crn or enable\_hub\_vpc\_id set), then the spoke VPC resolver will be updated to a delegated resolver. | `bool` | `false` | no |
186186
| <a name="input_use_existing_dns_instance"></a> [use\_existing\_dns\_instance](#input\_use\_existing\_dns\_instance) | Whether to use an existing dns instance. If true, existing\_dns\_instance\_id must be set. | `bool` | `false` | no |

dynamic_values/subnet.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ locals {
1616
zone = index(keys(var.subnets), zone) + 1 # Zone 1, 2, or 3
1717
zone_name = "${var.region}-${index(keys(var.subnets), zone) + 1}" # Contains region and zone
1818
cidr = value.cidr # CIDR Block
19+
no_prefix = value.no_addr_prefix # If true will not create addr prefix for subnet under any circumstance
1920
count = index(var.subnets[zone], value) + 1 # Count of the subnet within the zone
2021
acl = value.acl_name
2122
# Public gateway ID

dynamic_values/variables.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,21 @@ variable "subnets" {
187187
cidr = string
188188
public_gateway = optional(bool)
189189
acl_name = string
190+
no_addr_prefix = optional(bool, false)
190191
}))
191192
zone-2 = list(object({
192193
name = string
193194
cidr = string
194195
public_gateway = optional(bool)
195196
acl_name = string
197+
no_addr_prefix = optional(bool, false)
196198
}))
197199
zone-3 = list(object({
198200
name = string
199201
cidr = string
200202
public_gateway = optional(bool)
201203
acl_name = string
204+
no_addr_prefix = optional(bool, false)
202205
}))
203206
})
204207
}

subnet.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ locals {
1717

1818
resource "ibm_is_vpc_address_prefix" "subnet_prefix" {
1919
# Address prefixes replace subnet prefixes
20-
for_each = length(local.address_prefixes) > 0 || !var.create_subnets ? {} : local.subnet_object
20+
# Only create prefix if creating subnets, flag not set to disable prefix creation, and no specific prefixes were supplied
21+
for_each = { for k, v in local.subnet_object : k => v if(v.no_prefix == false && var.create_subnets == true && length(local.address_prefixes) == 0) }
2122
name = each.value.prefix_name
2223
zone = each.value.zone_name
2324
vpc = local.vpc_id
@@ -37,7 +38,7 @@ resource "ibm_is_subnet" "subnet" {
3738
name = each.key
3839
zone = each.value.zone_name
3940
resource_group = var.resource_group_id
40-
ipv4_cidr_block = length(keys(local.address_prefixes)) == 0 ? ibm_is_vpc_address_prefix.subnet_prefix[each.value.prefix_name].cidr : each.value.cidr
41+
ipv4_cidr_block = length(keys(local.address_prefixes)) == 0 && !each.value.no_prefix ? ibm_is_vpc_address_prefix.subnet_prefix[each.value.prefix_name].cidr : each.value.cidr
4142
network_acl = ibm_is_network_acl.network_acl[each.value.acl].id
4243
public_gateway = each.value.public_gateway
4344
tags = var.tags

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,18 +324,21 @@ variable "subnets" {
324324
cidr = string
325325
public_gateway = optional(bool)
326326
acl_name = string
327+
no_addr_prefix = optional(bool, false) # do not automatically add address prefix for subnet, overrides other conditions if set to true
327328
}))
328329
zone-2 = optional(list(object({
329330
name = string
330331
cidr = string
331332
public_gateway = optional(bool)
332333
acl_name = string
334+
no_addr_prefix = optional(bool, false) # do not automatically add address prefix for subnet, overrides other conditions if set to true
333335
})))
334336
zone-3 = optional(list(object({
335337
name = string
336338
cidr = string
337339
public_gateway = optional(bool)
338340
acl_name = string
341+
no_addr_prefix = optional(bool, false) # do not automatically add address prefix for subnet, overrides other conditions if set to true
339342
})))
340343
})
341344

@@ -346,6 +349,7 @@ variable "subnets" {
346349
cidr = "10.10.10.0/24"
347350
public_gateway = true
348351
acl_name = "vpc-acl"
352+
no_addr_prefix = false
349353
}
350354
],
351355
zone-2 = [
@@ -354,6 +358,7 @@ variable "subnets" {
354358
cidr = "10.20.10.0/24"
355359
public_gateway = true
356360
acl_name = "vpc-acl"
361+
no_addr_prefix = false
357362
}
358363
],
359364
zone-3 = [
@@ -362,6 +367,7 @@ variable "subnets" {
362367
cidr = "10.30.10.0/24"
363368
public_gateway = false
364369
acl_name = "vpc-acl"
370+
no_addr_prefix = false
365371
}
366372
]
367373
}

0 commit comments

Comments
 (0)