Skip to content

Commit dcf9464

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

File tree

8 files changed

+113
-198
lines changed

8 files changed

+113
-198
lines changed

ibm_catalog.json

Lines changed: 16 additions & 60 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
},
@@ -425,8 +417,7 @@
425417
]
426418
},
427419
{
428-
"key": "event_notifications_name",
429-
"description": "Name of the Event Notification instance to create if not using an existing instance."
420+
"key": "event_notifications_name"
430421
},
431422
{
432423
"key": "service_plan",
@@ -455,45 +446,31 @@
455446
]
456447
},
457448
{
458-
"key": "event_notifications_tags"
449+
"key": "event_notifications_resource_tags"
459450
},
460451
{
461-
"key": "access_tags",
462-
"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."
452+
"key": "event_notifications_access_tags"
463453
},
464454
{
465-
"key": "existing_event_notifications_instance_crn",
466-
"description": "CRN of existing Event Notifications instance, set if using an existing Event Notifications instance"
455+
"key": "existing_event_notifications_instance_crn"
467456
},
468457
{
469-
"displayname": "Key Management Service encryption enabled",
470-
"key": "kms_encryption_enabled",
471-
"description": "Set to true to enable encryption on Event Notifications instance and Cloud Object Storage bucket."
458+
"key": "kms_encryption_enabled"
472459
},
473460
{
474-
"displayname": "Existing Key Management Service instance CRN",
475-
"key": "existing_kms_instance_crn",
476-
"description": "CRN of existing Key Management Service instance. Required if setting 'key_management_service_encryption_enabled' to 'true'."
461+
"key": "existing_kms_instance_crn"
477462
},
478463
{
479-
"displayname": "Key Management Service endpoint url",
480-
"key": "kms_endpoint_url",
481-
"description": "Endpoint URL of existing Key Management Service instance. Required if setting 'key_management_service_encryption_enabled' to 'true'."
464+
"key": "kms_endpoint_url"
482465
},
483466
{
484-
"displayname": "Existing Key Management Service root key CRN",
485-
"key": "existing_kms_root_key_crn",
486-
"description": "CRN of existing root key to be used in existing Key Management Service instance. To use 'key_management_service_encryption_enabled' must be enabled."
467+
"key": "existing_kms_root_key_crn"
487468
},
488469
{
489-
"displayname": "Exsiting Key Management Service key name",
490-
"key": "existing_kms_key_name",
491-
"description": "Name of existing root key to be used in existing Key Management Service instance. To use 'existing_key_management_service_root_key_crn' must be set."
470+
"key": "existing_kms_key_name"
492471
},
493472
{
494-
"displayname": "Key Management Service endpoint type",
495473
"key": "kms_endpoint_type",
496-
"description": "The type of the endpoint that is used for communicating with the KMS instance. Possible values: `public` or `private` (default). Only used if not supplying an existing root key.",
497474
"options": [
498475
{
499476
"displayname": "public",
@@ -529,70 +506,49 @@
529506
"key": "event_notifications_key_ring_name"
530507
},
531508
{
532-
"displayname": "Cloud Object Storage key ring name",
533509
"key": "cos_key_ring_name"
534510
},
535511
{
536-
"displayname": "Cloud Object Storage key name",
537512
"key": "cos_key_name"
538513
},
539514
{
540-
"displayname": "Skip Event Notifications Key Management Service auth policy",
541515
"key": "skip_event_notifications_kms_auth_policy"
542516
},
543517
{
544-
"displayname": "IBM Cloud Key Management Service apikey",
545518
"key": "ibmcloud_kms_api_key"
546519
},
547520
{
548-
"displayname": "Cloud Object Storage integration enabled",
549-
"key" : "cos_integration_enabled",
550-
"description" : "Set to 'true' to enable Cloud Object Storage integration with the Event Notification instance."
521+
"key" : "enable_collecting_failed_events"
551522
},
552523
{
553-
"displayname": "Existing Cloud Object Storage instance CRN",
554-
"key": "existing_cos_instance_crn",
555-
"description" : "Existing Cloud Object Storage instance CRN. Required if 'cloud_object_storage_integration_enabled' is set to 'true'."
524+
"key": "existing_cos_instance_crn"
556525
},
557526
{
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."
527+
"key": "existing_cos_endpoint"
561528
},
562529
{
563-
"displayname": "Existing Cloud Object Storage endpoint",
564-
"key": "existing_cos_endpoint",
565-
"description" : "The endpoint URL for your bucket region. [Learn more](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-endpoints). Only required if using an existing bucket with the `existing_cloud_object_storage_bucket_name` variable."
530+
"key": "cos_bucket_name"
566531
},
567532
{
568-
"displayname": "Cloud Object Storage bucket name",
569-
"key": "cos_bucket_name",
570-
"description" : "Name of Cloud Object Storage bucket to be created."
533+
"key": "kms_encryption_enabled_bucket"
571534
},
572535
{
573-
"displayname": "Key Management Service encryption enabled bucket",
574-
"key": "kms_encryption_enabled_bucket",
575-
"description" : "Set to true to enable Key Protect encryption on Cloud Object Storage bucket."
536+
"key": "cos_bucket_class"
576537
},
577538
{
578-
"displayname": "Cloud Object Storage bucket class",
579-
"key": "cos_bucket_class",
580-
"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`."
539+
"key": "cos_bucket_access_tags"
581540
},
582541
{
583-
"displayname": "Skip Event Notifications Cloud Object Storage auth policy",
584542
"key": "skip_event_notifications_cos_auth_policy"
585543
},
586544
{
587-
"displayname": "Skip Cloud Object Storage Key Management Service auth policy",
588545
"key": "skip_cos_kms_auth_policy"
589546
},
590547

591548
{
592549
"key": "cross_region_location"
593550
},
594551
{
595-
"displayname": "Cloud Object Storage region",
596552
"key": "cos_bucket_region"
597553
},
598554
{

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: 16 additions & 35 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
@@ -20,7 +19,7 @@ module "resource_group" {
2019

2120
# parse KMS details from the existing KMS instance CRN
2221
module "existing_kms_instance_crn_parser" {
23-
count = var.kms_encryption_enabled && var.existing_kms_instance_crn != null ? 1 : 0
22+
count = var.kms_encryption_enabled ? 1 : 0
2423
source = "terraform-ibm-modules/common-utilities/ibm//modules/crn-parser"
2524
version = "1.1.0"
2625
crn = var.existing_kms_instance_crn
@@ -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)