Skip to content

Commit 2de5c04

Browse files
authored
feat: worker pool taints are now optional and have no value by default (#42)
1 parent 23ca7de commit 2de5c04

File tree

19 files changed

+713
-237
lines changed

19 files changed

+713
-237
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ You need the following permissions to run this module.
115115
<!-- BEGIN EXAMPLES HOOK -->
116116
## Examples
117117

118+
- [ Apply Taints Example](examples/apply_taints)
118119
- [ Existing COS](examples/existing_cos)
119120
- [ 2 MZR clusters in same VPC](examples/multiple_mzr_clusters)
120121
- [ Single Zone Cluster](examples/single_zone_cluster)
@@ -169,8 +170,8 @@ No modules.
169170
| <a name="input_use_existing_cos"></a> [use\_existing\_cos](#input\_use\_existing\_cos) | Flag indicating whether or not to use an existing COS instance | `bool` | `false` | no |
170171
| <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 |
171172
| <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 |
172-
| <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> }))</pre> | <pre>[<br> {<br> "labels": {},<br> "machine_type": "bx2.4x16",<br> "pool_name": "default",<br> "subnet_prefix": "zone-1",<br> "workers_per_zone": 2<br> },<br> {<br> "labels": {<br> "dedicated": "zone-2"<br> },<br> "machine_type": "bx2.4x16",<br> "pool_name": "zone-2",<br> "subnet_prefix": "zone-2",<br> "workers_per_zone": 2<br> },<br> {<br> "labels": {<br> "dedicated": "zone-3"<br> },<br> "machine_type": "bx2.4x16",<br> "pool_name": "zone-3",<br> "subnet_prefix": "zone-3",<br> "workers_per_zone": 2<br> }<br>]</pre> | no |
173-
| <a name="input_worker_pools_taints"></a> [worker\_pools\_taints](#input\_worker\_pools\_taints) | Map of lists containing node taints by node-pool name | `map(list(object({ key = string, value = string, effect = string })))` | <pre>{<br> "all": [],<br> "default": [],<br> "zone-2": [<br> {<br> "effect": "NoExecute",<br> "key": "dedicated",<br> "value": "zone-2"<br> }<br> ],<br> "zone-3": [<br> {<br> "effect": "NoExecute",<br> "key": "dedicated",<br> "value": "zone-3"<br> }<br> ]<br>}</pre> | no |
173+
| <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> }))</pre> | <pre>[<br> {<br> "machine_type": "bx2.4x16",<br> "pool_name": "default",<br> "subnet_prefix": "zone-1",<br> "workers_per_zone": 2<br> },<br> {<br> "machine_type": "bx2.4x16",<br> "pool_name": "zone-2",<br> "subnet_prefix": "zone-2",<br> "workers_per_zone": 2<br> },<br> {<br> "machine_type": "bx2.4x16",<br> "pool_name": "zone-3",<br> "subnet_prefix": "zone-3",<br> "workers_per_zone": 2<br> }<br>]</pre> | no |
174+
| <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 |
174175

175176
## Outputs
176177

examples/apply_taints/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Apply Taints Example
2+
3+
- This example provisions OCP cluster and set taints for worker pools.
4+
- The example also enables a key protect provider for the cluster, as well as the required COS instance.

