Skip to content

Commit 208eb88

Browse files
authored
fix: add count to the data block so that it does not execute when var.verify_worker_network_readiness is set to false (#91)
1 parent a1eb359 commit 208eb88

File tree

5 files changed

+112
-16
lines changed

5 files changed

+112
-16
lines changed

examples/apply_taints/README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,82 @@
22

33
- This example provisions OCP cluster and set taints for worker pools.
44
- The example also enables a key protect provider for the cluster, as well as the required COS instance.
5+
- The OCP cluster created has a private endpoint.
6+
7+
## Private Cluster
8+
9+
## Usage
10+
```hcl
11+
# Replace "master" with a GIT release version to lock into a specific release
12+
module "ocp_base" {
13+
# update this value to the value of your IBM Cloud API key
14+
ibmcloud_api_key = "ibm cloud api key" # pragma: allowlist secret
15+
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-base-ocp-vpc.git?ref=master"
16+
cluster_name = "example-cluster-name"
17+
# modify the value for resource_group_id with and id of a group you own
18+
resource_group_id = "id of existing resource group"
19+
region = "us-south"
20+
force_delete_storage = true
21+
vpc_id = "id of existing VPC"
22+
## obtain the below values from the targeted VPC and adjust to the number of zones,
23+
## subnets, subnet name, cidr_block, id, zone
24+
vpc_subnets = {
25+
zone-1 = [
26+
{
27+
cidr_block = "192.168.32.0/22"
28+
id = "0717-afc29fbb-0dbe-493a-a5b9-f3c5899cb8b9"
29+
zone = "us-south-1"
30+
},
31+
{
32+
cidr_block = "192.168.36.0/22"
33+
id = "0727-d65c1eda-9e38-4200-8452-cb8ff5bb3140"
34+
zone = "us-south-2"
35+
},
36+
{
37+
cidr_block = "192.168.40.0/22"
38+
id = "0737-9a823cd3-16bf-4ba4-a429-9e1fc7db74b8"
39+
zone = "us-south-3"
40+
}
41+
]
42+
zone-2 = [
43+
{
44+
cidr_block = "192.168.0.0/22"
45+
id = "0717-846b9490-34ae-4a6c-8288-28112dca1ba3"
46+
zone = "us-south-1"
47+
},
48+
{
49+
cidr_block = "192.168.4.0/22"
50+
id = "0727-ef8db7f6-ffa5-4d8b-a317-4631741a45ee"
51+
zone = "us-south-2"
52+
},
53+
{
54+
cidr_block = "192.168.8.0/22"
55+
id = "0737-c9a6d871-d95b-4914-abf5-82c22f4161d1"
56+
zone = "us-south-3"
57+
}
58+
]
59+
zone-3 = [
60+
{
61+
cidr_block = "192.168.16.0/22"
62+
id = "0717-d46e227c-89d4-4b02-9008-d03907a275b6"
63+
zone = "us-south-1"
64+
},
65+
{
66+
cidr_block = "192.168.20.0/22"
67+
id = "0727-93b1edcb-966c-4517-a7af-6ac63cd93adf"
68+
zone = "us-south-2"
69+
},
70+
{
71+
cidr_block = "192.168.24.0/22"
72+
id = "0737-807ec4f1-4d84-484e-b2f4-62dd5e431065"
73+
zone = "us-south-3"
74+
}
75+
]
76+
}
77+
disable_public_endpoint = true
78+
## verify_worker_network_readiness should be set to false when runtime does not have access to the kube-api-server.
79+
## For example, if we are running terraform apply from a vsi server which is connected to the cluster vpc using a vpn or transit gateway that time verify_worker_network_readiness can be set to true.
80+
verify_worker_network_readiness = false
81+
}
82+
83+
```

examples/apply_taints/main.tf

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,20 @@ locals {
6262
}
6363

6464
module "ocp_base" {
65-
source = "../.."
66-
cluster_name = var.prefix
67-
ibmcloud_api_key = var.ibmcloud_api_key
68-
resource_group_id = module.resource_group.resource_group_id
69-
region = var.region
70-
force_delete_storage = true
71-
vpc_id = module.vpc.vpc_id
72-
vpc_subnets = local.cluster_vpc_subnets
73-
worker_pools = var.worker_pools
74-
worker_pools_taints = var.worker_pools_taints
75-
ocp_version = var.ocp_version
76-
tags = var.resource_tags
65+
source = "../.."
66+
cluster_name = var.prefix
67+
ibmcloud_api_key = var.ibmcloud_api_key
68+
resource_group_id = module.resource_group.resource_group_id
69+
region = var.region
70+
force_delete_storage = true
71+
vpc_id = module.vpc.vpc_id
72+
vpc_subnets = local.cluster_vpc_subnets
73+
worker_pools = var.worker_pools
74+
worker_pools_taints = var.worker_pools_taints
75+
ocp_version = var.ocp_version
76+
disable_public_endpoint = var.disable_public_endpoint
77+
verify_worker_network_readiness = var.verify_worker_network_readiness
78+
tags = var.resource_tags
7779
kms_config = {
7880
instance_id = module.kp_all_inclusive.key_protect_guid
7981
crk_id = module.kp_all_inclusive.keys["ocp.${var.prefix}-cluster-key"].key_id

examples/apply_taints/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,16 @@ variable "worker_pools_taints" {
185185
}
186186
}
187187

188+
variable "disable_public_endpoint" {
189+
type = bool
190+
description = "Flag indicating that the public endpoint should be enabled or disabled"
191+
default = true
192+
}
193+
194+
variable "verify_worker_network_readiness" {
195+
type = bool
196+
description = "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."
197+
default = false
198+
}
199+
188200
##############################################################################

main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ resource "null_resource" "reset_api_key" {
199199
##############################################################################
200200

201201
data "ibm_container_cluster_config" "cluster_config" {
202+
count = var.verify_worker_network_readiness ? 1 : 0
202203
cluster_name_id = local.cluster_id
203204
config_dir = "${path.module}/kubeconfig"
204205
resource_group_id = var.resource_group_id
@@ -319,7 +320,7 @@ resource "null_resource" "confirm_network_healthy" {
319320
command = "${path.module}/scripts/confirm_network_healthy.sh"
320321
interpreter = ["/bin/bash", "-c"]
321322
environment = {
322-
KUBECONFIG = data.ibm_container_cluster_config.cluster_config.config_file_path
323+
KUBECONFIG = data.ibm_container_cluster_config.cluster_config[0].config_file_path
323324
}
324325
}
325326
}

module-metadata.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@
207207
"description": "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.",
208208
"default": true,
209209
"source": [
210+
"data.ibm_container_cluster_config.cluster_config.count",
210211
"null_resource.confirm_network_healthy.count"
211212
],
212213
"pos": {
@@ -456,7 +457,7 @@
456457
},
457458
"pos": {
458459
"filename": "main.tf",
459-
"line": 252
460+
"line": 253
460461
}
461462
},
462463
"ibm_container_vpc_worker_pool.pool": {
@@ -472,7 +473,7 @@
472473
},
473474
"pos": {
474475
"filename": "main.tf",
475-
"line": 211
476+
"line": 212
476477
}
477478
},
478479
"ibm_resource_instance.cos_instance": {
@@ -503,7 +504,7 @@
503504
},
504505
"pos": {
505506
"filename": "main.tf",
506-
"line": 312
507+
"line": 313
507508
}
508509
},
509510
"null_resource.reset_api_key": {
@@ -525,6 +526,7 @@
525526
"type": "ibm_container_cluster_config",
526527
"name": "cluster_config",
527528
"attributes": {
529+
"count": "verify_worker_network_readiness",
528530
"resource_group_id": "resource_group_id"
529531
},
530532
"provider": {

0 commit comments

Comments
 (0)