Skip to content

Commit 1ed856b

Browse files
authored
feat: the following optional input variables have been added to the OCP DA solution, allowing the use of existing resources for KMS and COS:<br>- existing_kms_instance_name<br>- existing_kms_resource_group<br>- existing_kms_endpoint_type<br>- existing_cos_instance_name<br>- existing_cos_resource_group<br>- existing_cos_endpoint_type<br>- use_existing_cos_for_vpc_flowlogs<br>- use_existing_cos_for_atracker (#855)
1 parent 98b225c commit 1ed856b

File tree

22 files changed

+457
-89
lines changed

22 files changed

+457
-89
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Large diffs are not rendered by default.

cos.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ resource "ibm_cos_bucket" "buckets" {
8686
bucket_name = "${var.prefix}-${each.value.name}${each.value.random_suffix == "true" ? "-${random_string.random_cos_suffix.result}" : ""}"
8787
resource_instance_id = local.cos_instance_ids[each.value.instance]
8888
storage_class = each.value.storage_class
89-
endpoint_type = each.value.endpoint_type
89+
endpoint_type = coalesce(each.value.endpoint_type, "public")
9090
force_delete = each.value.force_delete
9191
single_site_location = each.value.single_site_location
9292
region_location = (each.value.region_location == null && each.value.single_site_location == null && each.value.cross_region_location == null) ? var.region : each.value.region_location

dynamic_values.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module "dynamic_values" {
3030
f5_vsi = var.f5_vsi
3131
f5_template_data = var.f5_template_data
3232
skip_kms_block_storage_s2s_auth_policy = var.skip_kms_block_storage_s2s_auth_policy
33+
skip_kms_kube_s2s_auth_policy = var.skip_kms_kube_s2s_auth_policy
3334
skip_all_s2s_auth_policies = var.skip_all_s2s_auth_policies
3435
atracker_cos_bucket = var.atracker.add_route == true ? var.atracker.collector_bucket_name : null
3536
}

dynamic_values/config_modules/service_authorizations/service_authorizations.tf

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ variable "skip_kms_block_storage_s2s_auth_policy" {
2222
description = "Add kms to block storage s2s"
2323
}
2424

25+
variable "skip_kms_kube_s2s_auth_policy" {
26+
description = "Add kms to kubernetes s2s"
27+
}
28+
2529
variable "skip_all_s2s_auth_policies" {
2630
description = "Add s2s authorization policies"
2731
}
@@ -73,7 +77,7 @@ module "kube_to_kms" {
7377
roles = ["Reader"]
7478
target_service_name = local.target_key_management_service
7579
target_resource_instance_id = var.key_management_guid
76-
} if local.target_key_management_service != null
80+
} if local.target_key_management_service != null && !var.skip_kms_kube_s2s_auth_policy
7781
]
7882
}
7983

@@ -95,7 +99,7 @@ module "cos_to_key_management" {
9599
roles = ["Reader"]
96100
target_service_name = local.target_key_management_service
97101
target_resource_instance_id = var.key_management_guid
98-
} if local.target_key_management_service != null
102+
} if local.target_key_management_service != null && !instance.skip_kms_s2s_auth_policy
99103
]
100104
}
101105

@@ -111,7 +115,7 @@ module "flow_logs_to_cos" {
111115
roles = ["Writer"]
112116
target_service_name = "cloud-object-storage"
113117
target_resource_instance_id = split(":", var.cos_instance_ids[instance.name])[7]
114-
}
118+
} if !instance.skip_flowlogs_s2s_auth_policy
115119
]
116120
}
117121

@@ -122,19 +126,19 @@ module "flow_logs_to_cos" {
122126
##############################################################################
123127

124128
locals {
125-
atracker_cos_instance = var.atracker_cos_bucket == null ? null : flatten([
129+
atracker_cos_instance = var.atracker_cos_bucket == null ? null : one(flatten([
126130
for instance in var.cos :
127131
[
128132
for bucket in instance.buckets :
129133
[instance.name] if bucket.name == var.atracker_cos_bucket
130-
]
131-
])[0]
134+
] if !instance.skip_atracker_s2s_auth_policy
135+
]))
132136
}
133137

