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

Commit 947206f

Browse files
author
Andrew Trice
authored
added output that contains a list of workers (id and zone) (#50)
Signed-off-by: Andrew Trice <[email protected]>
1 parent 40ef16b commit 947206f

File tree

8 files changed

+137
-1
lines changed

8 files changed

+137
-1
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
.idea/
22
*.iml
3+
4+
*.tfstate*
5+
.terraform.lock*
6+
7+
.terraform
8+
test/stages/.terraform
9+
test/stages/module
10+
11+
test/existing-cluster/.terraform
12+
test/existing-cluster/module
13+
test/existing-cluster/.kube

main.tf

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ locals {
4848
cluster_type_tag = local.cluster_type == "kubernetes" ? "iks" : "ocp"
4949
cluster_version = local.cluster_type == "openshift" ? "${var.ocp_version}_openshift" : ""
5050
vpc_subnet_count = var.vpc_subnet_count
51+
total_workers = var.worker_count * var.vpc_subnet_count
5152
vpc_id = !var.exists ? data.ibm_is_vpc.vpc[0].id : ""
5253
vpc_subnets = !var.exists ? var.vpc_subnets : []
5354
security_group_id = !var.exists ? data.ibm_is_vpc.vpc[0].default_security_group : ""
@@ -76,6 +77,12 @@ locals {
7677
source = "0.0.0.0/0"
7778
destination = "0.0.0.0/0"
7879
}]
80+
workers = flatten([
81+
for i in range(local.total_workers) : {
82+
id = data.ibm_container_vpc_cluster_worker.workers[i].id
83+
zone = data.ibm_container_vpc_cluster_worker.workers[i].network_interfaces[0].subnet_id
84+
}
85+
])
7986
}
8087

8188
resource null_resource create_dirs {
@@ -269,7 +276,7 @@ resource ibm_is_security_group_rule rule_tcp_k8s {
269276
}
270277

271278
data ibm_container_vpc_cluster config {
272-
depends_on = [ibm_container_vpc_cluster.cluster, null_resource.create_dirs, ibm_is_security_group_rule.rule_tcp_k8s]
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]
273280

274281
name = local.cluster_name
275282
alb_type = var.disable_public_endpoint ? "private" : "public"
@@ -311,3 +318,13 @@ data ibm_container_cluster_config cluster {
311318
resource_group_id = data.ibm_resource_group.resource_group.id
312319
config_dir = local.cluster_config_dir
313320
}
321+
322+
data "ibm_container_vpc_cluster_worker" "workers" {
323+
depends_on = [
324+
data.ibm_container_vpc_cluster.config,
325+
ibm_container_vpc_worker_pool.cluster_pool
326+
]
327+
count = var.worker_count * var.vpc_subnet_count
328+
worker_id = data.ibm_container_vpc_cluster.config.workers[count.index]
329+
cluster_name_id = data.ibm_container_vpc_cluster.config.id
330+
}

outputs.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ output "sync" {
4747
description = "Value used to sync downstream modules"
4848
depends_on = [data.ibm_container_vpc_cluster.config]
4949
}
50+
51+
output "total_worker_count" {
52+
description = "The total number of workers for the cluster. (subnets * number of workers)"
53+
value = local.total_workers
54+
depends_on = [ibm_container_vpc_worker_pool.cluster_pool]
55+
}
56+
57+
output "workers" {
58+
description = "List of objects containing data for all workers "
59+
value = local.workers
60+
depends_on = [ibm_container_vpc_worker_pool.cluster_pool]
61+
}

test/existing-cluster/provider.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
provider "ibm" {
2+
region = var.region
3+
ibmcloud_api_key = var.ibmcloud_api_key
4+
}

test/existing-cluster/stage0.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
required_version = ">= 0.13.0"
3+
4+
required_providers {
5+
ibm = {
6+
source = "ibm-cloud/ibm"
7+
}
8+
}
9+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module "resource_group" {
2+
source = "github.com/cloud-native-toolkit/terraform-ibm-resource-group.git"
3+
4+
resource_group_name = var.resource_group_name
5+
provision = false
6+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module "cluster" {
2+
source = "./module"
3+
4+
resource_group_name = module.resource_group.name
5+
region = var.region
6+
ibmcloud_api_key = var.ibmcloud_api_key
7+
name = var.cluster_name
8+
worker_count = var.worker_count
9+
exists = var.cluster_exists
10+
name_prefix = var.name_prefix
11+
vpc_name = ""
12+
vpc_subnets = []
13+
vpc_subnet_count = var.vpc_subnet_count
14+
cos_id = ""
15+
}
16+
17+
18+
resource null_resource print_resources {
19+
triggers = {
20+
always_run = timestamp()
21+
}
22+
23+
provisioner "local-exec" {
24+
command = "echo 'Resource group: ${var.resource_group_name}'"
25+
}
26+
provisioner "local-exec" {
27+
command = "echo 'Total Workers: ${module.cluster.total_worker_count}'"
28+
}
29+
provisioner "local-exec" {
30+
command = "echo 'Workers: ${jsonencode(module.cluster.workers)}'"
31+
}
32+
}

test/existing-cluster/variables.tf

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
# Resource Group Variables
3+
variable "resource_group_name" {
4+
type = string
5+
description = "Existing resource group where the IKS cluster will be provisioned."
6+
}
7+
8+
variable "ibmcloud_api_key" {
9+
type = string
10+
description = "The api key for IBM Cloud access"
11+
}
12+
13+
variable "region" {
14+
type = string
15+
description = "Region for VLANs defined in private_vlan_number and public_vlan_number."
16+
}
17+
18+
variable "cluster_name" {
19+
type = string
20+
description = "The name of the cluster"
21+
default = ""
22+
}
23+
24+
variable "cluster_exists" {
25+
type = string
26+
description = "Flag indicating if the cluster already exists (true or false)"
27+
default = "true"
28+
}
29+
30+
variable "name_prefix" {
31+
type = string
32+
description = "Prefix name that should be used for the cluster and services. If not provided then resource_group_name will be used"
33+
default = ""
34+
}
35+
36+
variable "vpc_subnet_count" {
37+
type = number
38+
description = "The number of subnets to create for the VPC instance"
39+
default = 1
40+
}
41+
42+
variable "worker_count" {
43+
type = number
44+
default = 4
45+
}

0 commit comments

Comments
 (0)