Skip to content
This repository was archived by the owner on Aug 12, 2024. It is now read-only.

Commit fdb0e3a

Browse files
author
Sean Sundberg
authored
Reduces the workers to a single worker pool (#55)
* Reduces the workers to a single worker pool * Loads jq cli using submodule Signed-off-by: Sean Sundberg <[email protected]>
1 parent 448fd09 commit fdb0e3a

File tree

3 files changed

+20
-32
lines changed

3 files changed

+20
-32
lines changed

main.tf

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ resource null_resource print_cluster_versions {
151151
}
152152
}
153153

154+
module setup_clis {
155+
source = "github.com/cloud-native-toolkit/terraform-util-clis.git"
156+
157+
clis = ["jq"]
158+
}
159+
154160
data ibm_is_vpc vpc {
155161
count = !var.exists ? 1 : 0
156162
depends_on = [null_resource.print_resources]
@@ -173,6 +179,7 @@ resource null_resource setup_acl_rules {
173179
environment = {
174180
IBMCLOUD_API_KEY = var.ibmcloud_api_key
175181
ACL_RULES = jsonencode(local.acl_rules)
182+
BIN_DIR = module.setup_clis.bin_dir
176183
}
177184
}
178185
}
@@ -231,9 +238,13 @@ resource ibm_container_vpc_cluster cluster {
231238
disable_public_service_endpoint = var.disable_public_endpoint
232239
wait_till = "IngressReady"
233240

234-
zones {
235-
name = local.vpc_subnets[0].zone
236-
subnet_id = local.vpc_subnets[0].id
241+
dynamic "zones" {
242+
for_each = local.vpc_subnets
243+
244+
content {
245+
name = zones.value.zone
246+
subnet_id = zones.value.id
247+
}
237248
}
238249

239250
dynamic "kms_config" {
@@ -247,22 +258,6 @@ resource ibm_container_vpc_cluster cluster {
247258
}
248259
}
249260

250-
resource ibm_container_vpc_worker_pool cluster_pool {
251-
count = !var.exists ? local.vpc_subnet_count - 1 : 0
252-
253-
cluster = ibm_container_vpc_cluster.cluster[0].id
254-
worker_pool_name = "pool-${format("%02s", count.index + 2)}"
255-
flavor = var.flavor
256-
vpc_id = local.vpc_id
257-
worker_count = var.worker_count
258-
resource_group_id = data.ibm_resource_group.resource_group.id
259-
260-
zones {
261-
name = local.vpc_subnets[count.index + 1].zone
262-
subnet_id = local.vpc_subnets[count.index + 1].id
263-
}
264-
}
265-
266261
resource ibm_is_security_group_rule rule_tcp_k8s {
267262
count = !var.exists ? local.vpc_subnet_count : 0
268263

@@ -276,7 +271,7 @@ resource ibm_is_security_group_rule rule_tcp_k8s {
276271
}
277272

278273
data ibm_container_vpc_cluster config {
279-
depends_on = [ibm_container_vpc_cluster.cluster, null_resource.create_dirs, ibm_is_security_group_rule.rule_tcp_k8s, ibm_container_vpc_worker_pool.cluster_pool]
274+
depends_on = [ibm_container_vpc_cluster.cluster, null_resource.create_dirs, ibm_is_security_group_rule.rule_tcp_k8s]
280275

281276
name = local.cluster_name
282277
alb_type = var.disable_public_endpoint ? "private" : "public"
@@ -321,10 +316,9 @@ data ibm_container_cluster_config cluster {
321316

322317
data "ibm_container_vpc_cluster_worker" "workers" {
323318
depends_on = [
324-
data.ibm_container_vpc_cluster.config,
325-
ibm_container_vpc_worker_pool.cluster_pool
319+
data.ibm_container_vpc_cluster.config
326320
]
327321
count = var.worker_count * var.vpc_subnet_count
328322
worker_id = data.ibm_container_vpc_cluster.config.workers[count.index]
329323
cluster_name_id = data.ibm_container_vpc_cluster.config.id
330-
}
324+
}

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ output "sync" {
5151
output "total_worker_count" {
5252
description = "The total number of workers for the cluster. (subnets * number of workers)"
5353
value = local.total_workers
54-
depends_on = [ibm_container_vpc_worker_pool.cluster_pool]
54+
depends_on = [data.ibm_container_vpc_cluster_worker.workers]
5555
}
5656

5757
output "workers" {
5858
description = "List of objects containing data for all workers "
5959
value = local.workers
60-
depends_on = [ibm_container_vpc_worker_pool.cluster_pool]
60+
depends_on = [data.ibm_container_vpc_cluster_worker.workers]
6161
}

scripts/setup-acl-rules.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,7 @@ if ! ibmcloud account show 1> /dev/null 2> /dev/null; then
5050
fi
5151

5252
# Install jq if not available
53-
JQ=$(command -v jq || command -v ./bin/jq)
54-
55-
if [[ -z "${JQ}" ]]; then
56-
echo "jq missing. Installing"
57-
mkdir -p ./bin && curl -Lo ./bin/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
58-
JQ="${PWD}/bin/jq"
59-
fi
53+
JQ=$(command -v jq || command -v "${BIN_DIR}/jq")
6054

6155
## TODO more sophisticated logic needed to 1) test for existing rules and 2) place this rule in the right order
6256

0 commit comments

Comments
 (0)