Skip to content

Commit 381aaea

Browse files
authored
feat: add support for api-key reset resource block <br> IMPORTANT: <br> - During updates, you may observe the destruction of a null_resource. This is expected and has no impact on existing resources. <br> - Moving forward, there is no capability to check for the existence of the containers-kubernetes-key ahead of cluster creation. As a result, the key will always be created, even if it already exists. (#795)
1 parent bc3d592 commit 381aaea

File tree

10 files changed

+11
-204
lines changed

10 files changed

+11
-204
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ Optionally, you need the following permissions to attach Access Management tags
259259
| Name | Type |
260260
|------|------|
261261
| [ibm_container_addons.addons](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/container_addons) | resource |
262+
| [ibm_container_api_key_reset.reset_api_key](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/container_api_key_reset) | resource |
262263
| [ibm_container_ingress_instance.instance](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/container_ingress_instance) | resource |
263264
| [ibm_container_vpc_cluster.autoscaling_cluster](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/container_vpc_cluster) | resource |
264265
| [ibm_container_vpc_cluster.cluster](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/container_vpc_cluster) | resource |
@@ -271,14 +272,12 @@ Optionally, you need the following permissions to attach Access Management tags
271272
| [null_resource.config_map_status](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
272273
| [null_resource.confirm_network_healthy](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
273274
| [null_resource.ocp_console_management](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
274-
| [null_resource.reset_api_key](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
275275
| [time_sleep.wait_for_auth_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
276+
| [time_sleep.wait_for_reset_api_key](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
276277
| [ibm_container_addons.existing_addons](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/data-sources/container_addons) | data source |
277278
| [ibm_container_cluster_config.cluster_config](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/data-sources/container_cluster_config) | data source |
278279
| [ibm_container_cluster_versions.cluster_versions](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/data-sources/container_cluster_versions) | data source |
279280
| [ibm_container_vpc_worker_pool.all_pools](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/data-sources/container_vpc_worker_pool) | data source |
280-
| [ibm_iam_account_settings.iam_account_settings](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/data-sources/iam_account_settings) | data source |
281-
| [ibm_iam_auth_token.reset_api_key_tokendata](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/data-sources/iam_auth_token) | data source |
282281
| [ibm_is_lbs.all_lbs](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/data-sources/is_lbs) | data source |
283282
| [ibm_is_virtual_endpoint_gateway.api_vpe](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/data-sources/is_virtual_endpoint_gateway) | data source |
284283
| [ibm_is_virtual_endpoint_gateway.master_vpe](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/data-sources/is_virtual_endpoint_gateway) | data source |
@@ -322,7 +321,6 @@ Optionally, you need the following permissions to attach Access Management tags
322321
| <a name="input_skip_ocp_secrets_manager_iam_auth_policy"></a> [skip\_ocp\_secrets\_manager\_iam\_auth\_policy](#input\_skip\_ocp\_secrets\_manager\_iam\_auth\_policy) | To skip creating auth policy that allows OCP cluster 'Manager' role access in the existing Secrets Manager instance for managing ingress certificates. | `bool` | `false` | no |
323322
| <a name="input_tags"></a> [tags](#input\_tags) | Metadata labels describing this cluster deployment, i.e. test | `list(string)` | `[]` | no |
324323
| <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 |
325-
| <a name="input_use_private_endpoint"></a> [use\_private\_endpoint](#input\_use\_private\_endpoint) | Set this to true to force all API calls to use the IBM Cloud private endpoints. | `bool` | `false` | no |
326324
| <a name="input_verify_worker_network_readiness"></a> [verify\_worker\_network\_readiness](#input\_verify\_worker\_network\_readiness) | By setting this to true, a script runs 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, set this value to false. | `bool` | `true` | no |
327325
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | ID of the VPC instance where this cluster is provisioned. | `string` | n/a | yes |
328326
| <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 is created. | <pre>map(list(object({<br/> id = string<br/> zone = string<br/> cidr_block = string<br/> })))</pre> | n/a | yes |

examples/fscloud/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ module "ocp_fscloud" {
247247
access_tags = var.access_tags
248248
ocp_version = var.ocp_version
249249
additional_lb_security_group_ids = [module.custom_sg["custom-lb-sg"].security_group_id]
250-
use_private_endpoint = true
251250
ocp_entitlement = var.ocp_entitlement
252251
enable_ocp_console = false
253252
kms_config = {

main.tf

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ resource "ibm_resource_tag" "cos_access_tag" {
126126
##############################################################################
127127

128128
resource "ibm_container_vpc_cluster" "cluster" {
129-
depends_on = [null_resource.reset_api_key]
129+
depends_on = [time_sleep.wait_for_reset_api_key]
130130
count = var.ignore_worker_pool_size_changes ? 0 : 1
131131
name = var.cluster_name
132132
vpc_id = var.vpc_id
@@ -197,7 +197,7 @@ resource "ibm_container_vpc_cluster" "cluster" {
197197

198198
# copy of the cluster resource above which ignores changes to the worker pool for use in autoscaling scenarios
199199
resource "ibm_container_vpc_cluster" "autoscaling_cluster" {
200-
depends_on = [null_resource.reset_api_key]
200+
depends_on = [time_sleep.wait_for_reset_api_key]
201201
count = var.ignore_worker_pool_size_changes ? 1 : 0
202202
name = var.cluster_name
203203
vpc_id = var.vpc_id
@@ -284,28 +284,16 @@ resource "ibm_resource_tag" "cluster_access_tag" {
284284
# when the IAM API key is initially created and when it is fully replicated across Cloudant instances where the API key
285285
# does not work because it is not fully replicated, so commands that require the API key may fail with 404.
286286
#
287-
# WORKAROUND:
288-
# Run a script that checks if an IAM API key already exists for the given region and resource group, and if it does not,
289-
# run the ibmcloud ks api-key reset command to create one. The script will then pause for some time to allow any IAM
290-
# Cloudant replication to occur. By doing this, it means the cluster provisioning process will not attempt to create a
291-
# new key, and simply use the key created by this script. So hence should not face 404s anymore.
292-
# The IKS team are tracking internally https://github.ibm.com/alchemy-containers/armada-ironsides/issues/5023
287+
# Enhancement Request: Add support to skip API key reset if a valid key already exists (https://github.com/IBM-Cloud/terraform-provider-ibm/issues/6468).
293288

294-
data "ibm_iam_auth_token" "reset_api_key_tokendata" {
295-
}
296-
297-
data "ibm_iam_account_settings" "iam_account_settings" {
289+
resource "ibm_container_api_key_reset" "reset_api_key" {
290+
region = var.region
291+
resource_group_id = var.resource_group_id
298292
}
299293

300-
resource "null_resource" "reset_api_key" {
301-
provisioner "local-exec" {
302-
command = "${path.module}/scripts/reset_iks_api_key.sh ${var.region} ${var.resource_group_id} ${var.use_private_endpoint} ${var.cluster_config_endpoint_type}"
303-
interpreter = ["/bin/bash", "-c"]
304-
environment = {
305-
IAM_TOKEN = data.ibm_iam_auth_token.reset_api_key_tokendata.iam_access_token
306-
ACCOUNT_ID = data.ibm_iam_account_settings.iam_account_settings.account_id
307-
}
308-
}
294+
resource "time_sleep" "wait_for_reset_api_key" {
295+
depends_on = [ibm_container_api_key_reset.reset_api_key]
296+
create_duration = "10s"
309297
}
310298

311299
##############################################################################

modules/fscloud/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ No resources.
136136
| <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 |
137137
| <a name="input_service_subnet_cidr"></a> [service\_subnet\_cidr](#input\_service\_subnet\_cidr) | Specify a custom subnet CIDR to provide private IP addresses for services. The subnet must be at least `/24` or larger. Default value is `172.21.0.0/16` when the variable is set to `null`. | `string` | `null` | no |
138138
| <a name="input_tags"></a> [tags](#input\_tags) | Metadata labels describing this cluster deployment | `list(string)` | `[]` | no |
139-
| <a name="input_use_private_endpoint"></a> [use\_private\_endpoint](#input\_use\_private\_endpoint) | Set this to true to force all api calls to use the IBM Cloud private endpoints. | `bool` | `false` | no |
140139
| <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 |
141140
| <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 |
142141
| <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 |

modules/fscloud/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module "fscloud" {
1111
ocp_entitlement = var.ocp_entitlement
1212
vpc_id = var.vpc_id
1313
vpc_subnets = var.vpc_subnets
14-
use_private_endpoint = var.use_private_endpoint
1514
worker_pools = var.worker_pools
1615
disable_public_endpoint = true
1716
cluster_config_endpoint_type = var.cluster_config_endpoint_type

modules/fscloud/variables.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ variable "region" {
1313
description = "The IBM Cloud region where the cluster will be provisioned."
1414
}
1515

16-
variable "use_private_endpoint" {
17-
type = bool
18-
description = "Set this to true to force all api calls to use the IBM Cloud private endpoints."
19-
default = false
20-
}
21-
2216
# Cluster Variables
2317
variable "tags" {
2418
type = list(string)

scripts/reset_iks_api_key.sh

Lines changed: 0 additions & 162 deletions
This file was deleted.

solutions/fully-configurable/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ module "ocp_base" {
233233
number_of_lbs = var.number_of_lbs
234234
pod_subnet_cidr = var.pod_subnet_cidr
235235
service_subnet_cidr = var.service_subnet_cidr
236-
use_private_endpoint = var.use_private_endpoint
237236
verify_worker_network_readiness = var.verify_worker_network_readiness
238237
worker_pools_taints = var.worker_pools_taints
239238
enable_secrets_manager_integration = var.enable_secrets_manager_integration

solutions/quickstart/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,5 @@ module "ocp_base" {
143143
disable_outbound_traffic_protection = var.allow_outbound_traffic
144144
access_tags = var.access_tags
145145
disable_public_endpoint = !var.allow_public_access_to_cluster
146-
use_private_endpoint = true
147146
cluster_config_endpoint_type = "default"
148147
}

variables.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ variable "region" {
1313
description = "The IBM Cloud region where the cluster is provisioned."
1414
}
1515

16-
variable "use_private_endpoint" {
17-
type = bool
18-
description = "Set this to true to force all API calls to use the IBM Cloud private endpoints."
19-
default = false
20-
}
21-
2216
# Cluster Variables
2317
variable "tags" {
2418
type = list(string)

0 commit comments

Comments
 (0)