Skip to content

Commit 9895e5a

Browse files
authored
fix: fix issue that was causing secrets manager managed service credential re-creation<br><br>NOTE: When upgrading from previous version, you will see the following destroy and re-create, however there is no impact to any deployed infrastructure: (#646)
1 parent af28d1f commit 9895e5a

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

solutions/fully-configurable/main.tf

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ resource "time_sleep" "wait_for_mongodb_authorization_policy" {
348348
count = local.create_secrets_manager_auth_policy
349349
depends_on = [ibm_iam_authorization_policy.secrets_manager_key_manager]
350350
create_duration = "30s"
351+
triggers = {
352+
secrets_manager_region = local.existing_secrets_manager_instance_region
353+
secrets_manager_guid = local.existing_secrets_manager_instance_guid
354+
}
351355
}
352356

353357
locals {
@@ -393,12 +397,12 @@ locals {
393397
}
394398

395399
module "secrets_manager_service_credentials" {
396-
count = length(local.service_credential_secrets) > 0 ? 1 : 0
397-
depends_on = [time_sleep.wait_for_mongodb_authorization_policy]
398-
source = "terraform-ibm-modules/secrets-manager/ibm//modules/secrets"
399-
version = "2.10.2"
400-
existing_sm_instance_guid = local.existing_secrets_manager_instance_guid
401-
existing_sm_instance_region = local.existing_secrets_manager_instance_region
400+
count = length(local.service_credential_secrets) > 0 ? 1 : 0
401+
source = "terraform-ibm-modules/secrets-manager/ibm//modules/secrets"
402+
version = "2.10.2"
403+
# converted into implicit dependency and removed explicit depends_on time_sleep.wait_for_mongodb_authorization_policy for this module because of issue https://github.com/terraform-ibm-modules/terraform-ibm-icd-redis/issues/608
404+
existing_sm_instance_guid = local.create_secrets_manager_auth_policy > 0 ? time_sleep.wait_for_mongodb_authorization_policy[0].triggers["secrets_manager_guid"] : local.existing_secrets_manager_instance_guid
405+
existing_sm_instance_region = local.create_secrets_manager_auth_policy > 0 ? time_sleep.wait_for_mongodb_authorization_policy[0].triggers["secrets_manager_region"] : local.existing_secrets_manager_instance_region
402406
endpoint_type = var.existing_secrets_manager_endpoint_type
403407
secrets = local.secrets
404408
}

tests/pr_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package test
33

44
import (
5+
"encoding/json"
56
"fmt"
67
"log"
78
"math/rand"
@@ -136,15 +137,47 @@ func TestRunSecurityEnforcedUpgradeSolutionSchematics(t *testing.T) {
136137
CheckApplyResultForUpgrade: true,
137138
})
138139

140+
serviceCredentialSecrets := []map[string]any{
141+
{
142+
"secret_group_name": fmt.Sprintf("%s-secret-group", options.Prefix),
143+
"service_credentials": []map[string]string{
144+
{
145+
"secret_name": fmt.Sprintf("%s-cred-reader", options.Prefix),
146+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::role:Viewer",
147+
},
148+
{
149+
"secret_name": fmt.Sprintf("%s-cred-writer", options.Prefix),
150+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::role:Editor",
151+
},
152+
},
153+
},
154+
}
155+
156+
serviceCredentialNames := map[string]string{
157+
"admin": "Administrator",
158+
"user1": "Viewer",
159+
"user2": "Editor",
160+
}
161+
162+
serviceCredentialNamesJSON, err := json.Marshal(serviceCredentialNames)
163+
if err != nil {
164+
log.Fatalf("Error converting to JSON: %s", err)
165+
}
166+
139167
options.TerraformVars = []testschematic.TestSchematicTerraformVar{
140168
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
141169
{Name: "prefix", Value: options.Prefix, DataType: "string"},
142170
{Name: "deletion_protection", Value: false, DataType: "bool"},
143171
{Name: "existing_resource_group_name", Value: resourceGroup, DataType: "string"},
144172
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
173+
{Name: "existing_secrets_manager_instance_crn", Value: permanentResources["secretsManagerCRN"], DataType: "string"},
174+
{Name: "service_credential_secrets", Value: serviceCredentialSecrets, DataType: "list(object)"},
175+
{Name: "service_credential_names", Value: string(serviceCredentialNamesJSON), DataType: "map(string)"},
176+
{Name: "admin_pass_secrets_manager_secret_name", Value: options.Prefix, DataType: "string"},
177+
{Name: "admin_pass_secrets_manager_secret_group", Value: fmt.Sprintf("mongodb-%s-admin-secrets", options.Prefix), DataType: "string"},
145178
}
146179

147-
err := options.RunSchematicUpgradeTest()
180+
err = options.RunSchematicUpgradeTest()
148181
assert.Nil(t, err, "This should not have errored")
149182
}
150183

0 commit comments

Comments
 (0)