Skip to content

Commit 9203610

Browse files
authored
feat: do not create Event Notification related resources in the Deployable Architecture solution when an existing Secrets Manager instance is passed (#201)
1 parent dbc6468 commit 9203610

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ You need the following permissions to run this module.
9595
|------|-------------|------|---------|:--------:|
9696
| <a name="input_allowed_network"></a> [allowed\_network](#input\_allowed\_network) | The types of service endpoints to set on the Secrets Manager instance. Possible values are `private-only` or `public-and-private`. | `string` | `"public-and-private"` | no |
9797
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | (Optional, list) List of CBR rules to create | <pre>list(object({<br> description = string<br> account_id = string<br> rule_contexts = list(object({<br> attributes = optional(list(object({<br> name = string<br> value = string<br> }))) }))<br> enforcement_mode = string<br> }))</pre> | `[]` | no |
98-
| <a name="input_enable_event_notification"></a> [enable\_event\_notification](#input\_enable\_event\_notification) | 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. | `bool` | `false` | no |
98+
| <a name="input_enable_event_notification"></a> [enable\_event\_notification](#input\_enable\_event\_notification) | 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` and `existing_sm_instance_crn` must be null. | `bool` | `false` | no |
9999
| <a name="input_endpoint_type"></a> [endpoint\_type](#input\_endpoint\_type) | The type of endpoint (public or private) to connect to the Secrets Manager API. The Terraform provider uses this endpoint type to interact with the Secrets Manager API and configure Event Notifications. | `string` | `"public"` | no |
100100
| <a name="input_existing_en_instance_crn"></a> [existing\_en\_instance\_crn](#input\_existing\_en\_instance\_crn) | The CRN of the Event Notifications service to enable lifecycle notifications for your Secrets Manager instance. | `string` | `null` | no |
101101
| <a name="input_existing_kms_instance_guid"></a> [existing\_kms\_instance\_guid](#input\_existing\_kms\_instance\_guid) | The GUID of the Hyper Protect Crypto Services or Key Protect instance in which the key specified in `kms_key_crn` is coming from. Required only if `kms_encryption_enabled` is set to true, and `skip_kms_iam_authorization_policy` is set to false. | `string` | `null` | no |

main.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ locals {
1414
# tflint-ignore: terraform_unused_declarations
1515
validate_event_notification = var.enable_event_notification && var.existing_en_instance_crn == null ? tobool("When setting var.enable_event_notification to true, a value must be passed for var.existing_en_instance_crn") : true
1616
# tflint-ignore: terraform_unused_declarations
17-
validate_endpoint = var.enable_event_notification && var.endpoint_type == "public" && var.allowed_network == "private-only" && var.existing_sm_instance_crn == null ? tobool("It is not allowed to have conflicting var.endpoint_type and var.allowed_network values.") : true
17+
validate_endpoint = var.endpoint_type == "public" && var.allowed_network == "private-only" && var.existing_sm_instance_crn == null ? tobool("It is not allowed to have conflicting var.endpoint_type and var.allowed_network values.") : true
1818
# tflint-ignore: terraform_unused_declarations
1919
validate_region = var.existing_sm_instance_crn == null && var.region == null ? tobool("When existing_sm_instance_crn is null, a value must be passed for var.region") : true
2020
}
@@ -126,7 +126,8 @@ module "cbr_rule" {
126126

127127
# Create IAM Authorization Policies to allow SM to access event notification
128128
resource "ibm_iam_authorization_policy" "en_policy" {
129-
count = var.enable_event_notification == false || var.skip_en_iam_authorization_policy ? 0 : 1
129+
# if existing SM instance CRN is passed (!= null), then never create a policy
130+
count = var.existing_sm_instance_crn != null || (var.enable_event_notification == false || var.skip_en_iam_authorization_policy) ? 0 : 1
130131
source_service_name = "secrets-manager"
131132
source_resource_group_id = var.resource_group_id
132133
target_service_name = "event-notifications"
@@ -136,7 +137,8 @@ resource "ibm_iam_authorization_policy" "en_policy" {
136137
}
137138

138139
resource "ibm_sm_en_registration" "sm_en_registration" {
139-
count = var.enable_event_notification ? 1 : 0
140+
# if existing SM instance CRN is passed (!= null), then never register EN
141+
count = var.existing_sm_instance_crn == null && var.enable_event_notification ? 1 : 0
140142
depends_on = [time_sleep.wait_for_authorization_policy]
141143
instance_id = local.secrets_manager_guid
142144
region = local.secrets_manager_region

solutions/standard/main.tf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,23 @@ locals {
190190
}
191191

192192
data "ibm_en_destinations" "en_destinations" {
193-
count = var.enable_event_notification ? 1 : 0
193+
# if existing SM instance CRN is passed (!= null), then never do data lookup for EN destinations
194+
count = var.existing_secrets_manager_crn == null && var.enable_event_notification ? 1 : 0
194195
instance_guid = local.existing_en_guid
195196
}
196197

197198
# workaround for https://github.com/IBM-Cloud/terraform-provider-ibm/issues/5533
198199
resource "time_sleep" "wait_for_secrets_manager" {
199-
count = var.enable_event_notification ? 1 : 0
200+
# if existing SM instance CRN is passed (!= null), then never work with EN
201+
count = var.existing_secrets_manager_crn == null && var.enable_event_notification ? 1 : 0
200202
depends_on = [module.secrets_manager]
201203

202204
create_duration = "30s"
203205
}
204206

205207
resource "ibm_en_topic" "en_topic" {
206-
count = var.enable_event_notification ? 1 : 0
208+
# if existing SM instance CRN is passed (!= null), then never create EN topic
209+
count = var.existing_secrets_manager_crn == null && var.enable_event_notification ? 1 : 0
207210
depends_on = [time_sleep.wait_for_secrets_manager]
208211
instance_guid = local.existing_en_guid
209212
name = "Secrets Manager Topic"
@@ -218,7 +221,8 @@ resource "ibm_en_topic" "en_topic" {
218221
}
219222

220223
resource "ibm_en_subscription_email" "email_subscription" {
221-
count = var.enable_event_notification && length(var.sm_en_email_list) > 0 ? 1 : 0
224+
# if existing SM instance CRN is passed (!= null), then never create EN email subscription
225+
count = var.existing_secrets_manager_crn == null && var.enable_event_notification && length(var.sm_en_email_list) > 0 ? 1 : 0
222226
instance_guid = local.existing_en_guid
223227
name = "Email for Secrets Manager Subscription"
224228
description = "Subscription for Secret Manager Events"

solutions/standard/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ variable "ibmcloud_kms_api_key" {
249249
variable "enable_event_notification" {
250250
type = bool
251251
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."
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` and `existing_sm_instance_crn` must be null."
253253
}
254254

255255
variable "existing_event_notification_instance_crn" {

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ variable "skip_en_iam_authorization_policy" {
106106
variable "enable_event_notification" {
107107
type = bool
108108
default = false
109-
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."
109+
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` and `existing_sm_instance_crn` must be null."
110110
}
111111

112112
variable "existing_en_instance_crn" {

0 commit comments

Comments
 (0)