Skip to content

Commit cd9dd4a

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" (#197)
credential source service role
1 parent 01637aa commit cd9dd4a

File tree

4 files changed

+32
-37
lines changed

4 files changed

+32
-37
lines changed

solutions/standard/DA-types.md

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

5858
- `secret_name`: (required): A unique human-readable name of the secret to create.
59-
- `service_credentials_source_service_role`: (required): The role to give the service credential in the Databases for MySQL service. Acceptable values are `Writer`, `Reader`, `Manager`, and `None`
59+
- `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.
6060
- `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 (|).
6161
- `secret_auto_rotation`: (optional, default = `true`): Whether to configure automatic rotation of service credential.
6262
- `secret_auto_rotation_unit`: (optional, default = `day`): Specifies the unit of time for rotation of a secret. Acceptable values are `day` or `month`.
@@ -70,11 +70,11 @@ The following example includes all the configuration options for four service cr
7070
{
7171
"secret_group_name": "sg-1"
7272
"existing_secret_group": true
73-
"service_credentials": [ # pragma: allowlist secret
73+
"service_credentials": [ # pragma: allowlist secret
7474
{
7575
"secret_name": "cred-1"
76-
"service_credentials_source_service_role": "Writer"
77-
"secret_labels": ["test-writer-1", "test-writer-2"]
76+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::role:Editor"
77+
"secret_labels": ["test-editor-1", "test-editor-2"]
7878
"secret_auto_rotation": true
7979
"secret_auto_rotation_unit": "day"
8080
"secret_auto_rotation_interval": 89
@@ -83,20 +83,16 @@ The following example includes all the configuration options for four service cr
8383
},
8484
{
8585
"secret_name": "cred-2"
86-
"service_credentials_source_service_role": "Reader"
86+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::role:Viewer"
8787
}
8888
]
8989
},
9090
{
9191
"secret_group_name": "sg-2"
92-
"service_credentials": [ # pragma: allowlist secret
92+
"service_credentials": [ # pragma: allowlist secret
9393
{
9494
"secret_name": "cred-3"
95-
"service_credentials_source_service_role": "Editor"
96-
},
97-
{
98-
"secret_name": "cred-4"
99-
"service_credentials_source_service_role": "None"
95+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::role:Viewer"
10096
}
10197
]
10298
}

solutions/standard/main.tf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -298,16 +298,16 @@ locals {
298298
existing_secret_group = service_credentials.existing_secret_group
299299
secrets = [
300300
for secret in service_credentials.service_credentials : {
301-
secret_name = secret.secret_name
302-
secret_labels = secret.secret_labels
303-
secret_auto_rotation = secret.secret_auto_rotation
304-
secret_auto_rotation_unit = secret.secret_auto_rotation_unit
305-
secret_auto_rotation_interval = secret.secret_auto_rotation_interval
306-
service_credentials_ttl = secret.service_credentials_ttl
307-
service_credential_secret_description = secret.service_credential_secret_description
308-
service_credentials_source_service_role = secret.service_credentials_source_service_role
309-
service_credentials_source_service_crn = module.mysql.crn
310-
secret_type = "service_credentials" #checkov:skip=CKV_SECRET_6
301+
secret_name = secret.secret_name
302+
secret_labels = secret.secret_labels
303+
secret_auto_rotation = secret.secret_auto_rotation
304+
secret_auto_rotation_unit = secret.secret_auto_rotation_unit
305+
secret_auto_rotation_interval = secret.secret_auto_rotation_interval
306+
service_credentials_ttl = secret.service_credentials_ttl
307+
service_credential_secret_description = secret.service_credential_secret_description
308+
service_credentials_source_service_role_crn = secret.service_credentials_source_service_role_crn
309+
service_credentials_source_service_crn = module.mysql.crn
310+
secret_type = "service_credentials" #checkov:skip=CKV_SECRET_6
311311
}
312312
]
313313
}
@@ -325,7 +325,7 @@ module "secrets_manager_service_credentials" {
325325
count = length(local.service_credential_secrets) > 0 ? 1 : 0
326326
depends_on = [time_sleep.wait_for_mysql_authorization_policy]
327327
source = "terraform-ibm-modules/secrets-manager/ibm//modules/secrets"
328-
version = "1.19.10"
328+
version = "1.22.0"
329329
existing_sm_instance_guid = local.existing_secrets_manager_instance_guid
330330
existing_sm_instance_region = local.existing_secrets_manager_instance_region
331331
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
@@ -263,30 +263,29 @@ variable "service_credential_secrets" {
263263
secret_group_description = optional(string)
264264
existing_secret_group = optional(bool)
265265
service_credentials = list(object({
266-
secret_name = string
267-
service_credentials_source_service_role = string
268-
secret_labels = optional(list(string))
269-
secret_auto_rotation = optional(bool)
270-
secret_auto_rotation_unit = optional(string)
271-
secret_auto_rotation_interval = optional(number)
272-
service_credentials_ttl = optional(string)
273-
service_credential_secret_description = optional(string)
266+
secret_name = string
267+
service_credentials_source_service_role_crn = string
268+
secret_labels = optional(list(string))
269+
secret_auto_rotation = optional(bool)
270+
secret_auto_rotation_unit = optional(string)
271+
secret_auto_rotation_interval = optional(number)
272+
service_credentials_ttl = optional(string)
273+
service_credential_secret_description = optional(string)
274274

275275
}))
276276
}))
277277
default = []
278278
description = "Service credential secrets configuration for Databases for MySQL. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-icd-mysql/tree/main/solutions/standard/DA-types.md#service-credential-secrets)."
279279

280280
validation {
281+
# Service roles CRNs can be found at https://cloud.ibm.com/iam/roles, select the IBM Cloud Database and select the role
281282
condition = alltrue([
282283
for group in var.service_credential_secrets : alltrue([
283-
for credential in group.service_credentials : contains(
284-
["Writer", "Reader", "Manager", "None"], credential.service_credentials_source_service_role
285-
)
284+
# crn:v?:bluemix; two non-empty segments; three possibly empty segments; :serviceRole or role: non-empty segment
285+
for credential in group.service_credentials : can(regex("^crn:v[0-9]:bluemix(:..*){2}(:.*){3}:(serviceRole|role):..*$", credential.service_credentials_source_service_role_crn))
286286
])
287287
])
288-
error_message = "service_credentials_source_service_role role must be one of 'Writer', 'Reader', 'Manager', and 'None'."
289-
288+
error_message = "service_credentials_source_service_role_crn must be a serviceRole CRN. See https://cloud.ibm.com/iam/roles"
290289
}
291290
}
292291

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)