Skip to content

Commit 8396201

Browse files
authored
feat: updated the service_credential_secrets input object schema of the DA to support creating service specific roles<br>* The service_credentials_source_service_role attribute has been renamed to service_credentials_source_service_role_crn and now requires a full CRN value. For example: service_credentials_source_service_role_crn = "crn:v1:bluemix:public:iam::::role:Editor" (#473)
1 parent 122511f commit 8396201

File tree

4 files changed

+30
-35
lines changed

4 files changed

+30
-35
lines changed

solutions/standard/DA-types.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ In the configuration, specify the secret group name, whether it already exists o
5555
#### Options for service_credentials
5656

5757
- `secret_name`: (required): A unique human-readable name of the secret to create.
58-
- `service_credentials_source_service_role`: (required): The role to give the service credential in the Databases for MongoDB service. Acceptable values are `Writer`, `Reader`, `Manager`, and `None`
58+
- `service_credentials_source_service_role_crn`: (required): The CRN of the role to give the service credential in the IBM Cloud Database service. Service credentials role CRNs can be found at https://cloud.ibm.com/iam/roles, select the IBM Cloud Database and select the role.
5959
- `secret_labels`: (optional, default = `[]`): Labels of the secret to create. Up to 30 labels can be created. Labels can be 2 - 30 characters, including spaces. Special characters that are not permitted include the angled brackets (<>), comma (,), colon (:), ampersand (&), and vertical pipe character (|).
6060
- `secret_auto_rotation`: (optional, default = `true`): Whether to configure automatic rotation of service credential.
6161
- `secret_auto_rotation_unit`: (optional, default = `day`): Specifies the unit of time for rotation of a secret. Acceptable values are `day` or `month`.
@@ -72,8 +72,8 @@ The following example includes all the configuration options for four service cr
7272
"service_credentials": [ # pragma: allowlist secret
7373
{
7474
"secret_name": "cred-1"
75-
"service_credentials_source_service_role": "Writer"
76-
"secret_labels": ["test-writer-1", "test-writer-2"]
75+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::role:Editor"
76+
"secret_labels": ["test-editor-1", "test-editor-2"]
7777
"secret_auto_rotation": true
7878
"secret_auto_rotation_unit": "day"
7979
"secret_auto_rotation_interval": 89
@@ -82,7 +82,7 @@ The following example includes all the configuration options for four service cr
8282
},
8383
{
8484
"secret_name": "cred-2"
85-
"service_credentials_source_service_role": "Reader"
85+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::role:Viewer"
8686
}
8787
]
8888
},
@@ -91,11 +91,7 @@ The following example includes all the configuration options for four service cr
9191
"service_credentials": [ # pragma: allowlist secret
9292
{
9393
"secret_name": "cred-3"
94-
"service_credentials_source_service_role": "Editor"
95-
},
96-
{
97-
"secret_name": "cred-4"
98-
"service_credentials_source_service_role": "None"
94+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::role:Viewer"
9995
}
10096
]
10197
}

