Skip to content

Commit c7d443d

Browse files
feat: added cluster addon support to the OCP DA and module. It can be configured using the cluster_addons and manage_all_cluster_addons variables (#733)
1 parent 0b17edb commit c7d443d

File tree

7 files changed

+119
-1
lines changed

7 files changed

+119
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,7 @@ module "cluster_pattern" {
866866
| [ibm_appid_redirect_urls.urls](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/appid_redirect_urls) | resource |
867867
| [ibm_atracker_route.atracker_route](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/atracker_route) | resource |
868868
| [ibm_atracker_target.atracker_target](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/atracker_target) | resource |
869+
| [ibm_container_addons.addons](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/container_addons) | resource |
869870
| [ibm_container_vpc_cluster.cluster](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/container_vpc_cluster) | resource |
870871
| [ibm_container_vpc_worker_pool.pool](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/container_vpc_worker_pool) | resource |
871872
| [ibm_cos_bucket.buckets](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/cos_bucket) | resource |
@@ -890,6 +891,7 @@ module "cluster_pattern" {
890891
| [random_string.random_cos_suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
891892
| [time_sleep.wait_30_seconds](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
892893
| [time_sleep.wait_for_authorization_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
894+
| [ibm_container_addons.existing_addons](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/container_addons) | data source |
893895
| [ibm_container_cluster_versions.cluster_versions](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/container_cluster_versions) | data source |
894896
| [ibm_iam_account_settings.iam_account_settings](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/iam_account_settings) | data source |
895897
| [ibm_is_image.image](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/is_image) | data source |
@@ -903,7 +905,7 @@ module "cluster_pattern" {
903905
|------|-------------|------|---------|:--------:|
904906
| <a name="input_appid"></a> [appid](#input\_appid) | The App ID instance to be used for the teleport vsi deployments | <pre>object({<br> name = optional(string)<br> resource_group = optional(string)<br> use_data = optional(bool)<br> keys = optional(list(string))<br> use_appid = bool<br> })</pre> | <pre>{<br> "use_appid": false<br>}</pre> | no |
905907
| <a name="input_atracker"></a> [atracker](#input\_atracker) | atracker variables | <pre>object({<br> resource_group = string<br> receive_global_events = bool<br> collector_bucket_name = string<br> add_route = bool<br> })</pre> | n/a | yes |
906-
| <a name="input_clusters"></a> [clusters](#input\_clusters) | A list describing clusters workloads to create | <pre>list(<br> object({<br> name = string # Name of Cluster<br> vpc_name = string # Name of VPC<br> subnet_names = list(string) # List of vpc subnets for cluster<br> workers_per_subnet = number # Worker nodes per subnet.<br> machine_type = string # Worker node flavor<br> kube_type = string # iks or openshift<br> kube_version = optional(string) # Can be a version from `ibmcloud ks versions` or `default`<br> entitlement = optional(string) # entitlement option for openshift<br> secondary_storage = optional(string) # Secondary storage type<br> pod_subnet = optional(string) # Portable subnet for pods<br> service_subnet = optional(string) # Portable subnet for services<br> resource_group = string # Resource Group used for cluster<br> cos_name = optional(string) # Name of COS instance Required only for OpenShift clusters<br> access_tags = optional(list(string), [])<br> boot_volume_crk_name = optional(string) # Boot volume encryption key name<br> disable_public_endpoint = optional(bool, true) # disable cluster public, leaving only private endpoint<br> kms_config = optional(<br> object({<br> crk_name = string # Name of key<br> private_endpoint = optional(bool) # Private endpoint<br> })<br> )<br> worker_pools = optional(<br> list(<br> object({<br> name = string # Worker pool name<br> vpc_name = string # VPC name<br> workers_per_subnet = number # Worker nodes per subnet<br> flavor = string # Worker node flavor<br> subnet_names = list(string) # List of vpc subnets for worker pool<br> entitlement = optional(string) # entitlement option for openshift<br> secondary_storage = optional(string) # Secondary storage type<br> boot_volume_crk_name = optional(string) # Boot volume encryption key name<br> })<br> )<br> )<br> })<br> )</pre> | n/a | yes |
908+
| <a name="input_clusters"></a> [clusters](#input\_clusters) | A list describing clusters workloads to create | <pre>list(<br> object({<br> name = string # Name of Cluster<br> vpc_name = string # Name of VPC<br> subnet_names = list(string) # List of vpc subnets for cluster<br> workers_per_subnet = number # Worker nodes per subnet.<br> machine_type = string # Worker node flavor<br> kube_type = string # iks or openshift<br> kube_version = optional(string) # Can be a version from `ibmcloud ks versions` or `default`<br> entitlement = optional(string) # entitlement option for openshift<br> secondary_storage = optional(string) # Secondary storage type<br> pod_subnet = optional(string) # Portable subnet for pods<br> service_subnet = optional(string) # Portable subnet for services<br> resource_group = string # Resource Group used for cluster<br> cos_name = optional(string) # Name of COS instance Required only for OpenShift clusters<br> access_tags = optional(list(string), [])<br> boot_volume_crk_name = optional(string) # Boot volume encryption key name<br> disable_public_endpoint = optional(bool, true) # disable cluster public, leaving only private endpoint<br> addons = optional(object({ # Map of OCP cluster add-on versions to install<br> debug-tool = optional(string)<br> image-key-synchronizer = optional(string)<br> openshift-data-foundation = optional(string)<br> vpc-file-csi-driver = optional(string)<br> static-route = optional(string)<br> cluster-autoscaler = optional(string)<br> vpc-block-csi-driver = optional(string)<br> }), {})<br> manage_all_addons = optional(bool, false) # Instructs Terraform to manage all cluster addons, even if addons were installed outside of the module. If set to 'true' this module will destroy any addons that were installed by other sources.<br> kms_config = optional(<br> object({<br> crk_name = string # Name of key<br> private_endpoint = optional(bool) # Private endpoint<br> })<br> )<br> worker_pools = optional(<br> list(<br> object({<br> name = string # Worker pool name<br> vpc_name = string # VPC name<br> workers_per_subnet = number # Worker nodes per subnet<br> flavor = string # Worker node flavor<br> subnet_names = list(string) # List of vpc subnets for worker pool<br> entitlement = optional(string) # entitlement option for openshift<br> secondary_storage = optional(string) # Secondary storage type<br> boot_volume_crk_name = optional(string) # Boot volume encryption key name<br> })<br> )<br> )<br> })<br> )</pre> | n/a | yes |
907909
| <a name="input_cos"></a> [cos](#input\_cos) | Object describing the cloud object storage instance, buckets, and keys. Set `use_data` to false to create instance | <pre>list(<br> object({<br> name = string<br> use_data = optional(bool)<br> resource_group = string<br> plan = optional(string)<br> random_suffix = optional(bool) # Use a random suffix for COS instance<br> access_tags = optional(list(string), [])<br> buckets = list(object({<br> name = string<br> storage_class = string<br> endpoint_type = string<br> force_delete = bool<br> single_site_location = optional(string)<br> region_location = optional(string)<br> cross_region_location = optional(string)<br> kms_key = optional(string)<br> access_tags = optional(list(string), [])<br> allowed_ip = optional(list(string))<br> hard_quota = optional(number)<br> archive_rule = optional(object({<br> days = number<br> enable = bool<br> rule_id = optional(string)<br> type = string<br> }))<br> expire_rule = optional(object({<br> days = optional(number)<br> date = optional(string)<br> enable = bool<br> expired_object_delete_marker = optional(string)<br> prefix = optional(string)<br> rule_id = optional(string)<br> }))<br> activity_tracking = optional(object({<br> activity_tracker_crn = string<br> read_data_events = bool<br> write_data_events = bool<br> }))<br> metrics_monitoring = optional(object({<br> metrics_monitoring_crn = string<br> request_metrics_enabled = optional(bool)<br> usage_metrics_enabled = optional(bool)<br> }))<br> }))<br> keys = optional(<br> list(object({<br> name = string<br> role = string<br> enable_HMAC = bool<br> }))<br> )<br><br> })<br> )</pre> | n/a | yes |
908910
| <a name="input_enable_transit_gateway"></a> [enable\_transit\_gateway](#input\_enable\_transit\_gateway) | Create transit gateway | `bool` | `true` | no |
909911
| <a name="input_f5_template_data"></a> [f5\_template\_data](#input\_f5\_template\_data) | Data for all f5 templates | <pre>object({<br> tmos_admin_password = optional(string)<br> license_type = optional(string)<br> byol_license_basekey = optional(string)<br> license_host = optional(string)<br> license_username = optional(string)<br> license_password = optional(string)<br> license_pool = optional(string)<br> license_sku_keyword_1 = optional(string)<br> license_sku_keyword_2 = optional(string)<br> license_unit_of_measure = optional(string)<br> do_declaration_url = optional(string)<br> as3_declaration_url = optional(string)<br> ts_declaration_url = optional(string)<br> phone_home_url = optional(string)<br> template_source = optional(string)<br> template_version = optional(string)<br> app_id = optional(string)<br> tgactive_url = optional(string)<br> tgstandby_url = optional(string)<br> tgrefresh_url = optional(string)<br> })</pre> | <pre>{<br> "license_type": "none"<br>}</pre> | no |

cluster.tf

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,63 @@ resource "ibm_container_vpc_worker_pool" "pool" {
127127
}
128128

129129
##############################################################################
130+
131+
##############################################################################
132+
# Addons
133+
##############################################################################
134+
135+
# Lookup the current default csi-driver version
136+
data "ibm_container_addons" "existing_addons" {
137+
for_each = ibm_container_vpc_cluster.cluster
138+
cluster = each.value.id
139+
}
140+
141+
locals {
142+
csi_driver_version = {
143+
for cluster in ibm_container_vpc_cluster.cluster : cluster.name => (
144+
length(data.ibm_container_addons.existing_addons[cluster.name].addons) > 0 &&
145+
data.ibm_container_addons.existing_addons[cluster.name].addons[0].name == "vpc-block-csi-driver" ?
146+
data.ibm_container_addons.existing_addons[cluster.name].addons[0].version : ""
147+
)
148+
}
149+
150+
151+
# addons_list = var.addons != null ? { for k, v in var.addons : k => v if v != null } : {}
152+
# addons = lookup(local.addons_list, "vpc-block-csi-driver", null) == null ? merge(local.addons_list, { vpc-block-csi-driver = local.csi_driver_version[0] }) : local.addons_list
153+
# for each cluster in the clusters_map, get the addons and their versions and create an addons map including the corosponding csi_driver_version
154+
cluster_addons = {
155+
for cluster in var.clusters : "${var.prefix}-${cluster.name}" => {
156+
id = ibm_container_vpc_cluster.cluster["${var.prefix}-${cluster.name}"].id
157+
resource_group_id = ibm_container_vpc_cluster.cluster["${var.prefix}-${cluster.name}"].resource_group_id
158+
addons = merge(
159+
{ for addon_name, addon_version in(cluster.addons != null ? cluster.addons : {}) : addon_name => addon_version if addon_version != null },
160+
local.csi_driver_version["${var.prefix}-${cluster.name}"] != null ? { vpc-block-csi-driver = local.csi_driver_version["${var.prefix}-${cluster.name}"] } : {}
161+
)
162+
}
163+
}
164+
}
165+
166+
resource "ibm_container_addons" "addons" {
167+
# Worker pool creation can start before the 'ibm_container_vpc_cluster' completes since there is no explicit
168+
# depends_on in 'ibm_container_vpc_worker_pool', just an implicit depends_on on the cluster ID. Cluster ID can exist before
169+
# 'ibm_container_vpc_cluster' completes, so hence need to add explicit depends on against 'ibm_container_vpc_cluster' here.
170+
depends_on = [ibm_container_vpc_cluster.cluster, ibm_container_vpc_worker_pool.pool]
171+
for_each = local.cluster_addons
172+
cluster = each.value.id
173+
resource_group_id = each.value.resource_group_id
174+
175+
# setting to false means we do not want Terraform to manage addons that are managed elsewhere
176+
manage_all_addons = local.clusters_map[each.key].manage_all_addons
177+
178+
dynamic "addons" {
179+
for_each = local.cluster_addons[each.key].addons
180+
content {
181+
name = addons.key
182+
version = addons.value
183+
}
184+
}
185+
186+
timeouts {
187+
create = "1h"
188+
}
189+
}

patterns/roks/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ module "roks_landing_zone" {
3535
workers_per_zone = var.workers_per_zone
3636
flavor = var.flavor
3737
kube_version = var.kube_version
38+
cluster_addons = var.cluster_addons
39+
manage_all_cluster_addons = var.manage_all_cluster_addons
3840
add_atracker_route = var.add_atracker_route
3941
hs_crypto_instance_name = var.hs_crypto_instance_name
4042
hs_crypto_resource_group = var.hs_crypto_resource_group

patterns/roks/module/config.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ locals {
8787
cos_name = "cos"
8888
entitlement = var.entitlement
8989
secondary_storage = var.secondary_storage
90+
addons = var.cluster_addons
91+
manage_all_addons = var.manage_all_cluster_addons
9092
boot_volume_crk_name = "${var.prefix}-roks-key"
9193
# By default, create dedicated pool for logging
9294
worker_pools = [

patterns/roks/module/variables.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,27 @@ variable "secondary_storage" {
163163
default = null
164164
}
165165

166+
variable "cluster_addons" {
167+
type = object({
168+
debug-tool = optional(string)
169+
image-key-synchronizer = optional(string)
170+
openshift-data-foundation = optional(string)
171+
vpc-file-csi-driver = optional(string)
172+
static-route = optional(string)
173+
cluster-autoscaler = optional(string)
174+
vpc-block-csi-driver = optional(string)
175+
})
176+
description = "Map of OCP cluster add-on versions to install (NOTE: The 'vpc-block-csi-driver' add-on is installed by default for VPC clusters, however you can explicitly specify it here if you wish to choose a later version than the default one). For full list of all supported add-ons and versions, see https://cloud.ibm.com/docs/containers?topic=containers-supported-cluster-addon-versions"
177+
default = null
178+
}
179+
180+
variable "manage_all_cluster_addons" {
181+
type = bool
182+
default = false
183+
nullable = false # null values are set to default value
184+
description = "Instructs Terraform to manage all cluster addons, even if addons were installed outside of the module. If set to 'true' this module will destroy any addons that were installed by other sources."
185+
}
186+
166187
##############################################################################
167188

168189

patterns/roks/variables.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,27 @@ variable "entitlement" {
171171
default = null
172172
}
173173

174+
variable "cluster_addons" {
175+
type = object({
176+
debug-tool = optional(string)
177+
image-key-synchronizer = optional(string)
178+
openshift-data-foundation = optional(string)
179+
vpc-file-csi-driver = optional(string)
180+
static-route = optional(string)
181+
cluster-autoscaler = optional(string)
182+
vpc-block-csi-driver = optional(string)
183+
})
184+
description = "Map of OCP cluster add-on versions to install (NOTE: The 'vpc-block-csi-driver' add-on is installed by default for VPC clusters, however you can explicitly specify it here if you wish to choose a later version than the default one). For full list of all supported add-ons and versions, see https://cloud.ibm.com/docs/containers?topic=containers-supported-cluster-addon-versions"
185+
default = null
186+
}
187+
188+
variable "manage_all_cluster_addons" {
189+
type = bool
190+
default = false
191+
nullable = false # null values are set to default value
192+
description = "Instructs Terraform to manage all cluster addons, even if addons were installed outside of the module. If set to 'true' this module will destroy any addons that were installed by other sources."
193+
}
194+
174195
##############################################################################
175196

176197

variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,16 @@ variable "clusters" {
827827
access_tags = optional(list(string), [])
828828
boot_volume_crk_name = optional(string) # Boot volume encryption key name
829829
disable_public_endpoint = optional(bool, true) # disable cluster public, leaving only private endpoint
830+
addons = optional(object({ # Map of OCP cluster add-on versions to install
831+
debug-tool = optional(string)
832+
image-key-synchronizer = optional(string)
833+
openshift-data-foundation = optional(string)
834+
vpc-file-csi-driver = optional(string)
835+
static-route = optional(string)
836+
cluster-autoscaler = optional(string)
837+
vpc-block-csi-driver = optional(string)
838+
}), {})
839+
manage_all_addons = optional(bool, false) # Instructs Terraform to manage all cluster addons, even if addons were installed outside of the module. If set to 'true' this module will destroy any addons that were installed by other sources.
830840
kms_config = optional(
831841
object({
832842
crk_name = string # Name of key

0 commit comments

Comments
 (0)