Skip to content
This repository was archived by the owner on Aug 12, 2024. It is now read-only.

Commit f51bdbd

Browse files
author
Sean Sundberg
authored
Adds logic to encrypt cluster (#17)
- Adds kms_id, kms_key_id, kms_private_endpoint, and autorize_kms variables - Updates cluster provisioning to include kms_config block if values provided - Updates metadata to include kns dependency Signed-off-by: Sean Sundberg <[email protected]>
1 parent eaab78a commit f51bdbd

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

main.tf

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ locals {
4545
vpc_subnets = !var.exists ? var.vpc_subnets : []
4646
security_group_id = !var.exists ? data.ibm_is_vpc.vpc[0].default_security_group : ""
4747
ipv4_cidr_blocks = !var.exists ? data.ibm_is_subnet.vpc_subnet[*].ipv4_cidr_block : []
48+
kms_enabled = var.kms_id != "" && var.kms_key_id != ""
49+
kms_config = local.kms_enabled ? [{
50+
instance_id = var.kms_id
51+
crk_id = var.kms_key_id
52+
private_endpoint = var.kms_private_endpoint
53+
}] : []
54+
policy_targets = [
55+
"kms",
56+
"hs-crypto"
57+
]
4858
}
4959

5060
resource null_resource create_dirs {
@@ -116,9 +126,17 @@ data ibm_is_subnet vpc_subnet {
116126
identifier = local.vpc_subnets[count.index].id
117127
}
118128

129+
resource "ibm_iam_authorization_policy" "policy" {
130+
count = local.kms_enabled && var.authorize_kms ? length(local.policy_targets) : 0
131+
132+
source_service_name = "containers-kubernetes"
133+
target_service_name = local.policy_targets[count.index]
134+
roles = ["Reader"]
135+
}
136+
119137
resource ibm_container_vpc_cluster cluster {
120138
count = !var.exists ? 1 : 0
121-
depends_on = [null_resource.print_resources]
139+
depends_on = [null_resource.print_resources, ibm_iam_authorization_policy.policy]
122140

123141
name = local.cluster_name
124142
vpc_id = local.vpc_id
@@ -135,6 +153,16 @@ resource ibm_container_vpc_cluster cluster {
135153
name = local.vpc_subnets[0].zone
136154
subnet_id = local.vpc_subnets[0].id
137155
}
156+
157+
dynamic "kms_config" {
158+
for_each = local.kms_config
159+
160+
content {
161+
instance_id = kms_config.value["instance_id"]
162+
crk_id = kms_config.value["crk_id"]
163+
private_endpoint = kms_config.value["private_endpoint"]
164+
}
165+
}
138166
}
139167

140168
resource ibm_container_vpc_worker_pool cluster_pool {

module.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ versions:
2626
refs:
2727
- source: github.com/cloud-native-toolkit/terraform-ibm-vpc-subnets
2828
version: ">= 1.0.0"
29+
- id: kms
30+
refs:
31+
- source: github.com/cloud-native-toolkit/terraform-ibm-key-protect
32+
version: ">= 1.0.0"
33+
- source: github.com/cloud-native-toolkit/terraform-ibm-hpcs
34+
version: ">= 1.0.0"
35+
optional: true
2936
variables:
3037
- name: resource_group_name
3138
moduleRef:
@@ -47,6 +54,13 @@ versions:
4754
moduleRef:
4855
id: cos
4956
output: id
57+
- name: kms_id
58+
moduleRef:
59+
id: kms
60+
output: id
61+
optional: true
62+
- name: kms_key_id
63+
optional: true
5064
- name: name_prefix
5165
scope: global
5266
- name: region

variables.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,27 @@ variable "cos_id" {
9494
type = string
9595
description = "The crn of the COS instance that will be used with the OCP instance"
9696
}
97+
98+
variable "kms_id" {
99+
type = string
100+
description = "The crn of the KMS instance that will be used to encrypt the cluster."
101+
default = ""
102+
}
103+
104+
variable "kms_key_id" {
105+
type = string
106+
description = "The id of the root key in the KMS instance that will be used to encrypt the cluster."
107+
default = ""
108+
}
109+
110+
variable "kms_private_endpoint" {
111+
type = bool
112+
description = "Flag indicating that the private endpoint should be used to connect the KMS system to the cluster."
113+
default = true
114+
}
115+
116+
variable "authorize_kms" {
117+
type = bool
118+
description = "Flag indicating that the authorization between the kms and the service should be created."
119+
default = true
120+
}

0 commit comments

Comments
 (0)