Skip to content

Commit

Permalink
feat: add optional prefix variable to the DA solution (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
jor2 authored Jun 17, 2024
1 parent d386fdd commit 817437b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
34 changes: 20 additions & 14 deletions solutions/standard/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module "resource_group" {
source = "terraform-ibm-modules/resource-group/ibm"
version = "1.1.6"
resource_group_name = var.use_existing_resource_group == false ? var.resource_group_name : null
resource_group_name = var.use_existing_resource_group == false ? (var.prefix != null ? "${var.prefix}-${var.resource_group_name}" : var.resource_group_name) : null
existing_resource_group_name = var.use_existing_resource_group == true ? var.resource_group_name : null
}

Expand All @@ -20,6 +20,10 @@ locals {
kms_region = length(local.parsed_existing_kms_instance_crn) > 0 ? local.parsed_existing_kms_instance_crn[5] : null
en_kms_key_id = local.existing_kms_root_key_id != null ? local.existing_kms_root_key_id : module.kms[0].keys[format("%s.%s", var.en_key_ring_name, var.en_key_name)].key_id
kms_instance_guid = var.existing_kms_instance_crn != null ? element(split(":", var.existing_kms_instance_crn), length(split(":", var.existing_kms_instance_crn)) - 3) : module.kms[0].kms_instance_guid
en_key_name = var.prefix != null ? "${var.prefix}-${var.en_key_name}" : var.en_key_name
en_key_ring_name = var.prefix != null ? "${var.prefix}-${var.en_key_ring_name}" : var.en_key_ring_name
cos_key_name = var.prefix != null ? "${var.prefix}-${var.cos_key_name}" : var.cos_key_name
cos_key_ring_name = var.prefix != null ? "${var.prefix}-${var.cos_key_ring_name}" : var.cos_key_ring_name
}

# KMS root key for Event Notifications
Expand All @@ -37,12 +41,12 @@ module "kms" {
key_endpoint_type = var.kms_endpoint_type
keys = [
{
key_ring_name = var.en_key_ring_name
key_ring_name = local.en_key_ring_name
existing_key_ring = false
force_delete_key_ring = true
keys = [
{
key_name = var.en_key_name
key_name = local.en_key_name
standard_key = false
rotation_interval_month = 3
dual_auth_delete_enabled = false
Expand All @@ -51,12 +55,12 @@ module "kms" {
]
},
{
key_ring_name = var.cos_key_ring_name
key_ring_name = local.cos_key_ring_name
existing_key_ring = false
force_delete_key_ring = true
keys = [
{
key_name = var.cos_key_name
key_name = local.cos_key_name
standard_key = false
rotation_interval_month = 3
dual_auth_delete_enabled = false
Expand All @@ -73,11 +77,13 @@ module "kms" {

locals {
# tflint-ignore: terraform_unused_declarations
validate_cos_regions = var.cos_bucket_region != null && var.cross_region_location != null ? tobool("Cannot provide values for var.cos_bucket_region and var.cross_region_location") : true
cos_kms_key_crn = var.existing_cos_bucket_name != null ? null : var.existing_kms_root_key_crn != null ? var.existing_kms_root_key_crn : module.kms[0].keys[format("%s.%s", var.cos_key_ring_name, var.cos_key_name)].crn
cos_instance_guid = var.existing_cos_instance_crn != null ? element(split(":", var.existing_cos_instance_crn), length(split(":", var.existing_cos_instance_crn)) - 3) : module.cos.cos_instance_guid
cos_bucket_name = var.existing_cos_bucket_name != null ? var.existing_cos_bucket_name : module.cos.bucket_name
cos_bucket_region = var.cos_bucket_region != null ? var.cos_bucket_region : var.cross_region_location != null ? null : var.region
validate_cos_regions = var.cos_bucket_region != null && var.cross_region_location != null ? tobool("Cannot provide values for var.cos_bucket_region and var.cross_region_location") : true
cos_kms_key_crn = var.existing_cos_bucket_name != null ? null : local.existing_kms_root_key_id != null ? local.existing_kms_root_key_id : module.kms[0].keys[format("%s.%s", var.cos_key_ring_name, var.cos_key_name)].crn
cos_instance_guid = var.existing_cos_instance_crn != null ? element(split(":", var.existing_cos_instance_crn), length(split(":", var.existing_cos_instance_crn)) - 3) : module.cos.cos_instance_guid
cos_bucket_name = var.existing_cos_bucket_name != null ? var.existing_cos_bucket_name : (var.prefix != null ? "${var.prefix}-${var.cos_bucket_name}" : var.cos_bucket_name)
cos_bucket_name_with_suffix = var.existing_cos_bucket_name != null ? var.existing_cos_bucket_name : module.cos.bucket_name
cos_bucket_region = var.cos_bucket_region != null ? var.cos_bucket_region : var.cross_region_location != null ? null : var.region
cos_instance_name = var.prefix != null ? "${var.prefix}-${var.cos_instance_name}" : var.cos_instance_name
}

module "cos" {
Expand All @@ -91,10 +97,10 @@ module "cos" {
resource_group_id = module.resource_group.resource_group_id
region = local.cos_bucket_region
cross_region_location = var.cross_region_location
cos_instance_name = var.cos_instance_name
cos_instance_name = local.cos_instance_name
cos_plan = var.cos_plan
cos_tags = var.cos_instance_tags
bucket_name = var.cos_bucket_name
bucket_name = local.cos_bucket_name
access_tags = var.cos_instance_access_tags
management_endpoint_type_for_bucket = var.management_endpoint_type_for_bucket
existing_kms_instance_guid = local.kms_instance_guid
Expand All @@ -120,7 +126,7 @@ module "event_notifications" {
source = "../.."
resource_group_id = module.resource_group.resource_group_id
region = var.region
name = var.event_notification_name
name = var.prefix != null ? "${var.prefix}-${var.event_notification_name}" : var.event_notification_name
plan = var.service_plan
tags = var.tags
service_endpoints = var.service_endpoints
Expand All @@ -134,7 +140,7 @@ module "event_notifications" {
# COS Related
cos_integration_enabled = true
cos_destination_name = var.cos_destination_name
cos_bucket_name = local.cos_bucket_name
cos_bucket_name = local.cos_bucket_name_with_suffix
cos_instance_id = local.cos_instance_guid
skip_en_cos_auth_policy = var.skip_en_cos_auth_policy
cos_endpoint = local.cos_endpoint
Expand Down
22 changes: 14 additions & 8 deletions solutions/standard/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ variable "use_existing_resource_group" {

variable "resource_group_name" {
type = string
description = "The name of a new or an existing resource group in which Event Notifications resources are provisioned."
description = "The name of a new or an existing resource group in which to provision the Databases for Elasicsearch in. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
}

variable "region" {
Expand All @@ -32,6 +32,12 @@ variable "existing_monitoring_crn" {
description = "(Optional) The CRN of an existing IBM Cloud Monitoring instance. It is used to monitor the IBM Cloud Object Storage bucket that is used for storing failed events."
}

variable "prefix" {
type = string
description = "(Optional) Prefix to add to all resources created by this solution."
default = null
}

########################################################################################################################
# Event Notifications
########################################################################################################################
Expand All @@ -49,7 +55,7 @@ variable "service_credential_names" {

variable "event_notification_name" {
type = string
description = "The name of the Event Notifications instance that is created by this solution."
description = "The name of the Event Notifications instance that is created by this solution. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
default = "base-event-notifications"
}

Expand Down Expand Up @@ -113,25 +119,25 @@ variable "kms_endpoint_type" {
variable "en_key_ring_name" {
type = string
default = "en-key-ring"
description = "The name of the key ring which will be created for the Event Notifications instance. Not used if supplying an existing key."
description = "The name of the key ring which will be created for the Event Notifications instance. Not used if supplying an existing key. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
}

variable "en_key_name" {
type = string
default = "en-key"
description = "The name for the key that will be created for the Event Notifications. Not used if an existing key is specfied."
description = "The name for the key that will be created for the Event Notifications. Not used if an existing key is specfied. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
}

variable "cos_key_ring_name" {
type = string
default = "en-cos-key-ring"
description = "The name of the key ring which will be created for Object Storage. Not used if supplying an existing key or if `existing_cos_bucket_name` is specified."
description = "The name of the key ring which will be created for Object Storage. Not used if supplying an existing key or if `existing_cos_bucket_name` is specified. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
}

variable "cos_key_name" {
type = string
default = "en-cos-key"
description = "The name of the key which will be created for the Event Notifications. Not used if supplying an existing key."
description = "The name of the key which will be created for the Event Notifications. Not used if supplying an existing key. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
}

variable "skip_en_kms_auth_policy" {
Expand Down Expand Up @@ -166,7 +172,7 @@ variable "cos_destination_name" {

variable "cos_bucket_name" {
type = string
description = "The name to use when creating the Object Storage bucket for the storage of failed delivery events. Bucket names are globally unique. If `add_bucket_name_suffix` is set to `true`, a random 4 character string is added to this name to help ensure that the bucket name is unique."
description = "The name to use when creating the Object Storage bucket for the storage of failed delivery events. Bucket names are globally unique. If `add_bucket_name_suffix` is set to `true`, a random 4 character string is added to this name to help ensure that the bucket name is unique. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
default = "base-event-notifications-bucket"
}

Expand All @@ -185,7 +191,7 @@ variable "skip_cos_kms_auth_policy" {
variable "cos_instance_name" {
type = string
default = "base-security-services-cos"
description = "The name to use when creating the Object Storage instance."
description = "The name to use when creating the Object Storage instance. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
}

variable "cos_instance_tags" {
Expand Down

0 comments on commit 817437b

Please sign in to comment.