Skip to content

Commit 7a98602

Browse files
shemauSteve Peggs
andauthored
fix: enable event notifications in secrets manager DA (#178)
* fix: enable eveent notifications in DA * fix: add en crn validation check * fix: update existing resource test * fix: update existing resource test * fix: update existing resource test --------- Co-authored-by: Steve Peggs <[email protected]>
1 parent ffd808a commit 7a98602

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

solutions/standard/main.tf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
locals {
55
# tflint-ignore: terraform_unused_declarations
66
validate_resource_group = (var.existing_secrets_manager_crn == null && var.resource_group_name == null) ? tobool("Resource group name can not be null if existing secrets manager CRN is not set.") : true
7+
# tflint-ignore: terraform_unused_declarations
8+
validate_event_notifications = (var.existing_event_notification_instance_crn == null && var.enable_event_notification) ? tobool("To enable event notifications, an existing event notifications CRN must be set.") : true
9+
# tflint-ignore: terraform_unused_declarations
10+
validate_event_notifications_disabled = (var.existing_event_notification_instance_crn != null && !var.enable_event_notification) ? tobool("When an existing event notifications CRN is set, enable_event_notification should be true.") : true
711
}
812

913
module "resource_group" {
@@ -113,7 +117,7 @@ module "secrets_manager" {
113117
kms_key_crn = local.kms_key_crn
114118
skip_kms_iam_authorization_policy = var.skip_kms_iam_authorization_policy || local.create_cross_account_auth_policy
115119
# event notifications dependency
116-
enable_event_notification = var.existing_event_notification_instance_crn != null ? true : false
120+
enable_event_notification = var.enable_event_notification
117121
existing_en_instance_crn = var.existing_event_notification_instance_crn
118122
skip_en_iam_authorization_policy = var.skip_event_notification_iam_authorization_policy
119123
endpoint_type = local.sm_endpoint_type
@@ -187,7 +191,7 @@ locals {
187191
}
188192

189193
data "ibm_en_destinations" "en_destinations" {
190-
count = var.existing_event_notification_instance_crn != null ? 1 : 0
194+
count = var.enable_event_notification ? 1 : 0
191195
instance_guid = local.existing_en_guid
192196
}
193197

@@ -199,7 +203,7 @@ resource "time_sleep" "wait_for_secrets_manager" {
199203
}
200204

201205
resource "ibm_en_topic" "en_topic" {
202-
count = var.existing_event_notification_instance_crn != null ? 1 : 0
206+
count = var.enable_event_notification ? 1 : 0
203207
depends_on = [time_sleep.wait_for_secrets_manager]
204208
instance_guid = local.existing_en_guid
205209
name = "Secrets Manager Topic"
@@ -214,7 +218,7 @@ resource "ibm_en_topic" "en_topic" {
214218
}
215219

216220
resource "ibm_en_subscription_email" "email_subscription" {
217-
count = var.existing_event_notification_instance_crn != null && length(var.sm_en_email_list) > 0 ? 1 : 0
221+
count = var.enable_event_notification && length(var.sm_en_email_list) > 0 ? 1 : 0
218222
instance_guid = local.existing_en_guid
219223
name = "Email for Secrets Manager Subscription"
220224
description = "Subscription for Secret Manager Events"

solutions/standard/variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ variable "public_engine_enabled" {
9090
default = false
9191
}
9292

93+
########################################################################################################################
9394
# Public cert engine config
95+
########################################################################################################################
96+
9497
variable "public_engine_name" {
9598
type = string
9699
description = "The name of the IAM engine used to configure a Secrets Manager public certificate engine for an existing instance."
@@ -122,7 +125,10 @@ variable "acme_letsencrypt_private_key" {
122125
default = null
123126
}
124127

128+
########################################################################################################################
125129
# Private cert engine config
130+
########################################################################################################################
131+
126132
variable "private_engine_enabled" {
127133
type = bool
128134
description = "Set this to true to configure a Secrets Manager private certificate engine for an existing instance. If set to false, no private certificate engine will be configured for your instance."
@@ -165,6 +171,10 @@ variable "certificate_template_name" {
165171
default = "default-cert-template"
166172
}
167173

174+
########################################################################################################################
175+
# IAM engine config
176+
########################################################################################################################
177+
168178
variable "iam_engine_enabled" {
169179
type = bool
170180
description = "Set this to true to to configure a Secrets Manager IAM credentials engine. If set to false, no IAM engine will be configured for your instance."
@@ -236,6 +246,12 @@ variable "ibmcloud_kms_api_key" {
236246
# Event Notifications
237247
########################################################################################################################
238248

249+
variable "enable_event_notification" {
250+
type = bool
251+
default = false
252+
description = "Set this to true to enable lifecycle notifications for your Secrets Manager instance by connecting an Event Notifications service. When setting this to true, a value must be passed for `existing_en_instance_crn` variable."
253+
}
254+
239255
variable "existing_event_notification_instance_crn" {
240256
type = string
241257
description = "The CRN of the Event Notifications service used to enable lifecycle notifications for your Secrets Manager instance."

tests/pr_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ func TestRunExistingResourcesInstances(t *testing.T) {
195195
"region": region,
196196
"resource_group_name": terraform.Output(t, existingTerraformOptions, "resource_group_name"),
197197
"use_existing_resource_group": true,
198+
"enable_event_notification": true,
198199
"existing_event_notification_instance_crn": terraform.Output(t, existingTerraformOptions, "event_notification_instance_crn"),
199200
"existing_secrets_manager_crn": terraform.Output(t, existingTerraformOptions, "secrets_manager_instance_crn"),
200201
"iam_engine_enabled": true,
@@ -221,6 +222,7 @@ func TestRunExistingResourcesInstances(t *testing.T) {
221222
"region": region,
222223
"resource_group_name": terraform.Output(t, existingTerraformOptions, "resource_group_name"),
223224
"use_existing_resource_group": true,
225+
"enable_event_notification": true,
224226
"existing_event_notification_instance_crn": terraform.Output(t, existingTerraformOptions, "event_notification_instance_crn"),
225227
"existing_secrets_manager_kms_key_crn": terraform.Output(t, existingTerraformOptions, "secrets_manager_kms_key_crn"),
226228
"existing_kms_instance_crn": terraform.Output(t, existingTerraformOptions, "secrets_manager_kms_instance_crn"),

0 commit comments

Comments
 (0)