Skip to content

Commit 600945c

Browse files
authored
feat: added new input secret_groups which supports creating secret groups, and associated IAM access groups. By default it will create a group called General with an associated access group called general-secrets-group-access-group which will have SecretsReader role. (#314)
1 parent b548403 commit 600945c

File tree

15 files changed

+194
-24
lines changed

15 files changed

+194
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ You need the following permissions to run this module.
109109
| <a name="input_kms_key_crn"></a> [kms\_key\_crn](#input\_kms\_key\_crn) | The root key CRN of a Key Management Service like Key Protect or Hyper Protect Crypto Services (HPCS) that you want to use for encryption. Only used if `kms_encryption_enabled` is set to true. | `string` | `null` | no |
110110
| <a name="input_region"></a> [region](#input\_region) | The region where the resource will be provisioned.Its not required if passing a value for `existing_sm_instance_crn`. | `string` | `null` | no |
111111
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The ID of the resource group | `string` | n/a | yes |
112-
| <a name="input_secrets"></a> [secrets](#input\_secrets) | Secret Manager secrets configurations. | <pre>list(object({<br/> secret_group_name = string<br/> secret_group_description = optional(string)<br/> existing_secret_group = optional(bool, false)<br/> secrets = optional(list(object({<br/> secret_name = string<br/> secret_description = optional(string)<br/> secret_type = optional(string)<br/> imported_cert_certificate = optional(string)<br/> imported_cert_private_key = optional(string)<br/> imported_cert_intermediate = optional(string)<br/> secret_username = optional(string)<br/> secret_labels = optional(list(string), [])<br/> secret_payload_password = optional(string, "")<br/> secret_auto_rotation = optional(bool, true)<br/> secret_auto_rotation_unit = optional(string, "day")<br/> secret_auto_rotation_interval = optional(number, 89)<br/> service_credentials_ttl = optional(string, "7776000") # 90 days<br/> service_credentials_source_service_crn = optional(string)<br/> service_credentials_source_service_role_crn = optional(string)<br/> })))<br/> }))</pre> | `[]` | no |
112+
| <a name="input_secrets"></a> [secrets](#input\_secrets) | Secret Manager secrets configurations. | <pre>list(object({<br/> secret_group_name = string<br/> secret_group_description = optional(string)<br/> existing_secret_group = optional(bool, false)<br/> create_access_group = optional(bool, false)<br/> access_group_name = optional(string)<br/> access_group_roles = optional(list(string))<br/> access_group_tags = optional(list(string))<br/> secrets = optional(list(object({<br/> secret_name = string<br/> secret_description = optional(string)<br/> secret_type = optional(string)<br/> imported_cert_certificate = optional(string)<br/> imported_cert_private_key = optional(string)<br/> imported_cert_intermediate = optional(string)<br/> secret_username = optional(string)<br/> secret_labels = optional(list(string), [])<br/> secret_payload_password = optional(string, "")<br/> secret_auto_rotation = optional(bool, true)<br/> secret_auto_rotation_unit = optional(string, "day")<br/> secret_auto_rotation_interval = optional(number, 89)<br/> service_credentials_ttl = optional(string, "7776000") # 90 days<br/> service_credentials_source_service_crn = optional(string)<br/> service_credentials_source_service_role_crn = optional(string)<br/> })))<br/> }))</pre> | `[]` | no |
113113
| <a name="input_secrets_manager_name"></a> [secrets\_manager\_name](#input\_secrets\_manager\_name) | The name of the Secrets Manager instance to create | `string` | n/a | yes |
114114
| <a name="input_skip_en_iam_authorization_policy"></a> [skip\_en\_iam\_authorization\_policy](#input\_skip\_en\_iam\_authorization\_policy) | Set to true to skip the creation of an IAM authorization policy that permits all Secrets Manager instances (scoped to the resource group) an 'Event Source Manager' role to the given Event Notifications instance passed in the `existing_en_instance_crn` input variable. In addition, no policy is created if `enable_event_notification` is set to false. | `bool` | `false` | no |
115115
| <a name="input_skip_iam_authorization_policy"></a> [skip\_iam\_authorization\_policy](#input\_skip\_iam\_authorization\_policy) | Whether to skip the creation of the IAM authorization policies required to enable the IAM credentials engine. If set to false, policies will be created that grants the Secrets Manager instance 'Operator' access to the IAM identity service, and 'Groups Service Member Manage' access to the IAM groups service. | `bool` | `false` | no |

ibm_catalog.json

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
"title": "Creates a Secrets Manager instance.",
3030
"description": "Creates an IBM Secrets Manager instance."
3131
},
32+
{
33+
"title": "Create secret groups.",
34+
"description": "Optionally create secret groups inside your IBM Secrets Manager instance."
35+
},
36+
{
37+
"title": "Create access groups for your secret groups.",
38+
"description": "Optionally create access groups for the secret groups inside your IBM Secrets Manager instance."
39+
},
3240
{
3341
"title": "Optionally configure an IBM Secrets Manager IAM credentials engine to an IBM Secrets Manager instance.",
3442
"description": "Optionally configure an IBM Secrets Manager IAM credentials engine to an IBM Secrets Manager instance."
@@ -134,12 +142,12 @@
134142
"key": "existing_resource_group_name",
135143
"required": true,
136144
"custom_config": {
137-
"type": "resource_group",
138-
"grouping": "deployment",
139-
"original_grouping": "deployment",
140-
"config_constraints": {
141-
"identifier": "rg_name"
142-
}
145+
"type": "resource_group",
146+
"grouping": "deployment",
147+
"original_grouping": "deployment",
148+
"config_constraints": {
149+
"identifier": "rg_name"
150+
}
143151
}
144152
},
145153
{
@@ -169,7 +177,7 @@
169177
"config_constraints": {
170178
"type": "string"
171179
}
172-
}
180+
}
173181
},
174182
{
175183
"key": "service_plan",
@@ -252,6 +260,9 @@
252260
},
253261
{
254262
"key": "secrets_manager_cbr_rules"
263+
},
264+
{
265+
"key": "secret_groups"
255266
}
256267
],
257268
"architecture": {
@@ -401,7 +412,7 @@
401412
"config_constraints": {
402413
"type": "string"
403414
}
404-
}
415+
}
405416
},
406417
{
407418
"key": "service_plan",
@@ -423,12 +434,12 @@
423434
"key": "existing_resource_group_name",
424435
"required": true,
425436
"custom_config": {
426-
"type": "resource_group",
427-
"grouping": "deployment",
428-
"original_grouping": "deployment",
429-
"config_constraints": {
430-
"identifier": "rg_name"
431-
}
437+
"type": "resource_group",
438+
"grouping": "deployment",
439+
"original_grouping": "deployment",
440+
"config_constraints": {
441+
"identifier": "rg_name"
442+
}
432443
}
433444
},
434445
{
@@ -463,6 +474,9 @@
463474
},
464475
{
465476
"key": "secrets_manager_cbr_rules"
477+
},
478+
{
479+
"key": "secret_groups"
466480
}
467481
],
468482
"architecture": {

modules/secrets/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module "secrets_manager" {
5050

5151
| Name | Source | Version |
5252
|------|--------|---------|
53-
| <a name="module_secret_groups"></a> [secret\_groups](#module\_secret\_groups) | terraform-ibm-modules/secrets-manager-secret-group/ibm | 1.2.3 |
53+
| <a name="module_secret_groups"></a> [secret\_groups](#module\_secret\_groups) | terraform-ibm-modules/secrets-manager-secret-group/ibm | 1.3.2 |
5454
| <a name="module_secrets"></a> [secrets](#module\_secrets) | terraform-ibm-modules/secrets-manager-secret/ibm | 1.7.0 |
5555

5656
### Resources
@@ -66,7 +66,7 @@ module "secrets_manager" {
6666
| <a name="input_endpoint_type"></a> [endpoint\_type](#input\_endpoint\_type) | The service endpoint type to communicate with the provided secrets manager instance. Possible values are `public` or `private` | `string` | `"public"` | no |
6767
| <a name="input_existing_sm_instance_guid"></a> [existing\_sm\_instance\_guid](#input\_existing\_sm\_instance\_guid) | Instance ID of Secrets Manager instance in which the Secret will be added. | `string` | n/a | yes |
6868
| <a name="input_existing_sm_instance_region"></a> [existing\_sm\_instance\_region](#input\_existing\_sm\_instance\_region) | Region which the Secret Manager is deployed. | `string` | n/a | yes |
69-
| <a name="input_secrets"></a> [secrets](#input\_secrets) | Secret Manager secrets configurations. | <pre>list(object({<br/> secret_group_name = string<br/> secret_group_description = optional(string)<br/> existing_secret_group = optional(bool, false)<br/> secrets = optional(list(object({<br/> secret_name = string<br/> secret_description = optional(string)<br/> secret_type = optional(string)<br/> imported_cert_certificate = optional(string)<br/> imported_cert_private_key = optional(string)<br/> imported_cert_intermediate = optional(string)<br/> secret_username = optional(string)<br/> secret_labels = optional(list(string), [])<br/> secret_payload_password = optional(string, "")<br/> secret_auto_rotation = optional(bool, true)<br/> secret_auto_rotation_unit = optional(string, "day")<br/> secret_auto_rotation_interval = optional(number, 89)<br/> service_credentials_ttl = optional(string, "7776000") # 90 days<br/> service_credentials_source_service_crn = optional(string)<br/> service_credentials_source_service_role_crn = optional(string)<br/> service_credentials_source_service_hmac = optional(bool, false)<br/> })))<br/> }))</pre> | `[]` | no |
69+
| <a name="input_secrets"></a> [secrets](#input\_secrets) | Secret Manager secrets configurations. | <pre>list(object({<br/> secret_group_name = string<br/> secret_group_description = optional(string)<br/> existing_secret_group = optional(bool, false)<br/> create_access_group = optional(bool, false)<br/> access_group_name = optional(string)<br/> access_group_roles = optional(list(string))<br/> access_group_tags = optional(list(string))<br/> secrets = optional(list(object({<br/> secret_name = string<br/> secret_description = optional(string)<br/> secret_type = optional(string)<br/> imported_cert_certificate = optional(string)<br/> imported_cert_private_key = optional(string)<br/> imported_cert_intermediate = optional(string)<br/> secret_username = optional(string)<br/> secret_labels = optional(list(string), [])<br/> secret_payload_password = optional(string, "")<br/> secret_auto_rotation = optional(bool, true)<br/> secret_auto_rotation_unit = optional(string, "day")<br/> secret_auto_rotation_interval = optional(number, 89)<br/> service_credentials_ttl = optional(string, "7776000") # 90 days<br/> service_credentials_source_service_crn = optional(string)<br/> service_credentials_source_service_role_crn = optional(string)<br/> service_credentials_source_service_hmac = optional(bool, false)<br/> })), [])<br/> }))</pre> | `[]` | no |
7070

7171
### Outputs
7272

modules/secrets/main.tf

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ locals {
66
secret_groups = flatten([
77
for secret_group in var.secrets :
88
secret_group.existing_secret_group ? [] : [{
9-
secret_group_name = secret_group.secret_group_name
10-
secret_group_description = secret_group.secret_group_description
9+
secret_group_name = secret_group.secret_group_name
10+
secret_group_description = secret_group.secret_group_description
11+
secret_group_create_access_group = secret_group.create_access_group
12+
secret_group_access_group_name = secret_group.access_group_name
13+
secret_group_access_group_roles = secret_group.access_group_roles
14+
secret_group_access_group_tags = secret_group.access_group_tags
1115
}]
1216
])
1317
}
@@ -21,12 +25,16 @@ data "ibm_sm_secret_groups" "existing_secret_groups" {
2125
module "secret_groups" {
2226
for_each = { for obj in local.secret_groups : obj.secret_group_name => obj }
2327
source = "terraform-ibm-modules/secrets-manager-secret-group/ibm"
24-
version = "1.2.3"
28+
version = "1.3.2"
2529
region = var.existing_sm_instance_region
2630
secrets_manager_guid = var.existing_sm_instance_guid
2731
secret_group_name = each.value.secret_group_name
2832
secret_group_description = each.value.secret_group_description
2933
endpoint_type = var.endpoint_type
34+
create_access_group = each.value.secret_group_create_access_group
35+
access_group_name = each.value.secret_group_access_group_name
36+
access_group_roles = each.value.secret_group_access_group_roles
37+
access_group_tags = each.value.secret_group_access_group_tags
3038
}
3139

3240
##############################################################################

modules/secrets/variables.tf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ variable "secrets" {
2323
secret_group_name = string
2424
secret_group_description = optional(string)
2525
existing_secret_group = optional(bool, false)
26+
create_access_group = optional(bool, false)
27+
access_group_name = optional(string)
28+
access_group_roles = optional(list(string))
29+
access_group_tags = optional(list(string))
2630
secrets = optional(list(object({
2731
secret_name = string
2832
secret_description = optional(string)
@@ -40,7 +44,7 @@ variable "secrets" {
4044
service_credentials_source_service_crn = optional(string)
4145
service_credentials_source_service_role_crn = optional(string)
4246
service_credentials_source_service_hmac = optional(bool, false)
43-
})))
47+
})), [])
4448
}))
4549
description = "Secret Manager secrets configurations."
4650
default = []
@@ -58,4 +62,11 @@ variable "secrets" {
5862
true if(secret.secret_group_name == "default" && secret.existing_secret_group == false)
5963
]) == 0
6064
}
65+
validation {
66+
error_message = "When creating an access group, a list of roles must be specified."
67+
condition = length([
68+
for secret in var.secrets :
69+
true if(secret.create_access_group && secret.access_group_roles == null)
70+
]) == 0
71+
}
6172
}

reference-architecture/secrets_manager.svg

Lines changed: 1 addition & 1 deletion
Loading

solutions/fully-configurable/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
This solution supports the following:
44
- Taking in an existing resource group.
55
- Provisioning and configuring of a Secrets Manager instance.
6+
- Provisioning secrets groups inside a new or pre-existing Secrets Manager instance.
7+
- Provisioning access groups to the secrets groups of the Secrets Manager instance.
68
- Configuring KMS encryption using a newly created key, or passing an existing key.
79

810
![secret-manager-deployable-architecture](../../reference-architecture/secrets_manager.svg)
@@ -65,6 +67,7 @@ This solution supports the following:
6567
| <a name="input_prefix"></a> [prefix](#input\_prefix) | The prefix to add to all resources created by this solution. To not use any prefix value, you can set this value to `null` or an empty string. | `string` | n/a | yes |
6668
| <a name="input_provider_visibility"></a> [provider\_visibility](#input\_provider\_visibility) | Set the visibility value for the IBM terraform provider. Supported values are `public`, `private`, `public-and-private`. [Learn more](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/guides/custom-service-endpoints). | `string` | `"private"` | no |
6769
| <a name="input_region"></a> [region](#input\_region) | The region to provision resources to. | `string` | `"us-south"` | no |
70+
| <a name="input_secret_groups"></a> [secret\_groups](#input\_secret\_groups) | Secret Manager secret group and access group configurations. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-secrets-manager/tree/main/solutions/fully-configurable/provisioning_secrets_groups.md). | <pre>list(object({<br/> secret_group_name = string<br/> secret_group_description = optional(string)<br/> create_access_group = optional(bool, true)<br/> access_group_name = optional(string)<br/> access_group_roles = optional(list(string), ["SecretsReader"])<br/> access_group_tags = optional(list(string))<br/> }))</pre> | <pre>[<br/> {<br/> "access_group_name": "general-secrets-group-access-group",<br/> "access_group_roles": [<br/> "SecretsReader"<br/> ],<br/> "create_access_group": true,<br/> "secret_group_description": "A general purpose secrets group with an associated access group which has a secrets reader role",<br/> "secret_group_name": "General"<br/> }<br/>]</pre> | no |
6871
| <a name="input_secrets_manager_cbr_rules"></a> [secrets\_manager\_cbr\_rules](#input\_secrets\_manager\_cbr\_rules) | (Optional, list) List of CBR rules to create. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-secrets-manager/blob/main/solutions/fully-configurable/DA-cbr_rules.md) | <pre>list(object({<br/> description = string<br/> account_id = string<br/> rule_contexts = list(object({<br/> attributes = optional(list(object({<br/> name = string<br/> value = string<br/> }))) }))<br/> enforcement_mode = string<br/> operations = optional(list(object({<br/> api_types = list(object({<br/> api_type_id = string<br/> }))<br/> })))<br/> }))</pre> | `[]` | no |
6972
| <a name="input_secrets_manager_endpoint_type"></a> [secrets\_manager\_endpoint\_type](#input\_secrets\_manager\_endpoint\_type) | The type of endpoint (public or private) to connect to the Secrets Manager API. The Terraform provider uses this endpoint type to interact with the Secrets Manager API and configure Event Notifications. | `string` | `"private"` | no |
7073
| <a name="input_secrets_manager_instance_name"></a> [secrets\_manager\_instance\_name](#input\_secrets\_manager\_instance\_name) | The name to give the Secrets Manager instance provisioned by this solution. If a prefix input variable is specified, it is added to the value in the `<prefix>-value` format. Applies only if `existing_secrets_manager_crn` is not provided. | `string` | `"secrets-manager"` | no |

solutions/fully-configurable/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ module "secrets_manager" {
187187
cbr_rules = var.secrets_manager_cbr_rules
188188
endpoint_type = var.secrets_manager_endpoint_type
189189
allowed_network = var.allowed_network
190+
secrets = var.secret_groups
190191
}
191192

192193
data "ibm_resource_instance" "existing_sm" {

0 commit comments

Comments
 (0)