examples/apply_taints/main.tf

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
##############################################################################
2+
# Provision an OCP cluster with one extra worker pool inside a VPC
3+
##############################################################################
4+
5+
module "resource_group" {
6+
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-resource-group.git?ref=v1.0.5"
7+
# if an existing resource group is not set (null) create a new one using prefix
8+
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null
9+
existing_resource_group_name = var.resource_group
10+
}
11+
12+
###############################################################################
13+
# VPC
14+
###############################################################################
15+
16+
module "vpc" {
17+
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-landing-zone-vpc.git?ref=v4.0.0"
18+
resource_group_id = module.resource_group.resource_group_id
19+
region = var.region
20+
prefix = var.prefix
21+
tags = var.resource_tags
22+
name = var.vpc_name
23+
address_prefixes = var.addresses
24+
subnets = var.subnets
25+
use_public_gateways = var.public_gateway
26+
}
27+
28+
##############################################################################
29+
# Key Protect
30+
##############################################################################
31+
32+
module "kp_all_inclusive" {
33+
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-key-protect-all-inclusive.git?ref=v4.0.0"
34+
key_protect_instance_name = "${var.prefix}-kp-instance"
35+
resource_group_id = module.resource_group.resource_group_id
36+
region = var.region
37+
resource_tags = var.resource_tags
38+
key_map = { "ocp" = ["${var.prefix}-cluster-key"] }
39+
}
40+
41+
##############################################################################
42+
# Base OCP Cluster
43+
##############################################################################
44+
locals {
45+
cluster_vpc_subnets = {
46+
zone-1 = [{
47+
id = module.vpc.subnet_zone_list[0].id
48+
zone = module.vpc.subnet_zone_list[0].zone
49+
cidr_block = module.vpc.subnet_zone_list[0].cidr
50+
}],
51+
zone-2 = [{
52+
id = module.vpc.subnet_zone_list[1].id
53+
zone = module.vpc.subnet_zone_list[1].zone
54+
cidr_block = module.vpc.subnet_zone_list[1].cidr
55+
}],
56+
zone-3 = [{
57+
id = module.vpc.subnet_zone_list[2].id
58+
zone = module.vpc.subnet_zone_list[2].zone
59+
cidr_block = module.vpc.subnet_zone_list[2].cidr
60+
}]
61+
}
62+
}
63+
64+
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
77+
kms_config = {
78+
instance_id = module.kp_all_inclusive.key_protect_guid
79+
crk_id = module.kp_all_inclusive.keys["ocp.${var.prefix}-cluster-key"].key_id
80+
}
81+
}
82+
83+
##############################################################################

examples/apply_taints/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
##############################################################################
2+
# Outputs
3+
##############################################################################
4+
5+
output "cluster_name" {
6+
value = module.ocp_base.cluster_name
7+
description = "The name of the provisioned cluster."
8+
}
9+
10+
##############################################################################

examples/apply_taints/provider.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
##############################################################################
2+
# Terraform providers
3+
##############################################################################
4+
5+
provider "ibm" {
6+
ibmcloud_api_key = var.ibmcloud_api_key
7+
region = var.region
8+
}
9+
10+
##############################################################################

