Skip to content

Commit 16b9dfe

Browse files
authored
feat: Exposed the ability to allow version upgrades using new input enable_openshift_version_upgrade. This is intended for advanced users who manually control major version upgrades. Defaults to false to avoid unintended drift from IBM-managed patch updates. NOTE: Enabling this on existing clusters requires a one-time terraform state migration. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-base-ocp-vpc/blob/main/README.md#openshift-version-upgrade). (#760)
1 parent 4d905ff commit 16b9dfe

File tree

11 files changed

+266
-45
lines changed

11 files changed

+266
-45
lines changed

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,12 @@ module "ocp_base" {
118118
}
119119
```
120120

121-
### Customizing default cloud service endpoints.
121+
### Customizing default cloud service endpoints
122122

123123
The user must export the endpoint as an environment variable in order to use custom cloud service endpoints with this module. [Learn more](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/guides/custom-service-endpoints#getting-started-with-custom-service-endpoints).
124124

125125
**Important** The only supported method for customizing cloud service endpoints is to export the environment variables endpoint; be sure to export the value for `IBMCLOUD_IAM_API_ENDPOINT`, `IBMCLOUD_CS_API_ENDPOINT` and `IBMCLOUD_IS_NG_API_ENDPOINT`. For example,
126+
126127
```
127128
export IBMCLOUD_IAM_API_ENDPOINT="<endpoint_url>"
128129
export IBMCLOUD_CS_API_ENDPOINT="<endpoint_url>"
@@ -140,6 +141,7 @@ There is a provision to toggle outbound traffic by using the modules' `disable_o
140141
**Changes Requiring Re-creation of Default Worker Pool**
141142

142143
If you need to make changes to the default worker pool that require its re-creation (e.g., changing the worker node `operating_system`), you need to follow 3 steps:
144+
143145
1. you must set the `allow_default_worker_pool_replacement` variable to `true`, perform the apply.
144146
2. Once the first apply is successful, then make the required change to the default worker pool object, perform the apply.
145147
3. After successful apply of the default worker pool change set `allow_default_worker_pool_replacement` back to `false` in the code before the subsequent apply.
@@ -183,6 +185,46 @@ In all cases, note that:
183185
- **Important**: If additional load balancers are added after creating the cluster, for example, by exposing a Kubernetes service of type LoadBalancer, update the `number_of_lbs` variable and re-run this module to attach the extra security groups to the newly created load balancer.
184186
- The default IBM-managed security group is attached to the LBs in all cases.
185187