solutions/standard/main.tf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,16 @@ locals {
299299
existing_secret_group = service_credentials.existing_secret_group
300300
secrets = [
301301
for secret in service_credentials.service_credentials : {
302-
secret_name = secret.secret_name
303-
secret_labels = secret.secret_labels
304-
secret_auto_rotation = secret.secret_auto_rotation
305-
secret_auto_rotation_unit = secret.secret_auto_rotation_unit
306-
secret_auto_rotation_interval = secret.secret_auto_rotation_interval
307-
service_credentials_ttl = secret.service_credentials_ttl
308-
service_credential_secret_description = secret.service_credential_secret_description
309-
service_credentials_source_service_role = secret.service_credentials_source_service_role
310-
service_credentials_source_service_crn = module.mongodb.crn
311-
secret_type = "service_credentials" #checkov:skip=CKV_SECRET_6
302+
secret_name = secret.secret_name
303+
secret_labels = secret.secret_labels
304+
secret_auto_rotation = secret.secret_auto_rotation
305+
secret_auto_rotation_unit = secret.secret_auto_rotation_unit
306+
secret_auto_rotation_interval = secret.secret_auto_rotation_interval
307+
service_credentials_ttl = secret.service_credentials_ttl
308+
service_credential_secret_description = secret.service_credential_secret_description
309+
service_credentials_source_service_role_crn = secret.service_credentials_source_service_role_crn
310+
service_credentials_source_service_crn = module.mongodb.crn
311+
secret_type = "service_credentials" #checkov:skip=CKV_SECRET_6
312312
}
313313
]
314314
}
@@ -326,7 +326,7 @@ module "secrets_manager_service_credentials" {
326326
count = length(local.service_credential_secrets) > 0 ? 1 : 0
327327
depends_on = [time_sleep.wait_for_mongodb_authorization_policy]
328328
source = "terraform-ibm-modules/secrets-manager/ibm//modules/secrets"
329-
version = "1.19.10"
329+
version = "1.22.0"
330330
existing_sm_instance_guid = local.existing_secrets_manager_instance_guid
331331
existing_sm_instance_region = local.existing_secrets_manager_instance_region
332332
endpoint_type = var.existing_secrets_manager_endpoint_type

solutions/standard/variables.tf

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -277,30 +277,29 @@ variable "service_credential_secrets" {
277277
secret_group_description = optional(string)
278278
existing_secret_group = optional(bool)
279279
service_credentials = list(object({
280-
secret_name = string
281-
service_credentials_source_service_role = string
282-
secret_labels = optional(list(string))
283-
secret_auto_rotation = optional(bool)
284-
secret_auto_rotation_unit = optional(string)
285-
secret_auto_rotation_interval = optional(number)
286-
service_credentials_ttl = optional(string)
287-
service_credential_secret_description = optional(string)
280+
secret_name = string
281+
service_credentials_source_service_role_crn = string
282+
secret_labels = optional(list(string))
283+
secret_auto_rotation = optional(bool)
284+
secret_auto_rotation_unit = optional(string)
285+
secret_auto_rotation_interval = optional(number)
286+
service_credentials_ttl = optional(string)
287+
service_credential_secret_description = optional(string)
288288

289289
}))
290290
}))
291291
default = []
292292
description = "Service credential secrets configuration for Databases for MongoDB. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-icd-mongodb/tree/main/solutions/standard/DA-types.md#service-credential-secrets)."
293293

294294
validation {
295+
# Service roles CRNs can be found at https://cloud.ibm.com/iam/roles, select the IBM Cloud Database and select the role
295296
condition = alltrue([
296297
for group in var.service_credential_secrets : alltrue([
297-
for credential in group.service_credentials : contains(
298-
["Writer", "Reader", "Manager", "None"], credential.service_credentials_source_service_role
299-
)
298+
# crn:v?:bluemix; two non-empty segments; three possibly empty segments; :serviceRole or role: non-empty segment
299+
for credential in group.service_credentials : can(regex("^crn:v[0-9]:bluemix(:..*){2}(:.*){3}:(serviceRole|role):..*$", credential.service_credentials_source_service_role_crn))
300300
])
301301
])
302-
error_message = "service_credentials_source_service_role role must be one of 'Writer', 'Reader', 'Manager', and 'None'."
303-
302+
error_message = "service_credentials_source_service_role_crn must be a serviceRole CRN. See https://cloud.ibm.com/iam/roles"
304303
}
305304
}
306305

tests/pr_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ func TestRunStandardSolutionSchematics(t *testing.T) {
134134
"service_credentials": []map[string]string{
135135
{
136136
"secret_name": fmt.Sprintf("%s-cred-reader", options.Prefix),
137-
"service_credentials_source_service_role": "Reader",
137+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::role:Viewer",
138138
},
139139
{
140140
"secret_name": fmt.Sprintf("%s-cred-writer", options.Prefix),
141-
"service_credentials_source_service_role": "Writer",
141+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::role:Editor",
142142
},
143143
},
144144
},

0 commit comments

Comments
 (0)