|
| 1 | + |
| 2 | +# OpenShift Variables |
| 3 | +############################################################################## |
| 4 | + |
| 5 | +variable "openshift_cluster_name" { |
| 6 | + description = "Name of the cluster" |
| 7 | + type = string |
| 8 | + default = "roks" |
| 9 | +} |
| 10 | + |
| 11 | +variable "openshift_version" { |
| 12 | + description = "The OpenShift version that you want to set up in your cluster." |
| 13 | + type = string |
| 14 | + default = "" |
| 15 | +} |
| 16 | + |
| 17 | +variable "openshift_os" { |
| 18 | + description = "The Operating System (REDHAT_8_64 or RHCOS) for the Worker Nodes." |
| 19 | + type = string |
| 20 | + default = "RHCOS" |
| 21 | +} |
| 22 | + |
| 23 | +variable "openshift_machine_flavor" { |
| 24 | + description = " The default flavor of the OpenShift worker node." |
| 25 | + type = string |
| 26 | + default = "bx2.4x16" |
| 27 | +} |
| 28 | + |
| 29 | +variable "openshift_worker_nodes_per_zone" { |
| 30 | + description = "The number of worker nodes per zone in the default worker pool." |
| 31 | + type = number |
| 32 | + default = 1 |
| 33 | +} |
| 34 | + |
| 35 | +variable "worker_labels" { |
| 36 | + description = "Labels on all the workers in the default worker pool." |
| 37 | + type = map(any) |
| 38 | + default = null |
| 39 | +} |
| 40 | + |
| 41 | +variable "openshift_wait_till" { |
| 42 | + description = "specify the stage when Terraform to mark the cluster creation as completed." |
| 43 | + type = string |
| 44 | + default = "OneWorkerNodeReady" |
| 45 | + |
| 46 | + validation { |
| 47 | + error_message = "`openshift_wait_till` value must be one of `MasterNodeReady`, `OneWorkerNodeReady`, or `IngressReady`." |
| 48 | + condition = contains([ |
| 49 | + "MasterNodeReady", |
| 50 | + "OneWorkerNodeReady", |
| 51 | + "IngressReady" |
| 52 | + ], var.openshift_wait_till) |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +variable "openshift_disable_outbound_traffic_protection" { |
| 57 | + description = "Include this option to allow public outbound access from the cluster workers." |
| 58 | + type = bool |
| 59 | + default = true |
| 60 | +} |
| 61 | + |
| 62 | +variable "openshift_disable_public_service_endpoint" { |
| 63 | + description = "Boolean value true if Public service endpoint to be disabled." |
| 64 | + type = bool |
| 65 | + default = false |
| 66 | +} |
| 67 | + |
| 68 | +variable "openshift_force_delete_storage" { |
| 69 | + description = "force the removal of persistent storage associated with the cluster during cluster deletion." |
| 70 | + type = bool |
| 71 | + default = true |
| 72 | +} |
| 73 | + |
| 74 | +variable "kms_config" { |
| 75 | + type = list(map(string)) |
| 76 | + default = [] |
| 77 | +} |
| 78 | + |
| 79 | +variable "entitlement" { |
| 80 | + description = "Enable openshift entitlement during cluster creation ." |
| 81 | + type = string |
| 82 | + default = "cloud_pak" |
| 83 | +} |
| 84 | + |
| 85 | +variable "openshift_update_all_workers" { |
| 86 | + description = "OpenShift version of the worker nodes is updated." |
| 87 | + type = bool |
| 88 | + default = true |
| 89 | +} |
| 90 | + |
| 91 | +variable "is_openshift_cluster" { |
| 92 | + type = bool |
| 93 | + default = true |
| 94 | +} |
| 95 | + |
| 96 | +variable "roks_worker_pools" { |
| 97 | + description = "List of maps describing worker pools" |
| 98 | + |
| 99 | + type = list(object({ |
| 100 | + pool_name = string |
| 101 | + machine_type = string |
| 102 | + workers_per_zone = number |
| 103 | + })) |
| 104 | + |
| 105 | + default = [ |
| 106 | + { |
| 107 | + pool_name = "dev" |
| 108 | + machine_type = "bx2.4x16" |
| 109 | + workers_per_zone = 1 |
| 110 | + } |
| 111 | + ] |
| 112 | + |
| 113 | + validation { |
| 114 | + error_message = "Worker pool names must match the regex `^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$`." |
| 115 | + condition = length([ |
| 116 | + for pool in var.roks_worker_pools : |
| 117 | + false if !can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", pool.pool_name)) |
| 118 | + ]) == 0 |
| 119 | + } |
| 120 | + |
| 121 | + validation { |
| 122 | + error_message = "Worker pools cannot have duplicate names." |
| 123 | + condition = length(distinct([ |
| 124 | + for pool in var.roks_worker_pools : |
| 125 | + pool.pool_name |
| 126 | + ])) == length(var.roks_worker_pools) |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +## Resources |
| 131 | +############################################################################## |
| 132 | +resource "ibm_container_vpc_cluster" "roks_cluster" { |
| 133 | + name = format("%s-%s", local.basename, var.openshift_cluster_name) |
| 134 | + vpc_id = ibm_is_vpc.vpc.id |
| 135 | + resource_group_id = local.resource_group_id |
| 136 | + # Optional: Specify OpenShift version. If not included, 4.15 is used |
| 137 | + kube_version = var.openshift_version == "" ? "4.15_openshift" : var.openshift_version |
| 138 | + operating_system = var.openshift_os |
| 139 | + cos_instance_crn = var.is_openshift_cluster ? ibm_resource_instance.cos_openshift_registry[0].id : null |
| 140 | + entitlement = var.entitlement |
| 141 | + force_delete_storage = var.openshift_force_delete_storage |
| 142 | + tags = var.tags |
| 143 | + update_all_workers = var.openshift_update_all_workers |
| 144 | + |
| 145 | + flavor = var.openshift_machine_flavor |
| 146 | + worker_count = var.openshift_worker_nodes_per_zone |
| 147 | + wait_till = var.openshift_wait_till |
| 148 | + disable_public_service_endpoint = var.openshift_disable_public_service_endpoint |
| 149 | + # By default, public outbound access is blocked in OpenShift versions 4.15 |
| 150 | + disable_outbound_traffic_protection = var.openshift_disable_outbound_traffic_protection |
| 151 | + |
| 152 | + dynamic "zones" { |
| 153 | + for_each = { for subnet in ibm_is_subnet.subnet : subnet.id => subnet } |
| 154 | + content { |
| 155 | + name = zones.value.zone |
| 156 | + subnet_id = zones.value.id |
| 157 | + } |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +# Object Storage to backup the OpenShift Internal Registry |
| 162 | +############################################################################## |
| 163 | +resource "ibm_resource_instance" "cos_openshift_registry" { |
| 164 | + count = var.is_openshift_cluster ? 1 : 0 |
| 165 | + name = join("-", [local.basename, "cos-registry"]) |
| 166 | + resource_group_id = local.resource_group_id |
| 167 | + service = "cloud-object-storage" |
| 168 | + plan = "standard" |
| 169 | + location = "global" |
| 170 | + tags = var.tags |
| 171 | +} |
0 commit comments