Skip to content

Commit 21e9aaf

Browse files
authored
feat: added support to enable Secrets Manager integration using new input enable_secrets_manager_integration so you can centrally manage Ingress subdomain certificates and other secrets (#672)
1 parent 8fb7d3a commit 21e9aaf

File tree

13 files changed

+414
-89
lines changed

13 files changed

+414
-89
lines changed

README.md

Lines changed: 25 additions & 15 deletions
Large diffs are not rendered by default.

ibm_catalog.json

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,21 @@
388388
},
389389
{
390390
"key": "cbr_rules"
391+
},
392+
{
393+
"key": "enable_secrets_manager_integration"
394+
},
395+
{
396+
"key": "existing_secrets_manager_instance_crn"
397+
},
398+
{
399+
"key": "secrets_manager_secret_group_id"
400+
},
401+
{
402+
"key": "secrets_manager_endpoint_type"
403+
},
404+
{
405+
"key": "skip_ocp_secrets_manager_iam_auth_policy"
391406
}
392407
],
393408
"dependencies": [
@@ -561,14 +576,22 @@
561576
"reference_version": true
562577
},
563578
{
564-
"dependency_input": "resource_group_name",
565-
"version_input": "existing_resource_group_name",
579+
"dependency_input": "secrets_manager_endpoint_type",
580+
"version_input": "secrets_manager_endpoint_type",
566581
"reference_version": true
567582
},
568583
{
569584
"dependency_input": "use_existing_resource_group",
570585
"value": true,
571586
"reference_version": true
587+
},
588+
{
589+
"dependency_output": "secrets_manager_crn",
590+
"version_input": "existing_secrets_manager_instance_crn"
591+
},
592+
{
593+
"version_input": "enable_secrets_manager_integration",
594+
"value": true
572595
}
573596
]
574597
}

main.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,3 +719,40 @@ module "cbr_rule" {
719719
}]
720720
operations = var.cbr_rules[count.index].operations == null ? local.default_operations : var.cbr_rules[count.index].operations
721721
}
722+
723+
##############################################################
724+
# Ingress Secrets Manager Integration
725+
##############################################################
726+
727+
module "existing_secrets_manager_instance_parser" {
728+
count = var.enable_secrets_manager_integration ? 1 : 0
729+
source = "terraform-ibm-modules/common-utilities/ibm//modules/crn-parser"
730+
version = "1.1.0"
731+
crn = var.existing_secrets_manager_instance_crn
732+
}
733+
734+
resource "ibm_iam_authorization_policy" "ocp_secrets_manager_iam_auth_policy" {
735+
count = var.enable_secrets_manager_integration && !var.skip_ocp_secrets_manager_iam_auth_policy ? 1 : 0
736+
depends_on = [ibm_container_vpc_cluster.cluster, ibm_container_vpc_cluster.autoscaling_cluster, ibm_container_vpc_worker_pool.pool, ibm_container_vpc_worker_pool.autoscaling_pool]
737+
source_service_name = "containers-kubernetes"
738+
source_resource_instance_id = local.cluster_id
739+
target_service_name = "secrets-manager"
740+
target_resource_instance_id = module.existing_secrets_manager_instance_parser[0].service_instance
741+
roles = ["Manager"]
742+
}
743+
744+
resource "time_sleep" "wait_for_auth_policy" {
745+
count = var.enable_secrets_manager_integration ? 1 : 0
746+
depends_on = [ibm_iam_authorization_policy.ocp_secrets_manager_iam_auth_policy[0]]
747+
create_duration = "30s"
748+
}
749+
750+
751+
resource "ibm_container_ingress_instance" "instance" {
752+
count = var.enable_secrets_manager_integration ? 1 : 0
753+
depends_on = [time_sleep.wait_for_auth_policy]
754+
cluster = var.cluster_name
755+
instance_crn = var.existing_secrets_manager_instance_crn
756+
is_default = true
757+
secret_group_id = var.secrets_manager_secret_group_id
758+
}

outputs.tf

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
##############################################################################
44

55
output "cluster_id" {
6-
description = "ID of cluster created"
6+
description = "ID of the cluster"
77
value = var.ignore_worker_pool_size_changes ? ibm_container_vpc_cluster.autoscaling_cluster[0].id : ibm_container_vpc_cluster.cluster[0].id
88
depends_on = [null_resource.confirm_network_healthy]
99
}
1010

1111
output "cluster_name" {
12-
description = "Name of the created cluster"
12+
description = "Name of the cluster"
1313
value = var.ignore_worker_pool_size_changes ? ibm_container_vpc_cluster.autoscaling_cluster[0].name : ibm_container_vpc_cluster.cluster[0].name
1414
depends_on = [null_resource.confirm_network_healthy]
1515
}
1616

1717
output "cluster_crn" {
18-
description = "CRN for the created cluster"
18+
description = "CRN of the cluster"
1919
value = var.ignore_worker_pool_size_changes ? ibm_container_vpc_cluster.autoscaling_cluster[0].crn : ibm_container_vpc_cluster.cluster[0].crn
2020
depends_on = [null_resource.confirm_network_healthy]
2121
}
@@ -41,7 +41,7 @@ output "vpc_id" {
4141
}
4242

4343
output "region" {
44-
description = "Region cluster is deployed in"
44+
description = "Region that the cluster is deployed to"
4545
value = var.region
4646
}
4747

@@ -104,3 +104,8 @@ output "registry_vpe" {
104104
description = "Info about the registry VPE, if it exists. For more info about schema, see https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/is_virtual_endpoint_gateway"
105105
value = local.registry_vpe_id
106106
}
107+
108+
output "secrets_manager_integration_config" {
109+
description = "Information about the Secrets Manager instance that is used to store the Ingress certificates."
110+
value = var.enable_secrets_manager_integration ? ibm_container_ingress_instance.instance[0] : null
111+
}

0 commit comments

Comments
 (0)