Skip to content

Commit d69b8f3

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" (#374)
1 parent 293ec2e commit d69b8f3

File tree

4 files changed

+33
-34
lines changed

4 files changed

+33
-34
lines changed

solutions/standard/DA-types.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ In the configuration, specify the secret group name, whether it already exists o
5353
#### Options for service_credentials
5454

5555
- `secret_name`: (required): A unique human-readable name of the secret to create.
56-
- `service_credentials_source_service_role`: (required): The role to give the service credential in the Event Notification service. Acceptable values are `Writer`, `Reader`, `Manager`, `None`, `Event Source Manager`, `Channel Editor`, `Event Notification Publisher`, `Status Reporter`, `Device Manager`, `Email Sender`, `Custom Email Status Reporter` , and `Pool ID Manager`
56+
- `service_credentials_source_service_role_crn`: (required): The CRN of the role to give the service credential in the Event Nofication service. Service credentials role CRNs can be found at https://cloud.ibm.com/iam/roles, select Event Notifications and select the role. Role CRNs can be for the roles `Writer`, `Reader`, `Manager`, `Event Source Manager`, `Channel Editor`, `Event Notification Publisher`, `Status Reporter`, `Device Manager`, `Email Sender`, `Custom Email Status Reporter` , or `Pool ID Manager`
5757
- `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 (|).
5858
- `secret_auto_rotation`: (optional, default = `true`): Whether to configure automatic rotation of service credential.
5959
- `secret_auto_rotation_unit`: (optional, default = `day`): Specifies the unit of time for rotation of a secret. Acceptable values are `day` or `month`.
@@ -70,7 +70,7 @@ In the configuration, specify the secret group name, whether it already exists o
7070
"service_credentials": [
7171
{
7272
"secret_name": "cred-1"
73-
"service_credentials_source_service_role": "Writer"
73+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Writer"
7474
"secret_labels": ["test-writer-1", "test-writer-2"]
7575
"secret_auto_rotation": true
7676
"secret_auto_rotation_unit": "day"
@@ -80,7 +80,7 @@ In the configuration, specify the secret group name, whether it already exists o
8080
},
8181
{
8282
"secret_name": "cred-2"
83-
"service_credentials_source_service_role": "Reader"
83+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Reader"
8484
}
8585
]
8686
},
@@ -89,11 +89,7 @@ In the configuration, specify the secret group name, whether it already exists o
8989
"service_credentials": [
9090
{
9191
"secret_name": "cred-3"
92-
"service_credentials_source_service_role": "Editor"
93-
},
94-
{
95-
"secret_name": "cred-4"
96-
"service_credentials_source_service_role": "None"
92+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::role:Editor"
9793
}
9894
]
9995
}

solutions/standard/main.tf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,16 +353,16 @@ locals {
353353
existing_secret_group = service_credentials.existing_secret_group
354354
secrets = [
355355
for secret in service_credentials.service_credentials : {
356-
secret_name = secret.secret_name
357-
secret_labels = secret.secret_labels
358-
secret_auto_rotation = secret.secret_auto_rotation
359-
secret_auto_rotation_unit = secret.secret_auto_rotation_unit
360-
secret_auto_rotation_interval = secret.secret_auto_rotation_interval
361-
service_credentials_ttl = secret.service_credentials_ttl
362-
service_credential_secret_description = secret.service_credential_secret_description
363-
service_credentials_source_service_role = secret.service_credentials_source_service_role
364-
service_credentials_source_service_crn = local.eventnotification_crn
365-
secret_type = "service_credentials" #checkov:skip=CKV_SECRET_6
356+
secret_name = secret.secret_name
357+
secret_labels = secret.secret_labels
358+
secret_auto_rotation = secret.secret_auto_rotation
359+
secret_auto_rotation_unit = secret.secret_auto_rotation_unit
360+
secret_auto_rotation_interval = secret.secret_auto_rotation_interval
361+
service_credentials_ttl = secret.service_credentials_ttl
362+
service_credential_secret_description = secret.service_credential_secret_description
363+
service_credentials_source_service_role_crn = secret.service_credentials_source_service_role_crn
364+
service_credentials_source_service_crn = local.eventnotification_crn
365+
secret_type = "service_credentials" #checkov:skip=CKV_SECRET_6
366366
}
367367
]
368368
}
@@ -390,7 +390,7 @@ module "secrets_manager_service_credentials" {
390390
count = length(local.service_credential_secrets) > 0 ? 1 : 0
391391
depends_on = [time_sleep.wait_for_en_authorization_policy]
392392
source = "terraform-ibm-modules/secrets-manager/ibm//modules/secrets"
393-
version = "1.20.0"
393+
version = "1.22.0"
394394
existing_sm_instance_guid = local.existing_secrets_manager_instance_guid
395395
existing_sm_instance_region = local.existing_secrets_manager_instance_region
396396
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
@@ -311,30 +311,29 @@ variable "service_credential_secrets" {
311311
secret_group_description = optional(string)
312312
existing_secret_group = optional(bool)
313313
service_credentials = list(object({
314-
secret_name = string
315-
service_credentials_source_service_role = string
316-
secret_labels = optional(list(string))
317-
secret_auto_rotation = optional(bool)
318-
secret_auto_rotation_unit = optional(string)
319-
secret_auto_rotation_interval = optional(number)
320-
service_credentials_ttl = optional(string)
321-
service_credential_secret_description = optional(string)
314+
secret_name = string
315+
service_credentials_source_service_role_crn = string
316+
secret_labels = optional(list(string))
317+
secret_auto_rotation = optional(bool)
318+
secret_auto_rotation_unit = optional(string)
319+
secret_auto_rotation_interval = optional(number)
320+
service_credentials_ttl = optional(string)
321+
service_credential_secret_description = optional(string)
322322

323323
}))
324324
}))
325325
default = []
326326
description = "Service credential secrets configuration for Event Notification. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-event-notifications/tree/main/solutions/standard/DA-types.md#service-credential-secrets)."
327327

328328
validation {
329+
# Service roles CRNs can be found at https://cloud.ibm.com/iam/roles, select Event Notifications and select the role
329330
condition = alltrue([
330331
for group in var.service_credential_secrets : alltrue([
331-
for credential in group.service_credentials : contains(
332-
["Writer", "Reader", "Manager", "None", "Event Source Manager", "Channel Editor", "Event Notification Publisher", "Status Reporter", "Device Manager", "Email Sender", "Custom Email Status Reporter", "Pool ID Manager"], credential.service_credentials_source_service_role
333-
)
332+
# crn:v?:bluemix; two non-empty segments; three possibly empty segments; :serviceRole or role: non-empty segment
333+
for credential in group.service_credentials : can(regex("^crn:v[0-9]:bluemix(:..*){2}(:.*){3}:(serviceRole|role):..*$", credential.service_credentials_source_service_role_crn))
334334
])
335335
])
336-
error_message = "service_credentials_source_service_role role must be one of 'Writer', 'Reader', 'Manager', 'None', 'Event Source Manager', 'Channel Editor', 'Event Notification Publisher', 'Status Reporter', 'Device Manager', 'Email Sender', 'Custom Email Status Reporter' and 'Pool ID Manager'."
337-
336+
error_message = "service_credentials_source_service_role_crn must be a serviceRole CRN. See https://cloud.ibm.com/iam/roles"
338337
}
339338
}
340339

tests/pr_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,15 @@ func TestDAInSchematics(t *testing.T) {
124124
"service_credentials": []map[string]string{
125125
{
126126
"secret_name": fmt.Sprintf("%s-cred-reader", options.Prefix),
127-
"service_credentials_source_service_role": "Reader",
127+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Reader",
128128
},
129129
{
130130
"secret_name": fmt.Sprintf("%s-cred-writer", options.Prefix),
131-
"service_credentials_source_service_role": "Writer",
131+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Writer",
132+
},
133+
{
134+
"secret_name": fmt.Sprintf("%s-cred-editor", options.Prefix),
135+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::role:Editor",
132136
},
133137
},
134138
},

0 commit comments

Comments
 (0)