Skip to content

Commit a9c06c2

Browse files
authored
feat: option to pass list of subnets or subnet prefix (#142)
* feat: option to pass list of subnets or subnet prefix * fix: update comment * fix: update the error message
1 parent 5019315 commit a9c06c2

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ No modules.
181181
| <a name="input_verify_worker_network_readiness"></a> [verify\_worker\_network\_readiness](#input\_verify\_worker\_network\_readiness) | By setting this to true, a script will run kubectl commands to verify that all worker nodes can communicate successfully with the master. If the runtime does not have access to the kube cluster to run kubectl commands, this should be set to false. | `bool` | `true` | no |
182182
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | Id of the VPC instance where this cluster will be provisioned | `string` | n/a | yes |
183183
| <a name="input_vpc_subnets"></a> [vpc\_subnets](#input\_vpc\_subnets) | Metadata that describes the VPC's subnets. Obtain this information from the VPC where this cluster will be created | <pre>map(list(object({<br> id = string<br> zone = string<br> cidr_block = string<br> })))</pre> | n/a | yes |
184-
| <a name="input_worker_pools"></a> [worker\_pools](#input\_worker\_pools) | List of worker pools | <pre>list(object({<br> subnet_prefix = string<br> pool_name = string<br> machine_type = string<br> workers_per_zone = number<br> resource_group_id = optional(string)<br> labels = optional(map(string))<br> boot_volume_encryption_kms_config = optional(object({<br> crk = string<br> kms_instance_id = string<br> kms_account_id = optional(string)<br> }))<br> }))</pre> | n/a | yes |
184+
| <a name="input_worker_pools"></a> [worker\_pools](#input\_worker\_pools) | List of worker pools | <pre>list(object({<br> subnet_prefix = optional(string)<br> vpc_subnets = optional(list(object({<br> id = string<br> zone = string<br> cidr_block = string<br> })))<br> pool_name = string<br> machine_type = string<br> workers_per_zone = number<br> resource_group_id = optional(string)<br> labels = optional(map(string))<br> boot_volume_encryption_kms_config = optional(object({<br> crk = string<br> kms_instance_id = string<br> kms_account_id = optional(string)<br> }))<br> }))</pre> | n/a | yes |
185185
| <a name="input_worker_pools_taints"></a> [worker\_pools\_taints](#input\_worker\_pools\_taints) | Optional, Map of lists containing node taints by node-pool name | `map(list(object({ key = string, value = string, effect = string })))` | `null` | no |
186186

187187
## Outputs

main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ resource "ibm_container_vpc_cluster" "cluster" {
8484

8585
# default workers are mapped to the subnets that are "private"
8686
dynamic "zones" {
87-
for_each = var.vpc_subnets[local.default_pool.subnet_prefix]
87+
for_each = local.default_pool.subnet_prefix != null ? var.vpc_subnets[local.default_pool.subnet_prefix] : local.default_pool.vpc_subnets
8888
content {
8989
subnet_id = zones.value.id
9090
name = zones.value.zone
@@ -145,7 +145,7 @@ resource "ibm_container_vpc_cluster" "autoscaling_cluster" {
145145

146146
# default workers are mapped to the subnets that are "private"
147147
dynamic "zones" {
148-
for_each = var.vpc_subnets[local.default_pool.subnet_prefix]
148+
for_each = local.default_pool.subnet_prefix != null ? var.vpc_subnets[local.default_pool.subnet_prefix] : local.default_pool.vpc_subnets
149149
content {
150150
subnet_id = zones.value.id
151151
name = zones.value.zone
@@ -244,7 +244,7 @@ resource "ibm_container_vpc_worker_pool" "pool" {
244244
kms_account_id = each.value.boot_volume_encryption_kms_config == null ? null : each.value.boot_volume_encryption_kms_config.kms_account_id
245245

246246
dynamic "zones" {
247-
for_each = var.vpc_subnets[each.value.subnet_prefix]
247+
for_each = each.value.subnet_prefix != null ? var.vpc_subnets[each.value.subnet_prefix] : each.value.vpc_subnets
248248
content {
249249
subnet_id = zones.value.id
250250
name = zones.value.zone
@@ -289,7 +289,7 @@ resource "ibm_container_vpc_worker_pool" "autoscaling_pool" {
289289
}
290290

291291
dynamic "zones" {
292-
for_each = var.vpc_subnets[each.value.subnet_prefix]
292+
for_each = each.value.subnet_prefix != null ? var.vpc_subnets[each.value.subnet_prefix] : each.value.vpc_subnets
293293
content {
294294
subnet_id = zones.value.id
295295
name = zones.value.zone

module-metadata.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"pos": {
1515
"filename": "variables.tf",
16-
"line": 148
16+
"line": 157
1717
},
1818
"min_length": 1,
1919
"max_length": 128,
@@ -49,7 +49,7 @@
4949
],
5050
"pos": {
5151
"filename": "variables.tf",
52-
"line": 90
52+
"line": 99
5353
}
5454
},
5555
"cos_name": {
@@ -58,7 +58,7 @@
5858
"description": "Name of the COS instance to provision. New instance only provisioned if `use_existing_cos = false`. Default: `\u003ccluster_name\u003e_cos`",
5959
"pos": {
6060
"filename": "variables.tf",
61-
"line": 120
61+
"line": 129
6262
}
6363
},
6464
"disable_public_endpoint": {
@@ -72,7 +72,7 @@
7272
],
7373
"pos": {
7474
"filename": "variables.tf",
75-
"line": 102
75+
"line": 111
7676
}
7777
},
7878
"existing_cos_id": {
@@ -81,7 +81,7 @@
8181
"description": "The COS id of an already existing COS instance. Only required if 'use_existing_cos = true'",
8282
"pos": {
8383
"filename": "variables.tf",
84-
"line": 132
84+
"line": 141
8585
}
8686
},
8787
"force_delete_storage": {
@@ -95,7 +95,7 @@
9595
],
9696
"pos": {
9797
"filename": "variables.tf",
98-
"line": 114
98+
"line": 123
9999
}
100100
},
101101
"ibmcloud_api_key": {
@@ -122,7 +122,7 @@
122122
],
123123
"pos": {
124124
"filename": "variables.tf",
125-
"line": 66
125+
"line": 75
126126
},
127127
"min_length": 1,
128128
"max_length": 1024,
@@ -134,7 +134,7 @@
134134
"description": "Use to attach a Key Protect instance to the cluster",
135135
"pos": {
136136
"filename": "variables.tf",
137-
"line": 138
137+
"line": 147
138138
}
139139
},
140140
"ocp_entitlement": {
@@ -148,7 +148,7 @@
148148
],
149149
"pos": {
150150
"filename": "variables.tf",
151-
"line": 108
151+
"line": 117
152152
}
153153
},
154154
"ocp_version": {
@@ -157,7 +157,7 @@
157157
"description": "The version of the OpenShift cluster that should be provisioned (format 4.x). This is only used during initial cluster provisioning, but ignored for future updates. If no value is passed, or the string 'latest' is passed, the current latest OCP version will be used.",
158158
"pos": {
159159
"filename": "variables.tf",
160-
"line": 72
160+
"line": 81
161161
}
162162
},
163163
"region": {
@@ -232,7 +232,7 @@
232232
],
233233
"pos": {
234234
"filename": "variables.tf",
235-
"line": 126
235+
"line": 135
236236
}
237237
},
238238
"verify_worker_network_readiness": {
@@ -246,7 +246,7 @@
246246
],
247247
"pos": {
248248
"filename": "variables.tf",
249-
"line": 167
249+
"line": 176
250250
}
251251
},
252252
"vpc_id": {
@@ -262,7 +262,7 @@
262262
],
263263
"pos": {
264264
"filename": "variables.tf",
265-
"line": 162
265+
"line": 171
266266
},
267267
"immutable": true
268268
},
@@ -278,7 +278,7 @@
278278
},
279279
"worker_pools": {
280280
"name": "worker_pools",
281-
"type": "list(object({\n subnet_prefix = string\n pool_name = string\n machine_type = string\n workers_per_zone = number\n resource_group_id = optional(string)\n labels = optional(map(string))\n boot_volume_encryption_kms_config = optional(object({\n crk = string\n kms_instance_id = string\n kms_account_id = optional(string)\n }))\n }))",
281+
"type": "list(object({\n subnet_prefix = optional(string)\n vpc_subnets = optional(list(object({\n id = string\n zone = string\n cidr_block = string\n })))\n pool_name = string\n machine_type = string\n workers_per_zone = number\n resource_group_id = optional(string)\n labels = optional(map(string))\n boot_volume_encryption_kms_config = optional(object({\n crk = string\n kms_instance_id = string\n kms_account_id = optional(string)\n }))\n }))",
282282
"description": "List of worker pools",
283283
"required": true,
284284
"pos": {
@@ -292,7 +292,7 @@
292292
"description": "Optional, Map of lists containing node taints by node-pool name",
293293
"pos": {
294294
"filename": "variables.tf",
295-
"line": 60
295+
"line": 69
296296
}
297297
}
298298
},

variables.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ variable "vpc_subnets" {
4242

4343
variable "worker_pools" {
4444
type = list(object({
45-
subnet_prefix = string
45+
subnet_prefix = optional(string)
46+
vpc_subnets = optional(list(object({
47+
id = string
48+
zone = string
49+
cidr_block = string
50+
})))
4651
pool_name = string
4752
machine_type = string
4853
workers_per_zone = number
@@ -55,6 +60,10 @@ variable "worker_pools" {
5560
}))
5661
}))
5762
description = "List of worker pools"
63+
validation {
64+
condition = length([for worker_pool in var.worker_pools : worker_pool if(worker_pool.subnet_prefix == null && worker_pool.vpc_subnets == null) || (worker_pool.subnet_prefix != null && worker_pool.vpc_subnets != null)]) == 0
65+
error_message = "Please provide exactly one of subnet_prefix or vpc_subnets. Passing neither or both is invalid."
66+
}
5867
}
5968

6069
variable "worker_pools_taints" {

0 commit comments

Comments
 (0)