Skip to content

Commit abeb33c

Browse files
committed
variable validation, removed support for existing cos buckets
1 parent 4d3cab2 commit abeb33c

File tree

8 files changed

+104
-154
lines changed

8 files changed

+104
-154
lines changed

ibm_catalog.json

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@
200200
"displayname": "Existing Cloud Object Storage instance CRN",
201201
"key": "existing_cos_instance_crn"
202202
},
203-
{
204-
"displayname": "Existing Cloud Object Storage bucket name",
205-
"key": "existing_cos_bucket_name"
206-
},
207203
{
208204
"displayname": "Cloud Object Storage bucket name",
209205
"key": "cos_bucket_name"
@@ -279,10 +275,6 @@
279275
}
280276
]
281277
},
282-
{
283-
"displayname": "Existing Cloud Object Storage endpoint",
284-
"key": "existing_cos_endpoint"
285-
},
286278
{
287279
"key": "existing_secrets_manager_instance_crn"
288280
},
@@ -455,10 +447,10 @@
455447
]
456448
},
457449
{
458-
"key": "event_notifications_tags"
450+
"key": "event_notifications_resource_tags"
459451
},
460452
{
461-
"key": "access_tags",
453+
"key": "event_notifications_access_tags",
462454
"description": "A list of access tags to apply to the resources created by this solution. For more information, see https://cloud.ibm.com/docs/account?topic=account-access-tags-tutorial."
463455
},
464456
{
@@ -545,20 +537,15 @@
545537
"key": "ibmcloud_kms_api_key"
546538
},
547539
{
548-
"displayname": "Cloud Object Storage integration enabled",
549-
"key" : "cos_integration_enabled",
540+
"displayname": "Enable collecting failure events with Cloud Object Storage integration",
541+
"key" : "enable_collecting_failed_events",
550542
"description" : "Set to 'true' to enable Cloud Object Storage integration with the Event Notification instance."
551543
},
552544
{
553545
"displayname": "Existing Cloud Object Storage instance CRN",
554546
"key": "existing_cos_instance_crn",
555547
"description" : "Existing Cloud Object Storage instance CRN. Required if 'cloud_object_storage_integration_enabled' is set to 'true'."
556548
},
557-
{
558-
"displayname": "Existing Cloud Object Storage bucket name",
559-
"key": "existing_cos_bucket_name",
560-
"description" : "Existing bucket in an existing Cloud Object Storage instance."
561-
},
562549
{
563550
"displayname": "Existing Cloud Object Storage endpoint",
564551
"key": "existing_cos_endpoint",
@@ -579,6 +566,10 @@
579566
"key": "cos_bucket_class",
580567
"description" : "The storage class of the newly provisioned Cloud Object Storage bucket. Specify one of the following values for the storage class: `standard` (default), `vault`, `cold`, `smart`, or `onerate_active`."
581568
},
569+
{
570+
"displayname": "Cloud Object Storage bucket access tags",
571+
"key": "cos_bucket_access_tags"
572+
},
582573
{
583574
"displayname": "Skip Event Notifications Cloud Object Storage auth policy",
584575
"key": "skip_event_notifications_cos_auth_policy"

solutions/fully-configurable/catalogValidationValues.json.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"ibmcloud_api_key": $VALIDATION_APIKEY,
33
"existing_resource_group_name": "geretain-test-event-notifications",
4-
"event_notifications_tags": $TAGS,
4+
"event_notifications_resource_tags": $TAGS,
55
"kms_encryption_enabled": true,
66
"existing_kms_instance_crn": $HPCS_US_SOUTH_CRN,
77
"kms_endpoint_url": $HPCS_US_SOUTH_PRIVATE_ENDPOINT

solutions/fully-configurable/main.tf

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ locals {
88
}
99

1010
module "resource_group" {
11-
count = 1
1211
source = "terraform-ibm-modules/resource-group/ibm"
1312
version = "1.1.6"
1413
existing_resource_group_name = var.existing_resource_group_name
@@ -35,12 +34,6 @@ module "kms_root_key_crn_parser" {
3534
}
3635

3736
locals {
38-
# Validate existing KMS details
39-
# tflint-ignore: terraform_unused_declarations
40-
validate_kms_values = var.kms_encryption_enabled == true && var.existing_kms_instance_crn == null ? tobool("When setting var.key_protect_encryption_enabled to true, you must set var.existing_key_protect_instance_crn.") : true
41-
# Validate existing KMS key details
42-
# tflint-ignore: terraform_unused_declarations
43-
validate_kms_key_values = var.existing_kms_root_key_crn != null && (var.existing_kms_key_name == null || var.kms_endpoint_url == null) ? tobool("When setting var.existing_key_protect_root_key_crn, you must set var.existing_event_notification_key_protect_key_name and var.key_protect_endpoint_url.") : true
4437
# If an existing KMS root key, or an existing EN instance is passed, or KMS is not enabled do not create a new KMS root key
4538
create_kms_keys = !var.kms_encryption_enabled || var.existing_kms_root_key_crn != null || var.existing_event_notifications_instance_crn != null ? false : true
4639
# If existing KMS root key CRN passed, parse the ID from it
@@ -58,8 +51,8 @@ locals {
5851
kms_account_id = var.existing_kms_instance_crn != null ? try(split("/", module.existing_kms_instance_crn_parser[0].scope)[1], null) : null
5952
# Create cross account EN / KMS auth policy if not using existing EN instance, if 'skip_en_kms_auth_policy' is false, and a value is passed for 'ibmcloud_key_management_service_api_key'
6053
create_cross_account_en_kms_auth_policy = var.existing_event_notifications_instance_crn == null && !var.skip_event_notifications_kms_auth_policy && var.ibmcloud_kms_api_key != null
61-
# Create cross account COS / KMS auth policy if not using existing EN instance, if not using existing bucket, if 'skip_cos_kms_auth_policy' is false, and if a value is passed for 'ibmcloud_key_management_service_api_key'
62-
create_cross_account_cos_kms_auth_policy = var.existing_event_notifications_instance_crn == null && var.existing_cos_bucket_name == null && !var.skip_cos_kms_auth_policy && var.ibmcloud_kms_api_key != null
54+
# Create cross account COS / KMS auth policy if not using existing EN instance, if 'skip_cos_kms_auth_policy' is false, and if a value is passed for 'ibmcloud_key_management_service_api_key'
55+
create_cross_account_cos_kms_auth_policy = var.existing_event_notifications_instance_crn == null && !var.skip_cos_kms_auth_policy && var.ibmcloud_kms_api_key != null
6356
# If a prefix value is passed, add it to the EN key name
6457
en_key_name = var.existing_kms_key_name != null ? var.existing_kms_key_name : try("${local.prefix}-${var.event_notifications_key_name}", var.event_notifications_key_name)
6558
# If a prefix value is passed, add it to the EN key ring name
@@ -69,7 +62,7 @@ locals {
6962
# If a prefix value is passed, add it to the COS key ring name
7063
cos_key_ring_name = try("${local.prefix}-${var.cos_key_ring_name}", var.cos_key_ring_name)
7164
# Determine the COS KMS key CRN (new key or existing key). It will only have a value if not using an existing bucket or existing EN instance
72-
cos_kms_key_crn = var.existing_event_notifications_instance_crn != null || var.existing_cos_bucket_name != null ? null : var.existing_kms_root_key_crn != null ? var.existing_kms_root_key_crn : try(module.kms[0].keys[format("%s.%s", local.cos_key_ring_name, local.cos_key_name)].crn, null)
65+
cos_kms_key_crn = var.existing_event_notifications_instance_crn != null ? null : var.existing_kms_root_key_crn != null ? var.existing_kms_root_key_crn : try(module.kms[0].keys[format("%s.%s", local.cos_key_ring_name, local.cos_key_name)].crn, null)
7366
# If existing KMS instance CRN passed, parse the key ID from it
7467
cos_kms_key_id = local.cos_kms_key_crn != null ? module.cos_kms_key_crn_parser[0].resource : null
7568
# Event Notifications KMS Key ring config
@@ -100,8 +93,8 @@ locals {
10093
}
10194
]
10295
}
103-
# If not using existing EN instance or KMS key, create Key. Don't create a COS KMS key if using existing COS bucket.
104-
all_keys = local.create_kms_keys ? var.existing_cos_bucket_name != null ? [local.en_kms_key] : concat([local.en_kms_key], [local.en_cos_kms_key]) : []
96+
# If not using existing EN instance or KMS key, create Key.
97+
all_keys = local.create_kms_keys ? concat([local.en_kms_key], [local.en_cos_kms_key]) : []
10598
}
10699

107100
module "kms" {
@@ -116,9 +109,9 @@ module "kms" {
116109
keys = local.all_keys
117110
}
118111

119-
# If not using an existing COS bucket, or an existing EN instance, parse details from the new or existing KMS key CRN used for COS
112+
# If not using an existing EN instance, parse details from the new or existing KMS key CRN used for COS
120113
module "cos_kms_key_crn_parser" {
121-
count = (local.create_kms_keys || var.existing_kms_root_key_crn != null) && var.existing_cos_bucket_name == null ? 1 : 0
114+
count = (local.create_kms_keys || var.existing_kms_root_key_crn != null) ? 1 : 0
122115
source = "terraform-ibm-modules/common-utilities/ibm//modules/crn-parser"
123116
version = "1.1.0"
124117
crn = local.cos_kms_key_crn
@@ -219,32 +212,20 @@ module "existing_cos_crn_parser" {
219212
}
220213

221214
locals {
222-
# Validate mutually exclusive inputs
223-
# tflint-ignore: terraform_unused_declarations
224-
validate_existing_cos = var.cos_integration_enabled == true && (var.existing_cos_instance_crn == null || var.existing_cos_endpoint == null) ? tobool("If var.cloud_object_storage_integration_enabled is true, variables 'existing_cloud_object_storage_instance_crn' and 'existing_cloud_object_storage_endpoint' must be set.") : true
225-
# tflint-ignore: terraform_unused_declarations
226-
validate_cos_regions = var.cos_bucket_region != null && var.cross_region_location != null ? tobool("Cannot provide values for 'cloud_object_storage_bucket_region' and 'cross_region_location'. Pick one or the other, or alternatively pass no values for either and allow it to default to the 'region' input.") : true
227-
228-
# Validate cos inputs when using existing bucket
229-
# tflint-ignore: terraform_unused_declarations
230-
validate_cos_bucket = var.existing_cos_bucket_name != null && (var.existing_cos_instance_crn == null || var.existing_cos_endpoint == null) ? tobool("When passing a value for 'existing_cloud_object_storage_bucket_name', you must also pass values for 'existing_cloud_object_storage_instance_crn' and 'existing_cloud_object_storage_endpoint'.") : true
231-
232215
# If a bucket name is passed, or an existing EN CRN is passed; do not create COS resources
233-
create_cos_bucket = var.cos_integration_enabled == false || var.existing_cos_bucket_name == null || var.existing_event_notifications_instance_crn != null
216+
create_cos_bucket = var.enable_collecting_failed_events == false || var.existing_event_notifications_instance_crn != null ? false : true
234217
# determine COS details
235-
cos_bucket_name = var.cos_integration_enabled == false ? null : var.existing_cos_bucket_name != null ? var.existing_cos_bucket_name : local.create_cos_bucket ? try("${local.prefix}-${var.cos_bucket_name}", var.cos_bucket_name) : null
218+
cos_bucket_name = var.enable_collecting_failed_events == false ? null : local.create_cos_bucket ? try("${local.prefix}-${var.cos_bucket_name}", var.cos_bucket_name) : null
236219
cos_bucket_region = var.cos_bucket_region != null ? var.cos_bucket_region : var.cross_region_location != null ? null : var.region
237220
cos_instance_guid = var.existing_event_notifications_instance_crn == null ? (var.existing_cos_instance_crn == null ? (length(module.cos_buckets) > 0 ? module.cos_buckets.bucket_configs.cos_instance_guid : null) : module.existing_cos_crn_parser[0].service_instance) : null
238221

239-
# tflint-ignore: terraform_unused_declarations
240-
validate_existing_cos_values = !var.cos_integration_enabled || (var.existing_cos_instance_crn != null != var.existing_event_notifications_instance_crn != null) ? true : tobool("When var.cloud_object_storage_integration_enabled is set to true you must set one of var.existing_cloud_object_storage_instance_crn or var.existing_event_notification_instance_crn.")
241222
# If not using existing EN instance, parse the COS account ID from the CRN
242223
cos_account_id = var.existing_event_notifications_instance_crn == null ? var.existing_cos_instance_crn != null ? split("/", module.existing_cos_crn_parser[0].scope)[1] : null : null
243224
}
244225

245226
locals {
246227
bucket_config = [{
247-
access_tags = var.access_tags
228+
access_tags = var.cos_bucket_access_tags
248229
bucket_name = local.cos_bucket_name
249230
kms_encryption_enabled = var.kms_encryption_enabled_bucket
250231
kms_guid = var.kms_encryption_enabled_bucket ? local.kms_instance_guid : null
@@ -259,7 +240,7 @@ locals {
259240
}
260241

261242
module "cos_buckets" {
262-
count = var.cos_integration_enabled && var.existing_cos_bucket_name == null && var.existing_event_notifications_instance_crn == null ? 1 : 0
243+
count = var.enable_collecting_failed_events && var.existing_event_notifications_instance_crn == null ? 1 : 0
263244
source = "terraform-ibm-modules/cos/ibm//modules/buckets"
264245
version = "8.19.2"
265246
bucket_configs = local.bucket_config
@@ -297,12 +278,12 @@ data "ibm_resource_instance" "existing_en_instance" {
297278
module "event_notifications" {
298279
count = local.use_existing_en_instance ? 0 : 1
299280
source = "../.."
300-
resource_group_id = module.resource_group[0].resource_group_id
281+
resource_group_id = module.resource_group.resource_group_id
301282
region = var.region
302283
name = try("${local.prefix}-${var.event_notifications_name}", var.event_notifications_name)
303284
plan = var.service_plan
304-
tags = var.event_notifications_tags
305-
access_tags = var.access_tags
285+
tags = var.event_notifications_resource_tags
286+
access_tags = var.event_notifications_access_tags
306287
service_endpoints = var.service_endpoints
307288
service_credential_names = var.service_credential_names
308289
# KMS Related
@@ -312,7 +293,7 @@ module "event_notifications" {
312293
root_key_id = local.en_kms_key_id
313294
skip_en_kms_auth_policy = local.create_cross_account_en_kms_auth_policy || var.skip_event_notifications_kms_auth_policy
314295
# COS Related
315-
cos_integration_enabled = var.cos_integration_enabled
296+
cos_integration_enabled = var.enable_collecting_failed_events
316297
cos_bucket_name = local.cos_bucket_name
317298
cos_instance_id = var.existing_cos_instance_crn
318299
skip_en_cos_auth_policy = var.skip_event_notifications_cos_auth_policy || local.create_cross_account_cos_kms_auth_policy

solutions/fully-configurable/moved.tf

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

0 commit comments

Comments
 (0)