Skip to content

Commit 724a7de

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" (#304)
1 parent 033a6ce commit 724a7de

File tree

4 files changed

+31
-36
lines changed

4 files changed

+31
-36
lines changed

solutions/standard/DA-types.md

Lines changed: 6 additions & 10 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 RabbitMQ 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`.
@@ -69,11 +69,11 @@ The following example includes all the configuration options for four service cr
6969
{
7070
"secret_group_name": "sg-1"
7171
"existing_secret_group": true
72-
"service_credentials": [ # pragma: allowlist secret
72+
"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
@@ -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.rabbitmq.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.rabbitmq.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_rabbitmq_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 RabbitMQ. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-icd-rabbitmq/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)