Skip to content

Commit e3eab41

Browse files
authored
feat: add service_credential secret type (#101)<br>Support has been added for creating Service credentials secrets in Secrets Manager.<br><br>Before you start working with them, you will need to create a service authorization between Secrets Manager and the target service, see the provided example for more info.<br><br>Variables and outputs related to auto_rotation have been renamed. This may impact existing users of "user_password" type secrets.<br><br>Variables:<br>secret_user_pass_auto_rotation -> secret_auto_rotation<br>secret_user_pass_auto_rotation_unit -> secret_auto_rotation_unit<br>secret_user_pass_auto_rotation_interval -> secret_auto_rotation_interval<br> <br>Outputs:<br>user_pass_rotation -> secret_auto_rotation<br>user_pass_auto_rotation_interval -> secret_rotation_interval<br>user_pass_next_rotation_date -> secret_next_rotation_date
1 parent 1084d2d commit e3eab41

File tree

8 files changed

+253
-73
lines changed

8 files changed

+253
-73
lines changed

.secrets.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "go.sum|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2023-12-09T07:18:15Z",
6+
"generated_at": "2024-01-18T16:31:21Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"

README.md

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,42 @@ The module supports the following secret types:
1313
- [Arbitrary](https://cloud.ibm.com/docs/secrets-manager?topic=secrets-manager-arbitrary-secrets&interface=ui)
1414
- [User credentials](https://cloud.ibm.com/docs/secrets-manager?topic=secrets-manager-user-credentials&interface=ui)
1515
- [Imported Certificate](https://cloud.ibm.com/docs/secrets-manager?topic=secrets-manager-certificates&interface=api#import-certificates)
16+
- [Service Credentials](https://cloud.ibm.com/docs/secrets-manager?topic=secrets-manager-service-credentials&interface=api)
1617

17-
The following attributes and parameters are supported for both secret types:
18+
The following attributes and parameters are supported for all secret types:
1819

1920
- `secret_group_id`: When `null`, the `default` secret-group is used.
2021
- `secret_name`: The name of the secret that is created.
2122
- `secret_description`: The description of the secret.
23+
- `secret_type` : The type of the secret.
24+
- `secret_labels` : Any labels to attach to the secret.
25+
26+
The following attributes and paramters are supported when storing arbitrary secrets:
27+
2228
- `secret_payload_password`: The payload (for arbitrary secrets) or password (for username and password credentials) of the secret.
2329

24-
The following attributes and parameters are supported only when storing user credentials:
30+
The following attributes and parameters are supported when storing user credentials:
2531

32+
- `secret_payload_password`: The payload (for arbitrary secrets) or password (for username and password credentials) of the secret.
2633
- `secret_username`: The username of the secret that is created. Applicable only to the `username_password` secret type. When the parameter is `null`, an `arbitrary` secret is created.
27-
- `secret_user_pass_auto_rotation`: Configures automatic rotation. Default is `true`.
28-
- `secret_user_pass_auto_rotation_unit`: Specifies the unit type for the secret rotation. Accepted values are `day` or `month`. Default is `day`.
29-
- `secret_user_pass_auto_rotation_interval`: Specifies the rotation interval for the rotation unit. Default is `90`.
34+
- `secret_auto_rotation`: Configures automatic rotation. Default is `true`.
35+
- `secret_auto_rotation_unit`: Specifies the unit type for the secret rotation. Accepted values are `day` or `month`. Default is `day`.
36+
- `secret_auto_rotation_interval`: Specifies the rotation interval for the rotation unit. Default is `89`.
3037

31-
The following attributes and parameters are supported only when creating imported certificates:
38+
The following attributes and parameters are supported when creating imported certificates:
3239

33-
- `imported_cert`: specify if imported certificate secret type will be created, defaults to `false`.
3440
- `imported_cert_certificate`: The TLS certificate to be imported. Defaults to `null`.
3541
- `imported_cert_private_key`: Optional private key for the TLS certificate to be imported. Defaults to `null`.
3642
- `imported_cert_intermediate`: Optional intermediate certificate for the TLS certificate to be imported. Defaults to `null`.
3743

44+
The following attributes and parameters are supported when creating service credentials:
45+
46+
- `service_credentials_source_service_crn`: The CRN of the target service instance to create the service credentials.
47+
- `service_credentials_source_service_role`: The service specific role to give the service credentials.
48+
- `secret_auto_rotation`: Configures automatic rotation. Default is `true`.
49+
- `secret_auto_rotation_unit`: Specifies the unit type for the secret rotation. Accepted values are `day` or `month`. Default is `day`.
50+
- `secret_auto_rotation_interval`: Specifies the rotation interval for the rotation unit. Default is `89`.
51+
3852
<!-- Below content is automatically populated via pre-commit hook -->
3953
<!-- BEGIN OVERVIEW HOOK -->
4054
## Overview
@@ -53,14 +67,14 @@ The following attributes and parameters are supported only when creating importe
5367
##############################################################################
5468
5569
module "secrets_manager_arbitrary_secret" {
56-
# Replace "master" with a GIT release version to lock into a specific release
5770
source = "terraform-ibm-modules/secrets-manager-secret/ibm"
58-
version = "3.1.1"
71+
version = "latest" # Replace "latest" with a release version to lock into a specific release
5972
region = "us-south"
6073
secrets_manager_guid = "42454b3b-5b06-407b-a4b3-34d9ef323901"
6174
secret_group_id = "432b91f1-ff6d-4b47-9f06-82debc236d90"
6275
secret_name = "example-arbitrary-secret"
6376
secret_description = "Extended description for the arbirtary secret."
77+
secret_type = "arbitrary"
6478
secret_payload_password = "secret-data" #pragma: allowlist secret
6579
}
6680
```
@@ -71,14 +85,14 @@ module "secrets_manager_arbitrary_secret" {
7185
##############################################################################
7286
7387
module "secrets_manager_user_pass_secret" {
74-
# Replace "master" with a GIT release version to lock into a specific release
7588
source = "terraform-ibm-modules/secrets-manager-secret/ibm"
76-
version = "3.1.1"
89+
version = "latest" # Replace "latest" with a release version to lock into a specific release
7790
region = "us-south"
7891
secrets_manager_guid = "42454b3b-5b06-407b-a4b3-34d9ef323901"
7992
secret_group_id = "432b91f1-ff6d-4b47-9f06-82debc236d90"
8093
secret_name = "example-user-pass-secret"
8194
secret_description = "Extended description for the user pass secret."
95+
secret_type = "username_password"
8296
secret_payload_password = "secret-data" #pragma: allowlist secret
8397
secret_username = "terraform-user"
8498
}
@@ -90,21 +104,41 @@ module "secrets_manager_user_pass_secret" {
90104
##############################################################################
91105
92106
module "secret_manager_imported_cert secret" {
93-
# Replace "master" with a GIT release version to lock into a specific release
94107
source = "terraform-ibm-modules/secrets-manager-secret/ibm"
95-
version = "3.1.1"
108+
version = "latest" # Replace "latest" with a release version to lock into a specific release
96109
region = "us-south
97110
secrets_manager_guid = "42454b3b-5b06-407b-a4b3-34d9ef323901"
98111
secret_group_id = "432b91f1-ff6d-4b47-9f06-82debc236d90"
99112
secret_name = "example-imported-cert-secret"
100113
secret_description = "Extended description for the imported cert secret."
101-
imported_cert = true
114+
secret_type = "imported_cert"
102115
imported_cert_certificate = module.certificate.cert_pem
103116
imported_cert_private_key = module.certificate.private_key #pragma: allowlist secret
104117
imported_cert_intermediate = module.certificate.ca_cert_pem
105118
}
106119
```
107120

121+
```hcl
122+
##############################################################################
123+
# Create Service Credentials
124+
##############################################################################
125+
126+
# A service authorization between Secrets Manager and the target service is required. The "complete" example includes a sample service authorization.
127+
128+
module "secret_manager_service_credential" {
129+
source = "terraform-ibm-modules/secrets-manager-secret/ibm"
130+
version = "latest" # Replace "latest" with a release version to lock into a specific release
131+
region = "us-south
132+
secrets_manager_guid = "42454b3b-5b06-407b-a4b3-34d9ef323901"
133+
secret_group_id = "432b91f1-ff6d-4b47-9f06-82debc236d90"
134+
secret_name = "example-service-credential"
135+
secret_description = "Extended description for the service credentials secret."
136+
secret_type = "service_credentials"
137+
service_credentials_source_service_crn = module.cloud_object_storage.cos_instance_id
138+
service_credentials_source_service_role = "Writer"
139+
}
140+
```
141+
108142
### Required IAM access policies
109143
You need the following permissions to run this module.
110144

@@ -134,6 +168,7 @@ No modules.
134168
|------|------|
135169
| [ibm_sm_arbitrary_secret.arbitrary_secret](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/sm_arbitrary_secret) | resource |
136170
| [ibm_sm_imported_certificate.imported_cert](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/sm_imported_certificate) | resource |
171+
| [ibm_sm_service_credentials_secret.service_credentials_secret](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/sm_service_credentials_secret) | resource |
137172
| [ibm_sm_username_password_secret.username_password_secret](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/sm_username_password_secret) | resource |
138173

139174
### Inputs
@@ -144,17 +179,20 @@ No modules.
144179
| <a name="input_imported_cert_intermediate"></a> [imported\_cert\_intermediate](#input\_imported\_cert\_intermediate) | (optional) The intermediate certificate for the TLS certificate to import. | `string` | `null` | no |
145180
| <a name="input_imported_cert_private_key"></a> [imported\_cert\_private\_key](#input\_imported\_cert\_private\_key) | (optional) The private key for the TLS certificate to import. | `string` | `null` | no |
146181
| <a name="input_region"></a> [region](#input\_region) | The region where the Secrets Manager instance is deployed. | `string` | n/a | yes |
182+
| <a name="input_secret_auto_rotation"></a> [secret\_auto\_rotation](#input\_secret\_auto\_rotation) | Whether to configure automatic rotation. Applies only to the `username_password` and `service_credentials` secret types. | `bool` | `true` | no |
183+
| <a name="input_secret_auto_rotation_interval"></a> [secret\_auto\_rotation\_interval](#input\_secret\_auto\_rotation\_interval) | Specifies the rotation interval for the rotation unit. | `number` | `89` | no |
184+
| <a name="input_secret_auto_rotation_unit"></a> [secret\_auto\_rotation\_unit](#input\_secret\_auto\_rotation\_unit) | Specifies the unit of time for rotation of a username\_password secret. Acceptable values are `day` or `month`. | `string` | `"day"` | no |
147185
| <a name="input_secret_description"></a> [secret\_description](#input\_secret\_description) | Description of the secret to create. | `string` | n/a | yes |
148186
| <a name="input_secret_group_id"></a> [secret\_group\_id](#input\_secret\_group\_id) | The ID of the secret group for the secret. If `null`, the `default` secret group is used. | `string` | `"default"` | no |
149187
| <a name="input_secret_labels"></a> [secret\_labels](#input\_secret\_labels) | 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 (\|). | `list(string)` | `[]` | no |
150188
| <a name="input_secret_name"></a> [secret\_name](#input\_secret\_name) | Name of the secret to create. | `string` | n/a | yes |
151189
| <a name="input_secret_payload_password"></a> [secret\_payload\_password](#input\_secret\_payload\_password) | The payload (for arbitrary secrets) or password (for username and password credentials) of the secret. | `string` | `""` | no |
152-
| <a name="input_secret_type"></a> [secret\_type](#input\_secret\_type) | Type of secret to create, must be one of: arbitrary, username\_password, imported\_cert | `string` | n/a | yes |
153-
| <a name="input_secret_user_pass_auto_rotation"></a> [secret\_user\_pass\_auto\_rotation](#input\_secret\_user\_pass\_auto\_rotation) | Whether to configure automatic rotation. Applies only to the `username_password` secret type. | `bool` | `true` | no |
154-
| <a name="input_secret_user_pass_auto_rotation_interval"></a> [secret\_user\_pass\_auto\_rotation\_interval](#input\_secret\_user\_pass\_auto\_rotation\_interval) | Specifies the rotation interval for the rotation unit. | `number` | `90` | no |
155-
| <a name="input_secret_user_pass_auto_rotation_unit"></a> [secret\_user\_pass\_auto\_rotation\_unit](#input\_secret\_user\_pass\_auto\_rotation\_unit) | Specifies the unit of time for rotation of a username\_password secret. Acceptable values are `day` or `month`. | `string` | `"day"` | no |
190+
| <a name="input_secret_type"></a> [secret\_type](#input\_secret\_type) | Type of secret to create, must be one of: arbitrary, username\_password, imported\_cert, service\_credentials | `string` | n/a | yes |
156191
| <a name="input_secret_username"></a> [secret\_username](#input\_secret\_username) | Username of the secret to create. Applies only to `username_password` secret types. When `null`, an `arbitrary` secret is created. | `string` | `null` | no |
157192
| <a name="input_secrets_manager_guid"></a> [secrets\_manager\_guid](#input\_secrets\_manager\_guid) | The instance ID of the Secrets Manager instance where the secret will be added. | `string` | n/a | yes |
193+
| <a name="input_service_credentials_source_service_crn"></a> [service\_credentials\_source\_service\_crn](#input\_service\_credentials\_source\_service\_crn) | The CRN of the source service instance to create the service credential. | `string` | `null` | no |
194+
| <a name="input_service_credentials_source_service_role"></a> [service\_credentials\_source\_service\_role](#input\_service\_credentials\_source\_service\_role) | The role to give the service credential in the source service. | `string` | `null` | no |
195+
| <a name="input_service_credentials_ttl"></a> [service\_credentials\_ttl](#input\_service\_credentials\_ttl) | The time-to-live (TTL) to assign to generated service credentials (in seconds). | `number` | `"7776000"` | no |
158196
| <a name="input_service_endpoints"></a> [service\_endpoints](#input\_service\_endpoints) | The service endpoint type to communicate with the provided secrets manager instance. Possible values are `public` or `private` | `string` | `"public"` | no |
159197

160198
### Outputs
@@ -163,9 +201,9 @@ No modules.
163201
|------|-------------|
164202
| <a name="output_secret_crn"></a> [secret\_crn](#output\_secret\_crn) | CRN of the created Secret |
165203
| <a name="output_secret_id"></a> [secret\_id](#output\_secret\_id) | ID of the created Secret |
166-
| <a name="output_user_pass_next_rotation_date"></a> [user\_pass\_next\_rotation\_date](#output\_user\_pass\_next\_rotation\_date) | Next rotation data for username\_password secret |
167-
| <a name="output_user_pass_rotation"></a> [user\_pass\_rotation](#output\_user\_pass\_rotation) | Status of auto-rotation for username\_password secret |
168-
| <a name="output_user_pass_rotation_interval"></a> [user\_pass\_rotation\_interval](#output\_user\_pass\_rotation\_interval) | Rotation frecuency for username\_password secret |
204+
| <a name="output_secret_next_rotation_date"></a> [secret\_next\_rotation\_date](#output\_secret\_next\_rotation\_date) | Next rotation date for secret (if applicable) |
205+
| <a name="output_secret_rotation"></a> [secret\_rotation](#output\_secret\_rotation) | Status of auto-rotation for secret |
206+
| <a name="output_secret_rotation_interval"></a> [secret\_rotation\_interval](#output\_secret\_rotation\_interval) | Rotation frecuency for secret (if applicable) |
169207
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
170208

171209
## Contributing

cra-tf-validate-ignore-rules.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
{
2-
"scc_rules": []
2+
"scc_rules": [
3+
{
4+
"scc_rule_id": "rule-8cbd597c-7471-42bd-9c88-36b2696456e9",
5+
"description": "Check whether Cloud Object Storage network access is restricted to a specific IP range",
6+
"ignore_reason": "This rule is not relevant to the module itself, just the COS instance that is used in the example that is scanned",
7+
"is_valid": false
8+
},
9+
{
10+
"scc_rule_id": "rule-c97259ee-336d-4c5f-b436-1868107a9558",
11+
"description": "Check whether Cloud Object Storage is enabled with customer-managed encryption and Keep Your Own Key (KYOK)",
12+
"ignore_reason": "This rule is not relevant to the module itself, just the COS instance that is used in the example that is scanned",
13+
"is_valid": false
14+
}
15+
]
316
}

0 commit comments

Comments
 (0)