examples/apply_taints/variables.tf

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
##############################################################################
2+
# Input Variables
3+
##############################################################################
4+
5+
variable "ibmcloud_api_key" {
6+
type = string
7+
description = "The IBM Cloud api token"
8+
sensitive = true
9+
}
10+
11+
variable "prefix" {
12+
type = string
13+
description = "Prefix for name of all resource created by this example"
14+
default = "base-ocp-std"
15+
validation {
16+
error_message = "Prefix must begin and end with a letter and contain only letters, numbers, and - characters."
17+
condition = can(regex("^([A-z]|[a-z][-a-z0-9]*[a-z0-9])$", var.prefix))
18+
}
19+
}
20+
21+
variable "region" {
22+
type = string
23+
description = "Region where resources are created"
24+
default = "eu-gb"
25+
}
26+
27+
variable "resource_group" {
28+
type = string
29+
description = "An existing resource group name to use for this example, if unset a new resource group will be created"
30+
default = null
31+
}
32+
33+
variable "resource_tags" {
34+
type = list(string)
35+
description = "Optional list of tags to be added to created resources"
36+
default = []
37+
}
38+
39+
variable "ocp_version" {
40+
type = string
41+
description = "Version of the OCP cluster to provision"
42+
default = null
43+
}
44+
45+
##############################################################################
46+
# VPC variables
47+
##############################################################################
48+
49+
variable "vpc_name" {
50+
type = string
51+
description = "Name of the VPC"
52+
default = "management"
53+
}
54+
55+
variable "public_gateway" {
56+
description = "Create a public gateway in any of the three zones with `true`."
57+
type = object({
58+
zone-1 = optional(bool)
59+
zone-2 = optional(bool)
60+
zone-3 = optional(bool)
61+
})
62+
default = {
63+
zone-1 = true
64+
zone-2 = false
65+
zone-3 = false
66+
}
67+
}
68+
69+
variable "addresses" {
70+
description = "OPTIONAL - IP range that will be defined for the VPC for a certain location. Use only with manual address prefixes"
71+
type = object({
72+
zone-1 = optional(list(string))
73+
zone-2 = optional(list(string))
74+
zone-3 = optional(list(string))
75+
})
76+
default = {
77+
zone-1 = ["10.10.10.0/24"]
78+
zone-2 = ["10.20.10.0/24"]
79+
zone-3 = ["10.30.10.0/24"]
80+
}
81+
}
82+
83+
variable "subnets" {
84+
description = "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"
85+
type = object({
86+
zone-1 = list(object({
87+
acl_name = string
88+
name = string
89+
cidr = string
90+
public_gateway = optional(bool)
91+
}))
92+
zone-2 = list(object({
93+
acl_name = string
94+
name = string
95+
cidr = string
96+
public_gateway = optional(bool)
97+
}))
98+
zone-3 = list(object({
99+
acl_name = string
100+
name = string
101+
cidr = string
102+
public_gateway = optional(bool)
103+
}))
104+
})
105+
106+
default = {
107+
zone-1 = [
108+
{
109+
acl_name = "vpc-acl"
110+
name = "zone-1"
111+
cidr = "10.10.10.0/24"
112+
}
113+
],
114+
zone-2 = [
115+
{
116+
acl_name = "vpc-acl"
117+
name = "zone-2"
118+
cidr = "10.20.10.0/24"
119+
}
120+
],
121+
zone-3 = [
122+
{
123+
acl_name = "vpc-acl"
124+
name = "zone-3"
125+
cidr = "10.30.10.0/24"
126+
}
127+
]
128+
}
129+
}
130+
131+
variable "worker_pools" {
132+
type = list(object({
133+
subnet_prefix = string
134+
pool_name = string
135+
machine_type = string
136+
workers_per_zone = number
137+
resource_group_id = optional(string)
138+
labels = optional(map(string))
139+
}))
140+
description = "List of worker pools."
141+
default = [
142+
{
143+
subnet_prefix = "zone-1"
144+
pool_name = "default" # ibm_container_vpc_cluster automatically names standard pool "standard" (See https://github.com/IBM-Cloud/terraform-provider-ibm/issues/2849)
145+
machine_type = "bx2.4x16"
146+
workers_per_zone = 2
147+
},
148+
{
149+
subnet_prefix = "zone-2"
150+
pool_name = "zone-2"
151+
machine_type = "bx2.4x16"
152+
workers_per_zone = 2
153+
},
154+
{
155+
subnet_prefix = "zone-3"
156+
pool_name = "zone-3"
157+
machine_type = "bx2.4x16"
158+
workers_per_zone = 2
159+
}
160+
]
161+
}
162+
163+
variable "worker_pools_taints" {
164+
type = map(list(object({ key = string, value = string, effect = string })))
165+
description = "Map of lists containing node taints by node-pool name"
166+
167+
default = {
168+
all = []
169+
default = []
170+
zone-2 = [{
171+
key = "dedicated"
172+
value = "zone-2"
173+
effect = "NoExecute"
174+
}]
175+
zone-3 = [{
176+
key = "dedicated"
177+
value = "zone-3"
178+
effect = "NoExecute"
179+
}]
180+
}
181+
}
182+
183+
##############################################################################

examples/apply_taints/version.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
terraform {
2+
required_version = ">=1.3.0"
3+
required_providers {
4+
# Pin to the lowest provider version of the range defined in the main module to ensure lowest version still works
5+
ibm = {
6+
source = "ibm-cloud/ibm"
7+
version = "1.49.0"
8+
}
9+
}
10+
}
11+
12+
##############################################################################

0 commit comments

Comments
 (0)