Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Commit 32a3bba

Browse files
authored
feat: removed kms_region variable - its now programmtically determined<br>- existing_kms_guid has been renamed existing_kms_instance_crn<br>- existing_resource_group has been renamed use_existing_resource_group (#52)
1 parent 7423c64 commit 32a3bba

File tree

8 files changed

+33
-32
lines changed

8 files changed

+33
-32
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_guid: "XXXXXXXXXXXXXXXX"
9+
TF_VAR_existing_kms_instance_crn: "crn:v1:bluemix:public:hs-crypto:us-south:a/xxx:xxxx::"

ibm_catalog.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
}
5656
]
5757
},
58+
"configuration" : [
59+
{
60+
"key": "existing_scc_cos_kms_key_crn",
61+
"required": true
62+
}
63+
],
5864
"iam_permissions": [
5965
{
6066
"service_name": "compliance",

solutions/instances/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,12 @@ No resources.
4646
| <a name="input_existing_activity_tracker_crn"></a> [existing\_activity\_tracker\_crn](#input\_existing\_activity\_tracker\_crn) | (Optional) The CRN of an existing Activity Tracker instance. Used to send SCC COS bucket log data and all object write events to Activity Tracker. Only used if not supplying an existing COS bucket. | `string` | `null` | no |
4747
| <a name="input_existing_cos_instance_crn"></a> [existing\_cos\_instance\_crn](#input\_existing\_cos\_instance\_crn) | The CRN of an existing Cloud Object Storage instance. If not supplied, a new instance will be created. | `string` | `null` | no |
4848
| <a name="input_existing_en_crn"></a> [existing\_en\_crn](#input\_existing\_en\_crn) | (Optional) The CRN of an existing Event Notification instance. Used to integrate with SCC. | `string` | `null` | no |
49-
| <a name="input_existing_kms_guid"></a> [existing\_kms\_guid](#input\_existing\_kms\_guid) | The GUID of of the KMS instance used for the SCC COS bucket root Key. Only required if not supplying an existing KMS root key and if 'skip\_cos\_kms\_auth\_policy' is true. | `string` | `null` | no |
49+
| <a name="input_existing_kms_instance_crn"></a> [existing\_kms\_instance\_crn](#input\_existing\_kms\_instance\_crn) | The CRN of the existed Hyper Protect Crypto Services or Key Protect instance. Only required if not supplying an existing KMS root key and if 'skip\_cos\_kms\_auth\_policy' is true. | `string` | `null` | no |
5050
| <a name="input_existing_monitoring_crn"></a> [existing\_monitoring\_crn](#input\_existing\_monitoring\_crn) | (Optional) The CRN of an existing IBM Cloud Monitoring instance. Used to send all COS bucket request and usage metrics to, as well as SCC workload protection data. Ignored if using existing COS bucket and not provisioning SCC workload protection. | `string` | `null` | no |
51-
| <a name="input_existing_resource_group"></a> [existing\_resource\_group](#input\_existing\_resource\_group) | Whether to use an existing resource group. | `bool` | `false` | no |
5251
| <a name="input_existing_scc_cos_bucket_name"></a> [existing\_scc\_cos\_bucket\_name](#input\_existing\_scc\_cos\_bucket\_name) | The name of an existing bucket inside the existing Cloud Object Storage instance to use for SCC. If not supplied, a new bucket will be created. | `string` | `null` | no |
53-
| <a name="input_existing_scc_cos_kms_key_crn"></a> [existing\_scc\_cos\_kms\_key\_crn](#input\_existing\_scc\_cos\_kms\_key\_crn) | The CRN of an existing KMS key to be used to encrypt the SCC COS bucket. If not supplied, a new key ring and key will be created in the provided KMS instance. | `string` | `null` | no |
52+
| <a name="input_existing_scc_cos_kms_key_crn"></a> [existing\_scc\_cos\_kms\_key\_crn](#input\_existing\_scc\_cos\_kms\_key\_crn) | The CRN of an existing KMS key to be used to encrypt the SCC COS bucket. If no value is passed, a value must be passed for either 'var.existing\_kms\_instance\_crn' if you want to create a new key ring and key, or 'var.existing\_scc\_cos\_bucket\_name' if you want to use an existing bucket. | `string` | `null` | no |
5453
| <a name="input_ibmcloud_api_key"></a> [ibmcloud\_api\_key](#input\_ibmcloud\_api\_key) | The API Key to use for IBM Cloud. | `string` | n/a | yes |
5554
| <a name="input_kms_endpoint_type"></a> [kms\_endpoint\_type](#input\_kms\_endpoint\_type) | The type of endpoint to be used for commincating with the KMS instance. Allowed values are: 'public' or 'private' (default) | `string` | `"private"` | no |
56-
| <a name="input_kms_region"></a> [kms\_region](#input\_kms\_region) | The region in which KMS instance exists. | `string` | `"us-south"` | no |
5755
| <a name="input_management_endpoint_type_for_bucket"></a> [management\_endpoint\_type\_for\_bucket](#input\_management\_endpoint\_type\_for\_bucket) | The type of endpoint for the IBM terraform provider to use to manage COS buckets. (`public`, `private` or `direct`). Ensure to enable virtual routing and forwarding (VRF) in your account if using `private`, and that the terraform runtime has access to the the IBM Cloud private network. | `string` | `"private"` | no |
5856
| <a name="input_provision_scc_workload_protection"></a> [provision\_scc\_workload\_protection](#input\_provision\_scc\_workload\_protection) | Whether to provision an SCC Workload Protection instance. | `bool` | `true` | no |
5957
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | The name of a new or an existing resource group in which to provision resources to. | `string` | n/a | yes |
@@ -74,6 +72,7 @@ No resources.
7472
| <a name="input_scc_wp_service_plan"></a> [scc\_wp\_service\_plan](#input\_scc\_wp\_service\_plan) | SCC Workload Protection instance service pricing plan. Allowed values are: `free-trial` or `graduated-tier`. | `string` | `"graduated-tier"` | no |
7573
| <a name="input_skip_cos_kms_auth_policy"></a> [skip\_cos\_kms\_auth\_policy](#input\_skip\_cos\_kms\_auth\_policy) | Set to true to skip the creation of an IAM authorization policy that permits the COS instance created to read the encryption key from the KMS instance. WARNING: An authorization policy must exist before an encrypted bucket can be created | `bool` | `false` | no |
7674
| <a name="input_skip_scc_cos_auth_policy"></a> [skip\_scc\_cos\_auth\_policy](#input\_skip\_scc\_cos\_auth\_policy) | Set to true to skip the creation of an IAM authorization policy that permits the SCC instance created by this solution write access to the COS instance. Only used if `provision_scc_instance` is set to true. | `bool` | `false` | no |
75+
| <a name="input_use_existing_resource_group"></a> [use\_existing\_resource\_group](#input\_use\_existing\_resource\_group) | Whether to use an existing resource group. | `bool` | `false` | no |
7776

7877
### Outputs
7978

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_guid": $HPCS_US_SOUTH_GUID,
5-
"kms_region": "us-south"
4+
"existing_kms_instance_crn": $HPCS_US_SOUTH_CRN
65
}

solutions/instances/main.tf

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
locals {
66
# tflint-ignore: terraform_unused_declarations
7-
validate_inputs = var.existing_scc_cos_bucket_name == null && var.existing_scc_cos_kms_key_crn == null && var.existing_kms_guid == null ? tobool("A value must be passed for 'existing_kms_guid' if not supplying any value for 'existing_scc_cos_kms_key_crn' or 'existing_scc_cos_bucket_name'.") : true
7+
validate_inputs = var.existing_scc_cos_bucket_name == null && var.existing_scc_cos_kms_key_crn == null && var.existing_kms_instance_crn == null ? tobool("A value must be passed for 'existing_kms_instance_crn' if not supplying any value for 'existing_scc_cos_kms_key_crn' or 'existing_scc_cos_bucket_name'.") : true
88
# tflint-ignore: terraform_unused_declarations
99
validate_cos_inputs = var.existing_scc_cos_bucket_name != null && var.existing_scc_cos_kms_key_crn != null ? tobool("A value should not be passed for 'existing_scc_cos_kms_key_crn' when passing a value for 'existing_scc_cos_bucket_name'. A key is only needed when creating a new COS bucket.") : true
1010
# tflint-ignore: terraform_unused_declarations
@@ -18,14 +18,20 @@ locals {
1818
module "resource_group" {
1919
source = "terraform-ibm-modules/resource-group/ibm"
2020
version = "1.1.5"
21-
resource_group_name = var.existing_resource_group == false ? var.resource_group_name : null
22-
existing_resource_group_name = var.existing_resource_group == true ? var.resource_group_name : null
21+
resource_group_name = var.use_existing_resource_group == false ? var.resource_group_name : null
22+
existing_resource_group_name = var.use_existing_resource_group == true ? var.resource_group_name : null
2323
}
2424

2525
#######################################################################################################################
2626
# KMS Key
2727
#######################################################################################################################
2828

29+
locals {
30+
parsed_existing_kms_instance_crn = var.existing_kms_instance_crn != null ? split(":", var.existing_kms_instance_crn) : []
31+
kms_region = length(local.parsed_existing_kms_instance_crn) > 0 ? local.parsed_existing_kms_instance_crn[5] : null
32+
existing_kms_guid = length(local.parsed_existing_kms_instance_crn) > 0 ? local.parsed_existing_kms_instance_crn[7] : null
33+
}
34+
2935
# KMS root key for SCC COS bucket
3036
module "kms" {
3137
providers = {
@@ -35,8 +41,8 @@ module "kms" {
3541
source = "terraform-ibm-modules/kms-all-inclusive/ibm"
3642
version = "4.8.5"
3743
create_key_protect_instance = false
38-
region = var.kms_region
39-
existing_kms_instance_guid = var.existing_kms_guid
44+
region = local.kms_region
45+
existing_kms_instance_guid = local.existing_kms_guid
4046
key_ring_endpoint_type = var.kms_endpoint_type
4147
key_endpoint_type = var.kms_endpoint_type
4248
keys = [
@@ -99,7 +105,7 @@ module "cos" {
99105
add_bucket_name_suffix = var.add_bucket_name_suffix
100106
bucket_name = var.scc_cos_bucket_name
101107
kms_encryption_enabled = true
102-
kms_guid = var.existing_kms_guid
108+
kms_guid = local.existing_kms_guid
103109
kms_key_crn = local.scc_cos_kms_key_crn
104110
skip_iam_authorization_policy = var.skip_cos_kms_auth_policy
105111
management_endpoint_type = var.management_endpoint_type_for_bucket

solutions/instances/provider.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ provider "ibm" {
1010
provider "ibm" {
1111
alias = "kms"
1212
ibmcloud_api_key = var.ibmcloud_api_key
13-
region = var.kms_region
13+
region = local.kms_region
1414
}
1515

1616
provider "ibm" {

solutions/instances/variables.tf

Lines changed: 4 additions & 10 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
@@ -30,22 +30,16 @@ variable "existing_monitoring_crn" {
3030
# KMS variables
3131
########################################################################################################################
3232

33-
variable "kms_region" {
34-
type = string
35-
default = "us-south"
36-
description = "The region in which KMS instance exists."
37-
}
38-
39-
variable "existing_kms_guid" {
33+
variable "existing_kms_instance_crn" {
4034
type = string
4135
default = null
42-
description = "The GUID of of the KMS instance used for the SCC COS bucket root Key. Only required if not supplying an existing KMS root key and if 'skip_cos_kms_auth_policy' is true."
36+
description = "The CRN of the existed Hyper Protect Crypto Services or Key Protect instance. Only required if not supplying an existing KMS root key and if 'skip_cos_kms_auth_policy' is true."
4337
}
4438

4539
variable "existing_scc_cos_kms_key_crn" {
4640
type = string
4741
default = null
48-
description = "The CRN of an existing KMS key to be used to encrypt the SCC COS bucket. If not supplied, a new key ring and key will be created in the provided KMS instance."
42+
description = "The CRN of an existing KMS key to be used to encrypt the SCC COS bucket. If no value is passed, a value must be passed for either 'var.existing_kms_instance_crn' if you want to create a new key ring and key, or 'var.existing_scc_cos_bucket_name' if you want to use an existing bucket."
4943
}
5044

5145
variable "kms_endpoint_type" {

tests/pr_test.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ func TestInstancesInSchematics(t *testing.T) {
6969
options.TerraformVars = []testschematic.TestSchematicTerraformVar{
7070
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
7171
{Name: "resource_group_name", Value: options.Prefix, DataType: "string"},
72-
{Name: "existing_kms_guid", Value: permanentResources["hpcs_south"], DataType: "string"},
73-
{Name: "kms_region", Value: "us-south", DataType: "string"}, // KMS instance is in us-south
72+
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
7473
{Name: "scc_region", Value: region, DataType: "string"},
7574
{Name: "cos_region", Value: region, DataType: "string"},
7675
{Name: "cos_instance_tags", Value: options.Tags, DataType: "list(string)"},
@@ -97,9 +96,8 @@ func TestRunUpgradeInstances(t *testing.T) {
9796

9897
options.TerraformVars = map[string]interface{}{
9998
"resource_group_name": options.Prefix,
100-
"existing_kms_guid": permanentResources["hpcs_south"],
99+
"existing_kms_instance_crn": permanentResources["hpcs_south_crn"],
101100
"kms_endpoint_type": "public",
102-
"kms_region": "us-south",
103101
"management_endpoint_type_for_bucket": "public",
104102
}
105103

@@ -163,7 +161,7 @@ func TestRunExistingResourcesInstances(t *testing.T) {
163161
"cos_region": region,
164162
"scc_region": region,
165163
"resource_group_name": terraform.Output(t, existingTerraformOptions, "resource_group_name"),
166-
"existing_resource_group": true,
164+
"use_existing_resource_group": true,
167165
"existing_monitoring_crn": terraform.Output(t, existingTerraformOptions, "monitoring_crn"),
168166
"existing_scc_cos_bucket_name": terraform.Output(t, existingTerraformOptions, "bucket_name"),
169167
"existing_cos_instance_crn": terraform.Output(t, existingTerraformOptions, "cos_crn"),
@@ -189,10 +187,9 @@ func TestRunExistingResourcesInstances(t *testing.T) {
189187
"cos_region": region,
190188
"scc_region": region,
191189
"resource_group_name": terraform.Output(t, existingTerraformOptions, "resource_group_name"),
192-
"existing_resource_group": true,
190+
"use_existing_resource_group": true,
193191
"existing_monitoring_crn": terraform.Output(t, existingTerraformOptions, "monitoring_crn"),
194-
"existing_kms_guid": permanentResources["hpcs_south"],
195-
"kms_region": "us-south",
192+
"existing_kms_instance_crn": permanentResources["hpcs_south_crn"],
196193
"kms_endpoint_type": "public",
197194
"existing_cos_instance_crn": terraform.Output(t, existingTerraformOptions, "cos_crn"),
198195
"management_endpoint_type_for_bucket": "public",

0 commit comments

Comments
 (0)