188+
### OpenShift Version Upgrade
189+
190+
Consumers who want to deploy an OpenShift cluster through this module and later manage **master** version upgrades via Terraform must set the variable `enable_openshift_version_upgrade` to `true`. Master upgrade typically require manual checks, and potential updates to the workload, therefore this option is set to `false` by default. This is an advanced capability that we recommend to set to `true` only if you have a robust process to handle master upgrades before updating the version via Terraform.
191+
192+
Existing users: this capability was introduced in v3.64 of the module. Existing users with a cluster created on previous version of the module can also enable this variable to manage version upgrades through Terraform. However, when `enable_openshift_version_upgrade` is set to `true`, Terraform may plan to destroy and re-create the cluster because the resource type in the module changes. To prevent this, you **must** migrate the existing state to the new resource address before applying any changes - `ibm_container_vpc_cluster.cluster[0]` to `ibm_container_vpc_cluster.cluster_with_upgrade[0]` or, when using auto-scaling, `ibm_container_vpc_cluster.autoscaling_cluster[0]` to `ibm_container_vpc_cluster.autoscaling_cluster_with_upgrade[0]`. This is a one time migration of the state.
193+
194+
There are several options to do this:
195+
196+
#### Use terraform moved blocks (recommended)
197+
198+
The recommended approach is to use Terraform's native `moved` block feature:
199+
200+
```hcl
201+
# Example assuming your OCP module is called "ocp"
202+
moved {
203+
from = module.ocp.ibm_container_vpc_cluster.cluster[0]
204+
to = module.ocp.ibm_container_vpc_cluster.cluster_with_upgrade[0]
205+
}
206+
```
207+
208+
For auto-scaling clusters:
209+
```hcl
210+
moved {
211+
from = module.ocp.ibm_container_vpc_cluster.autoscaling_cluster[0]
212+
to = module.ocp.ibm_container_vpc_cluster.autoscaling_cluster_with_upgrade[0]
213+
}
214+
```
215+
216+
Add this block to your Terraform configuration, run `terraform plan` to verify the state migration, then `terraform apply` to apply the changes. This approach works for both local Terraform and Schematics deployments.
217+
218+
After a successful migration and once all team members have applied the changes, you can safely remove the moved blocks from your configuration.
219+
220+
#### Alternative: manual state migration
221+
222+
If you prefer not to use moved blocks, you can manually use the terraform state mv command to migrate resources:
223+
224+
- For local Terraform deployments, see the [terraform state mv documentation](https://developer.hashicorp.com/terraform/cli/commands/state/mv)
225+
- For Schematics deployments, see the [ibmcloud schematics workspace state mv documentation](https://cloud.ibm.com/docs/schematics?topic=schematics-schematics-cli-reference#schematics-wks_statemv)
226+
227+
186228
### Troubleshooting
187229

188230
#### New kube_version message
@@ -262,7 +304,9 @@ Optionally, you need the following permissions to attach Access Management tags
262304
| [ibm_container_api_key_reset.reset_api_key](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/container_api_key_reset) | resource |
263305
| [ibm_container_ingress_instance.instance](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/container_ingress_instance) | resource |
264306
| [ibm_container_vpc_cluster.autoscaling_cluster](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/container_vpc_cluster) | resource |
307+
| [ibm_container_vpc_cluster.autoscaling_cluster_with_upgrade](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/container_vpc_cluster) | resource |
265308
| [ibm_container_vpc_cluster.cluster](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/container_vpc_cluster) | resource |
309+
| [ibm_container_vpc_cluster.cluster_with_upgrade](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/container_vpc_cluster) | resource |
266310
| [ibm_container_vpc_worker_pool.autoscaling_pool](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/container_vpc_worker_pool) | resource |
267311
| [ibm_container_vpc_worker_pool.pool](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/container_vpc_worker_pool) | resource |
268312
| [ibm_iam_authorization_policy.ocp_secrets_manager_iam_auth_policy](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
@@ -302,6 +346,7 @@ Optionally, you need the following permissions to attach Access Management tags
302346
| <a name="input_disable_outbound_traffic_protection"></a> [disable\_outbound\_traffic\_protection](#input\_disable\_outbound\_traffic\_protection) | Whether to allow public outbound access from the cluster workers. This is only applicable for OCP 4.15 and later. | `bool` | `false` | no |
303347
| <a name="input_disable_public_endpoint"></a> [disable\_public\_endpoint](#input\_disable\_public\_endpoint) | Whether access to the public service endpoint is disabled when the cluster is created. Does not affect existing clusters. You can't disable a public endpoint on an existing cluster, so you can't convert a public cluster to a private cluster. To change a public endpoint to private, create another cluster with this input set to `true`. | `bool` | `false` | no |
304348
| <a name="input_enable_ocp_console"></a> [enable\_ocp\_console](#input\_enable\_ocp\_console) | Flag to specify whether to enable or disable the OpenShift console. If set to `null` the module does not modify the current setting on the cluster. Keep in mind that when this input is set to `true` or `false` on a cluster with private only endpoint enabled, the runtime must be able to access the private endpoint. | `bool` | `null` | no |
349+
| <a name="input_enable_openshift_version_upgrade"></a> [enable\_openshift\_version\_upgrade](#input\_enable\_openshift\_version\_upgrade) | When set to true, allows Terraform to manage major OpenShift version upgrades. This is intended for advanced users who manually control major version upgrades. Defaults to false to avoid unintended drift from IBM-managed patch updates. NOTE: Enabling this on existing clusters requires a one-time terraform state migration. See [README](https://github.com/terraform-ibm-modules/terraform-ibm-base-ocp-vpc/blob/main/README.md#openshift-version-upgrade) for details. | `bool` | `false` | no |
305350
| <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 |
306351
| <a name="input_enable_secrets_manager_integration"></a> [enable\_secrets\_manager\_integration](#input\_enable\_secrets\_manager\_integration) | Integrate with IBM Cloud Secrets Manager so you can centrally manage Ingress subdomain certificates and other secrets. [Learn more](https://cloud.ibm.com/docs/containers?topic=containers-secrets-mgr) | `bool` | `false` | no |
307352
| <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 |

examples/advanced/main.tf

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,20 @@ locals {
155155
}
156156

157157
module "ocp_base" {
158-
source = "../.."
159-
cluster_name = var.prefix
160-
resource_group_id = module.resource_group.resource_group_id
161-
region = var.region
162-
force_delete_storage = true
163-
vpc_id = ibm_is_vpc.vpc.id
164-
vpc_subnets = local.cluster_vpc_subnets
165-
worker_pools = local.worker_pools
166-
ocp_version = var.ocp_version
167-
tags = var.resource_tags
168-
access_tags = var.access_tags
169-
worker_pools_taints = local.worker_pools_taints
170-
ocp_entitlement = var.ocp_entitlement
158+
source = "../.."
159+
cluster_name = var.prefix
160+
resource_group_id = module.resource_group.resource_group_id
161+
region = var.region
162+
force_delete_storage = true
163+
vpc_id = ibm_is_vpc.vpc.id
164+
vpc_subnets = local.cluster_vpc_subnets
165+
worker_pools = local.worker_pools
166+
ocp_version = var.ocp_version
167+
tags = var.resource_tags
168+
access_tags = var.access_tags
169+
worker_pools_taints = local.worker_pools_taints
170+
ocp_entitlement = var.ocp_entitlement
171+
enable_openshift_version_upgrade = var.enable_openshift_version_upgrade
171172
# Enable if using worker autoscaling. Stops Terraform managing worker count.
172173
ignore_worker_pool_size_changes = true
173174
addons = {

examples/advanced/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,9 @@ variable "ocp_entitlement" {
5151
description = "Value that is applied to the entitlements for OCP cluster provisioning"
5252
default = null
5353
}
54+
55+
variable "enable_openshift_version_upgrade" {
56+
type = bool
57+
description = "When set to true, allows Terraform to manage major OpenShift version upgrades. This is intended for advanced users who manually control major version upgrades. Defaults to false to avoid unintended drift from IBM-managed patch updates. NOTE: Enabling this on existing clusters requires a one-time terraform state migration. See [README](https://github.com/terraform-ibm-modules/terraform-ibm-base-ocp-vpc/blob/main/README.md#openshift-version-upgrade) for details."
58+
default = false
59+
}

examples/basic/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ locals {
6363
pool_name = "default" # ibm_container_vpc_cluster automatically names default pool "default" (See https://github.com/IBM-Cloud/terraform-provider-ibm/issues/2849)
6464
machine_type = "bx2.4x16"
6565
workers_per_zone = 2 # minimum of 2 is allowed when using single zone
66-
operating_system = "REDHAT_8_64"
66+
operating_system = "RHCOS"
6767
}
6868
]
6969
}

examples/custom_sg/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ module "ocp_base" {
104104
vpc_id = ibm_is_vpc.vpc.id
105105
vpc_subnets = local.cluster_vpc_subnets
106106
ocp_version = var.ocp_version
107+
enable_openshift_version_upgrade = var.enable_openshift_version_upgrade
107108
worker_pools = local.worker_pools
108109
access_tags = var.access_tags
109110
attach_ibm_managed_security_group = true # true is the default

examples/custom_sg/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ variable "ocp_version" {
4040
default = "4.14"
4141
}
4242

43+
variable "enable_openshift_version_upgrade" {
44+
type = bool
45+
description = "When set to true, allows Terraform to manage major OpenShift version upgrades. This is intended for advanced users who manually control major version upgrades. Defaults to false to avoid unintended drift from IBM-managed patch updates. NOTE: Enabling this on existing clusters requires a one-time terraform state migration. See README for details."
46+
default = false
47+
}
48+
4349
variable "access_tags" {
4450
type = list(string)
4551
description = "A list of access tags to apply to the resources created by the module."

0 commit comments

Comments
 (0)