Skip to content

Commit f4b1a10

Browse files
authored
feat: added new variable enable_registry_storage (bool) to allow consumer to enable or disable an IBM Cloud Object Storage bucket to be used for OpenShift internal container image storage. Previously this was not optional and was always provisioned with COS storage, but recent changes to underlying API now makes it possible to turn storage off to take care of certain compliancy restrictions.<br>NOTE: You must have an allowlisted account to avail of this feature until its fully GA (#307)
1 parent d85b328 commit f4b1a10

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,10 @@ Optionally, you need the following permissions to attach Access Management tags
190190
| <a name="input_cluster_config_endpoint_type"></a> [cluster\_config\_endpoint\_type](#input\_cluster\_config\_endpoint\_type) | Specify which type of endpoint to use for for cluster config access: 'default', 'private', 'vpe', 'link'. 'default' value will use the default endpoint of the cluster. | `string` | `"default"` | no |
191191
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | The name that will be assigned to the provisioned cluster | `string` | n/a | yes |
192192
| <a name="input_cluster_ready_when"></a> [cluster\_ready\_when](#input\_cluster\_ready\_when) | The cluster is ready when one of the following: MasterNodeReady (not recommended), OneWorkerNodeReady, Normal, IngressReady | `string` | `"IngressReady"` | no |
193-
| <a name="input_cos_name"></a> [cos\_name](#input\_cos\_name) | Name of the COS instance to provision. New instance only provisioned if `use_existing_cos = false`. Default: `<cluster_name>_cos` | `string` | `null` | no |
193+
| <a name="input_cos_name"></a> [cos\_name](#input\_cos\_name) | Name of the COS instance to provision for OpenShift internal registry storage. New instance only provisioned if 'enable\_registry\_storage' is true and 'use\_existing\_cos' is false. Default: '<cluster\_name>\_cos' | `string` | `null` | no |
194194
| <a name="input_disable_public_endpoint"></a> [disable\_public\_endpoint](#input\_disable\_public\_endpoint) | Flag indicating that the public endpoint should be enabled or disabled | `bool` | `false` | no |
195-
| <a name="input_existing_cos_id"></a> [existing\_cos\_id](#input\_existing\_cos\_id) | The COS id of an already existing COS instance. Only required if 'use\_existing\_cos = true' | `string` | `null` | no |
195+
| <a name="input_enable_registry_storage"></a> [enable\_registry\_storage](#input\_enable\_registry\_storage) | Set to `true` to enable IBM Cloud Object Storage for the Red Hat OpenShift internal image registry. Set to `false` only for new cluster deployments in an account that is allowlisted for this feature. | `bool` | `true` | no |
196+
| <a name="input_existing_cos_id"></a> [existing\_cos\_id](#input\_existing\_cos\_id) | The COS id of an already existing COS instance to use for OpenShift internal registry storage. Only required if 'enable\_registry\_storage' and 'use\_existing\_cos' are true | `string` | `null` | no |
196197
| <a name="input_force_delete_storage"></a> [force\_delete\_storage](#input\_force\_delete\_storage) | Flag indicating whether or not to delete attached storage when destroying the cluster - Default: false | `bool` | `false` | no |
197198
| <a name="input_ibmcloud_api_key"></a> [ibmcloud\_api\_key](#input\_ibmcloud\_api\_key) | APIkey that's associated with the account to use, set via environment variable TF\_VAR\_ibmcloud\_api\_key | `string` | n/a | yes |
198199
| <a name="input_ignore_worker_pool_size_changes"></a> [ignore\_worker\_pool\_size\_changes](#input\_ignore\_worker\_pool\_size\_changes) | Enable if using worker autoscaling. Stops Terraform managing worker count | `bool` | `false` | no |
@@ -203,7 +204,7 @@ Optionally, you need the following permissions to attach Access Management tags
203204
| <a name="input_region"></a> [region](#input\_region) | The IBM Cloud region where the cluster will be provisioned. | `string` | n/a | yes |
204205
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The Id of an existing IBM Cloud resource group where the cluster will be grouped. | `string` | n/a | yes |
205206
| <a name="input_tags"></a> [tags](#input\_tags) | Metadata labels describing this cluster deployment, i.e. test | `list(string)` | `[]` | no |
206-
| <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 |
207+
| <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 for OpenShift internal registry storage. Only applicable if 'enable\_registry\_storage' is true | `bool` | `false` | no |
207208
| <a name="input_verify_worker_network_readiness"></a> [verify\_worker\_network\_readiness](#input\_verify\_worker\_network\_readiness) | 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. | `bool` | `true` | no |
208209
| <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 |
209210
| <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 |

main.tf

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ locals {
1414
default_ocp_version = "${data.ibm_container_cluster_versions.cluster_versions.default_openshift_version}_openshift"
1515
ocp_version = var.ocp_version == null || var.ocp_version == "default" ? local.default_ocp_version : (var.ocp_version == "latest" ? local.latest_ocp_version : "${var.ocp_version}_openshift")
1616

17-
cos_name = var.use_existing_cos == true || (var.use_existing_cos == false && var.cos_name != null) ? var.cos_name : "${var.cluster_name}_cos"
18-
cos_location = "global"
19-
cos_plan = "standard"
20-
cos_instance_crn = var.use_existing_cos != false ? var.existing_cos_id : module.cos_instance[0].cos_instance_id
17+
cos_name = var.use_existing_cos == true || (var.use_existing_cos == false && var.cos_name != null) ? var.cos_name : "${var.cluster_name}_cos"
18+
cos_location = "global"
19+
cos_plan = "standard"
20+
# if not enable_registry_storage then set cos to 'null', otherwise use existing or new CRN
21+
cos_instance_crn = var.enable_registry_storage == true ? (var.use_existing_cos != false ? var.existing_cos_id : module.cos_instance[0].cos_instance_id) : null
2122

2223
# Validation approach based on https://stackoverflow.com/a/66682419
23-
validate_condition = var.use_existing_cos == true && var.existing_cos_id == null
24+
validate_condition = var.enable_registry_storage == true && var.use_existing_cos == true && var.existing_cos_id == null
2425
validate_msg = "A value for 'existing_cos_id' variable must be passed when 'use_existing_cos = true'"
2526
# tflint-ignore: terraform_unused_declarations
2627
validate_check = regex("^${local.validate_msg}$", (!local.validate_condition ? local.validate_msg : ""))
@@ -45,7 +46,7 @@ data "ibm_container_cluster_versions" "cluster_versions" {
4546
}
4647

4748
module "cos_instance" {
48-
count = var.use_existing_cos ? 0 : 1
49+
count = var.enable_registry_storage && !var.use_existing_cos ? 1 : 0
4950

5051
source = "terraform-ibm-modules/cos/ibm"
5152
version = "7.0.6"
@@ -63,7 +64,7 @@ moved {
6364
}
6465

6566
resource "ibm_resource_tag" "cos_access_tag" {
66-
count = var.use_existing_cos || length(var.access_tags) == 0 ? 0 : 1
67+
count = var.enable_registry_storage && !var.use_existing_cos && length(var.access_tags) > 0 ? 1 : 0
6768
resource_id = module.cos_instance[0].cos_instance_id
6869
tags = var.access_tags
6970
tag_type = "access"

variables.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,28 @@ variable "force_delete_storage" {
147147

148148
variable "cos_name" {
149149
type = string
150-
description = "Name of the COS instance to provision. New instance only provisioned if `use_existing_cos = false`. Default: `<cluster_name>_cos`"
150+
description = "Name of the COS instance to provision for OpenShift internal registry storage. New instance only provisioned if 'enable_registry_storage' is true and 'use_existing_cos' is false. Default: '<cluster_name>_cos'"
151151
default = null
152152
}
153153

154154
variable "use_existing_cos" {
155155
type = bool
156-
description = "Flag indicating whether or not to use an existing COS instance"
156+
description = "Flag indicating whether or not to use an existing COS instance for OpenShift internal registry storage. Only applicable if 'enable_registry_storage' is true"
157157
default = false
158158
}
159159

160160
variable "existing_cos_id" {
161161
type = string
162-
description = "The COS id of an already existing COS instance. Only required if 'use_existing_cos = true'"
162+
description = "The COS id of an already existing COS instance to use for OpenShift internal registry storage. Only required if 'enable_registry_storage' and 'use_existing_cos' are true"
163163
default = null
164164
}
165165

166+
variable "enable_registry_storage" {
167+
type = bool
168+
description = "Set to `true` to enable IBM Cloud Object Storage for the Red Hat OpenShift internal image registry. Set to `false` only for new cluster deployments in an account that is allowlisted for this feature."
169+
default = true
170+
}
171+
166172
variable "kms_config" {
167173
type = object({
168174
crk_id = string

0 commit comments

Comments
 (0)