134138
module "atracker_to_cos" {
135139
source = "../list_to_map"
136140
list = [
137-
for instance in(var.atracker_cos_bucket != null ? ["atracker-to-cos"] : []) :
141+
for instance in(var.atracker_cos_bucket != null && local.atracker_cos_instance != null ? ["atracker-to-cos"] : []) :
138142
{
139143
name = instance
140144
source_service_name = "atracker"

dynamic_values/service_authorizations.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module "service_authorizations" {
1010
cos_instance_ids = local.cos_instance_ids
1111
skip_kms_block_storage_s2s_auth_policy = var.skip_kms_block_storage_s2s_auth_policy
1212
skip_all_s2s_auth_policies = var.skip_all_s2s_auth_policies
13+
skip_kms_kube_s2s_auth_policy = var.skip_kms_kube_s2s_auth_policy
1314
atracker_cos_bucket = var.atracker_cos_bucket
1415
clusters = var.clusters
1516
}

dynamic_values/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ variable "skip_kms_block_storage_s2s_auth_policy" {
184184
description = "Direct reference to kms block storage variable"
185185
}
186186

187+
variable "skip_kms_kube_s2s_auth_policy" {
188+
description = "Do not create a kube to kms auth policy"
189+
}
190+
187191
variable "skip_all_s2s_auth_policies" {
188192
description = "Direct reference to s2s authorization variable"
189193
}

kms/dynamic_values.unit_tests.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ locals {
2424
# tflint-ignore: terraform_unused_declarations
2525
assert_key_exists_in_map = module.unit_test_hs_crypto.keys["test_key"]
2626
# tflint-ignore: terraform_unused_declarations
27-
assert_key_ring_exists_in_map = regex("test-ring", module.unit_test_hs_crypto.key_rings[0])
27+
assert_key_ring_exists_in_map = regex("test-ring", module.unit_test_hs_crypto.key_rings[0].key_ring_name)
2828
# tflint-ignore: terraform_unused_declarations
2929
assert_no_duplicate_key_rings = regex("1", tostring(length(module.unit_test_hs_crypto.key_rings)))
3030
# tflint-ignore: terraform_unused_declarations

kms/dynamic_values/main.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,14 @@ locals {
7474
(encryption_key.name) => encryption_key if lookup(encryption_key, "existing_key_crn", null) == null
7575
}
7676
# Rings
77-
key_rings = distinct([
78-
for encryption_key in var.keys :
79-
encryption_key.key_ring if encryption_key.key_ring != null
77+
key_rings = distinct([for encryption_key in var.keys :
78+
{
79+
key_ring_name = encryption_key.key_ring
80+
endpoint = lookup(encryption_key, "endpoint", "public")
81+
} if encryption_key.key_ring != null
8082
])
8183

84+
8285
# Policies
8386
key_management_key_policies = {
8487
for encryption_key in var.keys :

kms/main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ data "ibm_resource_instance" "hpcs_instance" {
5959
##############################################################################
6060

6161
resource "ibm_kms_key_rings" "rings" {
62-
for_each = toset(local.key_rings)
63-
instance_id = local.key_management_guid
64-
key_ring_id = each.key
62+
for_each = { for ring in local.key_rings : ring.key_ring_name => ring }
63+
instance_id = local.key_management_guid
64+
key_ring_id = each.value.key_ring_name
65+
endpoint_type = each.value.endpoint
6566
}
6667

6768
##############################################################################

patterns/dynamic_values/cloud_object_storage.tf

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

55
module "cloud_object_storage" {
6-
source = "./config_modules/cloud_object_storage"
7-
prefix = var.prefix
8-
vpc_list = local.vpc_list
9-
bastion_resource_list = local.bastion_resource_list
10-
use_random_cos_suffix = var.use_random_cos_suffix
6+
source = "./config_modules/cloud_object_storage"
7+
prefix = var.prefix
8+
vpc_list = local.vpc_list
9+
bastion_resource_list = local.bastion_resource_list
10+
use_random_cos_suffix = var.use_random_cos_suffix
11+
existing_cos_instance_name = var.existing_cos_instance_name
12+
existing_cos_resource_group = var.existing_cos_resource_group
13+
use_existing_cos_for_atracker = var.use_existing_cos_for_atracker
14+
use_existing_cos_for_vpc_flowlogs = var.use_existing_cos_for_vpc_flowlogs
15+
endpoint_type = var.existing_cos_endpoint_type
16+
create_atracker_storage = var.add_atracker_route
17+
# skip the kms s2s auth policy for existing cos instances: if existing kms name is null or empty
18+
skip_kms_auth_for_existing_cos = coalesce(var.existing_kms_instance_name, "~EMPTY~") != "~EMPTY~" ? true : false
1119
}
1220

1321
##############################################################################

0 commit comments

Comments
 (0)