Skip to content

Commit 6564e06

Browse files
authored
feat: added support to optionally use an existing KMS instance by adding new optional input variable existing_kms_instance_crn. If not value passed, a new Key Protect instance gets created (#64)
1 parent 67b77ed commit 6564e06

File tree

3 files changed

+71
-5
lines changed

3 files changed

+71
-5
lines changed

ibm_catalog.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@
204204
"description": "Whether to provision logging and monitoring instances are configured to receive all platform logs and metrics in the target region. There can only be one instance per region provisioned for platform logs/metrics.",
205205
"required": false
206206
},
207+
{
208+
"key": "existing_kms_instance_crn",
209+
"type": "string",
210+
"default_value": "__NULL__",
211+
"description": "The CRN of an existing KMS instance to use in this solution. If not set, a new Key Protect instance is provisioned.",
212+
"required": false
213+
},
207214
{
208215
"key": "en_email_list",
209216
"type": "array",

stack_definition.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,22 @@
3232
"default": true,
3333
"custom_config": {}
3434
},
35+
{
36+
"name": "existing_kms_instance_crn",
37+
"required": false,
38+
"type": "string",
39+
"hidden": false,
40+
"default": "__NULL__",
41+
"custom_config": {}
42+
},
3543
{
3644
"name": "en_email_list",
3745
"required": false,
3846
"type": "array",
3947
"hidden": false,
4048
"default": [],
4149
"custom_config": {}
50+
4251
},
4352
{
4453
"name": "existing_secrets_manager_crn",
@@ -76,6 +85,10 @@
7685
"name": "use_existing_resource_group",
7786
"value": true
7887
},
88+
{
89+
"name": "existing_kms_instance_crn",
90+
"value": "ref:../../inputs/existing_kms_instance_crn"
91+
},
7992
{
8093
"name": "region",
8194
"value": "ref:../../inputs/region"
@@ -86,7 +99,7 @@
8699
}
87100
],
88101
"name": "1a - Key management",
89-
"version_locator": "7a4d68b4-cf8b-40cd-a3d1-f49aff526eb3.e7f105c4-8af4-4238-a98d-e89999ff14c8-global"
102+
"version_locator": "7a4d68b4-cf8b-40cd-a3d1-f49aff526eb3.4a3affda-ffc6-4d14-a4f7-aeeb2b80908c-global"
90103
},
91104
{
92105
"inputs": [
@@ -164,7 +177,7 @@
164177
},
165178
{
166179
"name": "kms_endpoint_url",
167-
"value": "ref:../../members/1a - Key management/outputs/kp_private_endpoint"
180+
"value": "ref:../../members/1a - Key management/outputs/kms_private_endpoint"
168181
},
169182
{
170183
"name": "existing_kms_instance_crn",

tests/pr_test.go

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
11
package tests
22

33
import (
4+
"log"
5+
"os"
6+
"testing"
7+
48
"github.com/stretchr/testify/assert"
9+
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/common"
510
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testprojects"
6-
"testing"
711
)
812

913
// Use existing resource group
1014
const resourceGroup = "geretain-test-resources"
1115

12-
func TestProjectsFullTest(t *testing.T) {
16+
// Define a struct with fields that match the structure of the YAML data
17+
const yamlLocation = "../common-dev-assets/common-go-assets/common-permanent-resources.yaml"
18+
19+
var permanentResources map[string]interface{}
20+
21+
func TestMain(m *testing.M) {
22+
// Read the YAML file contents
23+
var err error
24+
permanentResources, err = common.LoadMapFromYaml(yamlLocation)
25+
if err != nil {
26+
log.Fatal(err)
27+
}
1328

29+
os.Exit(m.Run())
30+
}
31+
32+
func TestProjectsFullTest(t *testing.T) {
33+
t.Parallel()
1434
options := testprojects.TestProjectOptionsDefault(&testprojects.TestProjectsOptions{
1535
Testing: t,
1636
Prefix: "cs", // setting prefix here gets a random string appended to it
@@ -21,7 +41,6 @@ func TestProjectsFullTest(t *testing.T) {
2141
"prefix": options.Prefix,
2242
"existing_resource_group_name": resourceGroup,
2343
"sm_service_plan": "trial",
24-
"use_existing_resource_group": false,
2544
"ibmcloud_api_key": options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], // always required by the stack
2645
"enable_platform_logs_metrics": false,
2746
}
@@ -33,3 +52,30 @@ func TestProjectsFullTest(t *testing.T) {
3352
t.Error("TestProjectsFullTest Failed")
3453
}
3554
}
55+
56+
func TestProjectsExistingResourcesTest(t *testing.T) {
57+
t.Parallel()
58+
options := testprojects.TestProjectOptionsDefault(&testprojects.TestProjectsOptions{
59+
Testing: t,
60+
Prefix: "ecs", // setting prefix here gets a random string appended to it
61+
ParallelDeploy: true,
62+
})
63+
64+
options.StackInputs = map[string]interface{}{
65+
"prefix": options.Prefix,
66+
"existing_resource_group_name": resourceGroup,
67+
"ibmcloud_api_key": options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], // always required by the stack
68+
"enable_platform_logs_metrics": false,
69+
// More info: https://github.ibm.com/GoldenEye/issues/issues/9709#issuecomment-83874969
70+
// "existing_secrets_manager_crn": permanentResources["secretsManagerCRN"],
71+
"sm_service_plan": "trial",
72+
"existing_kms_instance_crn": permanentResources["hpcs_south_crn"],
73+
}
74+
75+
err := options.RunProjectsTest()
76+
if assert.NoError(t, err) {
77+
t.Log("TestProjectsExistingResourcesTest Passed")
78+
} else {
79+
t.Error("TestProjectsExistingResourcesTest Failed")
80+
}
81+
}

0 commit comments

Comments
 (0)