Skip to content

Commit be40879

Browse files
authored
fix: renamed existing_kms_crn to existing_kms_instance_crn<br>* removed kms_region as its now programatically detected<br>* renamed existing_resource_group to use_existing_resource_group (#28)
1 parent 44572c2 commit be40879

File tree

7 files changed

+77
-30
lines changed

7 files changed

+77
-30
lines changed

cra-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ CRA_TARGETS:
66
PROFILE_ID: "bfacb71d-4b84-41ac-9825-e8a3a3eb7405" # SCC profile ID (currently set to IBM Cloud Framework for Financial Services 1.6.0 profile).
77
CRA_ENVIRONMENT_VARIABLES:
88
TF_VAR_resource_group_name: "test"
9-
TF_VAR_existing_kms_crn: "XXXX:hs-crypto:XXXXXXX:XXXXX:XXXXX"
9+
TF_VAR_existing_kms_instance_crn: "XXXX:hs-crypto:XXXXXXX:XXXXX:XXXXX"

ibm_catalog.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,51 @@
5858
}
5959
]
6060
},
61+
"configuration" : [
62+
{
63+
"key": "existing_cos_kms_key_crn",
64+
"required": true
65+
},
66+
{
67+
"key": "region",
68+
"required": true,
69+
"default_value": "",
70+
"options": [
71+
{
72+
"displayname": "Dallas (us-south)",
73+
"value": "us-south"
74+
},
75+
{
76+
"displayname": "Frankfurt (eu-de)",
77+
"value": "eu-de"
78+
},
79+
{
80+
"displayname": "London (eu-gb)",
81+
"value": "eu-gb"
82+
},
83+
{
84+
"displayname": "Madrid (eu-es)",
85+
"value": "eu-es"
86+
},
87+
{
88+
"displayname": "Osaka (jp-osa)",
89+
"value": "jp-osa"
90+
},
91+
{
92+
"displayname": "Sydney (au-syd)",
93+
"value": "au-syd"
94+
},
95+
{
96+
"displayname": "Tokyo (jp-tok)",
97+
"value": "jp-tok"
98+
},
99+
{
100+
"displayname": "Washington (us-east)",
101+
"value": "us-east"
102+
}
103+
]
104+
}
105+
],
61106
"architecture": {
62107
"descriptions": "This architecture supports deployment of Log Analysis and Cloud Monitoring instances on IBM Cloud and Activity Tracker event routing to a COS bucket target.",
63108
"features": [
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"ibmcloud_api_key": $VALIDATION_APIKEY,
33
"resource_group_name": $PREFIX,
4-
"existing_kms_crn": $HPCS_US_SOUTH_CRN,
5-
"kms_region": "us-south"
4+
"existing_kms_instance_crn": $HPCS_US_SOUTH_CRN
65
}

solutions/instances/main.tf

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
#######################################################################################################################
44

55
locals {
6-
archive_api_key = var.log_archive_api_key == null ? var.ibmcloud_api_key : var.log_archive_api_key
6+
archive_api_key = var.log_archive_api_key == null ? var.ibmcloud_api_key : var.log_archive_api_key
7+
default_cos_region = var.cos_region != null ? var.cos_region : var.region
78

89
cos_instance_crn = var.existing_cos_instance_crn != null ? var.existing_cos_instance_crn : module.cos_instance[0].cos_instance_crn
9-
existing_kms_guid = var.existing_kms_crn != null ? element(split(":", var.existing_kms_crn), length(split(":", var.existing_kms_crn)) - 3) : length(local.bucket_config_map) == 2 ? null : tobool("The CRN of the existing KMS is not provided.")
10+
existing_kms_guid = var.existing_kms_instance_crn != null ? element(split(":", var.existing_kms_instance_crn), length(split(":", var.existing_kms_instance_crn)) - 3) : length(local.bucket_config_map) == 2 ? null : tobool("The CRN of the existing KMS is not provided.")
1011
cos_instance_guid = var.existing_cos_instance_crn == null ? module.cos_instance[0].cos_instance_guid : element(split(":", var.existing_cos_instance_crn), length(split(":", var.existing_cos_instance_crn)) - 3)
1112
archive_cos_bucket_name = var.existing_log_archive_cos_bucket_name != null ? var.existing_log_archive_cos_bucket_name : module.cos_bucket[0].buckets[var.log_archive_cos_bucket_name].bucket_name
1213
archive_cos_bucket_endpoint = var.existing_log_archive_cos_bucket_endpoint != null ? var.existing_log_archive_cos_bucket_endpoint : module.cos_bucket[0].buckets[var.log_archive_cos_bucket_name].s3_endpoint_private
@@ -44,11 +45,13 @@ locals {
4445
days = 366
4546
} : null
4647

47-
kms_service = var.existing_kms_crn != null ? (
48-
can(regex(".*kms.*", var.existing_kms_crn)) ? "kms" : (
49-
can(regex(".*hs-crypto.*", var.existing_kms_crn)) ? "hs-crypto" : null
48+
kms_service = var.existing_kms_instance_crn != null ? (
49+
can(regex(".*kms.*", var.existing_kms_instance_crn)) ? "kms" : (
50+
can(regex(".*hs-crypto.*", var.existing_kms_instance_crn)) ? "hs-crypto" : null
5051
)
5152
) : null
53+
54+
kms_region = (length(local.bucket_config_map) != 0) ? (var.existing_cos_kms_key_crn == null ? element(split(":", var.existing_kms_instance_crn), length(split(":", var.existing_kms_instance_crn)) - 5) : null) : null
5255
}
5356

5457
#######################################################################################################################
@@ -58,8 +61,8 @@ locals {
5861
module "resource_group" {
5962
source = "terraform-ibm-modules/resource-group/ibm"
6063
version = "1.1.5"
61-
resource_group_name = var.existing_resource_group == false ? var.resource_group_name : null
62-
existing_resource_group_name = var.existing_resource_group == true ? var.resource_group_name : null
64+
resource_group_name = var.use_existing_resource_group == false ? var.resource_group_name : null
65+
existing_resource_group_name = var.use_existing_resource_group == true ? var.resource_group_name : null
6366
}
6467

6568
#######################################################################################################################
@@ -100,7 +103,7 @@ module "observability_instance" {
100103
bucket_name = local.cos_target_bucket_name
101104
endpoint = local.cos_target_bucket_endpoint
102105
instance_id = local.cos_instance_crn
103-
target_region = var.cos_region
106+
target_region = local.default_cos_region
104107
target_name = "cos-target"
105108
skip_atracker_cos_iam_auth_policy = false
106109
service_to_service_enabled = true
@@ -131,7 +134,7 @@ module "kms" {
131134
source = "terraform-ibm-modules/kms-all-inclusive/ibm"
132135
version = "4.8.5"
133136
create_key_protect_instance = false
134-
region = var.kms_region
137+
region = local.kms_region
135138
existing_kms_instance_guid = local.existing_kms_guid
136139
key_ring_endpoint_type = var.kms_endpoint_type
137140
key_endpoint_type = var.kms_endpoint_type
@@ -215,7 +218,7 @@ module "cos_bucket" {
215218
management_endpoint_type = var.management_endpoint_type_for_bucket
216219
storage_class = value.class
217220
resource_instance_id = local.cos_instance_crn
218-
region_location = var.cos_region
221+
region_location = local.default_cos_region
219222
force_delete = true
220223
archive_rule = local.archive_rule
221224
expire_rule = local.expire_rule

solutions/instances/provider.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ provider "logdna" {
2626
provider "ibm" {
2727
alias = "cos"
2828
ibmcloud_api_key = var.ibmcloud_api_key
29-
region = var.cos_region
29+
region = local.default_cos_region
3030
}
3131

3232
provider "ibm" {
3333
alias = "kms"
3434
ibmcloud_api_key = var.ibmcloud_api_key
35-
region = var.kms_region
35+
region = local.kms_region
3636
}

solutions/instances/variables.tf

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ variable "ibmcloud_api_key" {
88
sensitive = true
99
}
1010

11-
variable "existing_resource_group" {
11+
variable "use_existing_resource_group" {
1212
type = bool
1313
description = "Whether to use an existing resource group."
1414
default = false
@@ -23,6 +23,11 @@ variable "region" {
2323
description = "Region where observability resources will be created"
2424
type = string
2525
default = "us-south"
26+
27+
validation {
28+
condition = contains(["us-south", "us-east", "jp-osa", "jp-tok", "eu-de", "eu-es", "eu-gb", "au-syd"], var.region)
29+
error_message = "The specified region is not a valid selection!"
30+
}
2631
}
2732

2833
##############################################################################
@@ -124,8 +129,8 @@ variable "add_bucket_name_suffix" {
124129

125130
variable "cos_region" {
126131
type = string
127-
default = "us-south"
128-
description = "The Cloud Object Storage region."
132+
default = null
133+
description = "The Cloud Object Storage region. If no value is provided, it defaults to the value specified in the 'region' input variable."
129134
}
130135

131136
variable "cos_instance_name" {
@@ -245,16 +250,10 @@ variable "management_endpoint_type_for_bucket" {
245250
# KMS variables
246251
########################################################################################################################
247252

248-
variable "kms_region" {
249-
type = string
250-
default = "us-south"
251-
description = "The region in which KMS instance exists."
252-
}
253-
254-
variable "existing_kms_crn" {
253+
variable "existing_kms_instance_crn" {
255254
type = string
256255
default = null
257-
description = "The CRN of the KMS instance used for the COS bucket root Key. Only required if not supplying an existing KMS root key and if 'skip_cos_kms_auth_policy' is true."
256+
description = "The CRN of the KMS instance used for the COS bucket root Key. Only required if not supplying an existing KMS root key. Not required if existing bucket details are passed as an input."
258257
}
259258

260259
variable "existing_cos_kms_key_crn" {

tests/pr_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ const agentsKubeconfigDir = "solutions/agents/kubeconfig"
3030

3131
// Current supported regions for Observability instances
3232
var validRegions = []string{
33+
"au-syd",
3334
"eu-de",
3435
"eu-es",
3536
"eu-gb",
37+
"jp-osa",
38+
"jp-tok",
3639
"us-south",
3740
"us-east",
3841
}
@@ -76,8 +79,7 @@ func TestInstancesInSchematics(t *testing.T) {
7679
options.TerraformVars = []testschematic.TestSchematicTerraformVar{
7780
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
7881
{Name: "resource_group_name", Value: options.Prefix, DataType: "string"},
79-
{Name: "existing_kms_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
80-
{Name: "kms_region", Value: "us-south", DataType: "string"}, // KMS instance is in us-south
82+
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
8183
{Name: "cos_region", Value: region, DataType: "string"},
8284
{Name: "cos_instance_tags", Value: options.Tags, DataType: "list(string)"},
8385
{Name: "log_analysis_tags", Value: options.Tags, DataType: "list(string)"},
@@ -104,9 +106,8 @@ func TestRunUpgradeSolutionInstances(t *testing.T) {
104106
options.TerraformVars = map[string]interface{}{
105107
"resource_group_name": options.Prefix,
106108
"cos_instance_access_tags": permanentResources["accessTags"],
107-
"existing_kms_crn": permanentResources["hpcs_south_crn"],
109+
"existing_kms_instance_crn": permanentResources["hpcs_south_crn"],
108110
"kms_endpoint_type": "public",
109-
"kms_region": "us-south",
110111
"management_endpoint_type_for_bucket": "public",
111112
"log_analysis_service_endpoints": "public-and-private",
112113
"cloud_monitoring_service_endpoints": "public",

0 commit comments

Comments
 (0)