Skip to content

Commit faffa4f

Browse files
authored
feat: added support to add custom metadata to a secret using new input custom_metadata (#251)
1 parent 325198a commit faffa4f

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ No modules.
176176

177177
| Name | Description | Type | Default | Required |
178178
|------|-------------|------|---------|:--------:|
179+
| <a name="input_custom_metadata"></a> [custom\_metadata](#input\_custom\_metadata) | Optional metadata to be added to the secret. | `map(string)` | `null` | no |
179180
| <a name="input_endpoint_type"></a> [endpoint\_type](#input\_endpoint\_type) | The endpoint type to communicate with the provided secrets manager instance. Possible values are `public` or `private` | `string` | `"public"` | no |
180181
| <a name="input_imported_cert_certificate"></a> [imported\_cert\_certificate](#input\_imported\_cert\_certificate) | The TLS certificate to import. | `string` | `null` | no |
181182
| <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 |
@@ -204,6 +205,7 @@ No modules.
204205
| Name | Description |
205206
|------|-------------|
206207
| <a name="output_secret_crn"></a> [secret\_crn](#output\_secret\_crn) | CRN of the created Secret |
208+
| <a name="output_secret_group_id"></a> [secret\_group\_id](#output\_secret\_group\_id) | Secret group ID of the created secret |
207209
| <a name="output_secret_id"></a> [secret\_id](#output\_secret\_id) | ID of the created Secret |
208210
| <a name="output_secret_next_rotation_date"></a> [secret\_next\_rotation\_date](#output\_secret\_next\_rotation\_date) | Next rotation date for secret (if applicable) |
209211
| <a name="output_secret_rotation"></a> [secret\_rotation](#output\_secret\_rotation) | Status of auto-rotation for secret |

examples/complete/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ module "secrets_manager_arbitrary_secret" {
7575
secret_type = "arbitrary" #checkov:skip=CKV_SECRET_6
7676
secret_payload_password = local.payload
7777
secret_labels = local.secret_labels
78+
custom_metadata = { "metadata_custom_key" : "metadata_custom_value" } # can add any custom metadata here
7879
}
7980

8081
# retrieving information about the arbitrary secret
@@ -100,6 +101,7 @@ module "secrets_manager_user_pass_secret" {
100101
secret_payload_password = local.payload
101102
secret_username = "terraform-user" #checkov:skip=CKV_SECRET_6
102103
secret_labels = local.secret_labels
104+
custom_metadata = { "metadata_custom_key" : "metadata_custom_value" } # can add any custom metadata here
103105
}
104106

105107
# retrieving information about the userpass secret
@@ -126,6 +128,7 @@ module "secrets_manager_user_pass_no_rotate_secret" {
126128
secret_username = "terraform-user" #checkov:skip=CKV_SECRET_6
127129
secret_labels = local.secret_labels
128130
secret_auto_rotation = false
131+
custom_metadata = { "metadata_custom_key" : "metadata_custom_value" } # can add any custom metadata here
129132
}
130133

131134
# retrieving information about the userpass secret
@@ -190,6 +193,7 @@ module "secret_manager_imported_cert" {
190193
imported_cert_certificate = resource.tls_locally_signed_cert.cert.cert_pem
191194
imported_cert_private_key = resource.tls_private_key.key.private_key_pem
192195
imported_cert_intermediate = resource.tls_self_signed_cert.ca_cert.cert_pem
196+
custom_metadata = { "metadata_custom_key" : "metadata_custom_value" } # can add any custom metadata here
193197
}
194198

195199
##############################################################################
@@ -236,4 +240,5 @@ module "secret_manager_service_credential" {
236240
service_credentials_source_service_crn = module.cloud_object_storage.cos_instance_id
237241
service_credentials_source_service_role_crn = "crn:v1:bluemix:public:iam::::serviceRole:Writer"
238242
service_credentials_parameters = { "service-endpoints" : "public" }
243+
custom_metadata = { "metadata_custom_key" : "metadata_custom_value" } # can add any custom metadata here
239244
}

main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ resource "ibm_sm_arbitrary_secret" "arbitrary_secret" {
5050
labels = var.secret_labels
5151
payload = var.secret_payload_password
5252
endpoint_type = var.endpoint_type
53+
custom_metadata = var.custom_metadata
5354
}
5455

5556
resource "ibm_sm_username_password_secret" "username_password_secret" {
@@ -63,6 +64,7 @@ resource "ibm_sm_username_password_secret" "username_password_secret" {
6364
username = var.secret_username
6465
password = var.secret_payload_password
6566
endpoint_type = var.endpoint_type
67+
custom_metadata = var.custom_metadata
6668

6769
## This for_each block is NOT a loop to attach to multiple rotation blocks.
6870
## This block is only used to conditionally add rotation block depending on var.sm_iam_secret_auto_rotation
@@ -96,6 +98,7 @@ resource "ibm_sm_imported_certificate" "imported_cert" {
9698
private_key = local.imported_cert_private_key
9799
intermediate = local.imported_cert_intermediate
98100
endpoint_type = var.endpoint_type
101+
custom_metadata = var.custom_metadata
99102
}
100103

101104
locals {
@@ -121,6 +124,7 @@ resource "ibm_sm_service_credentials_secret" "service_credentials_secret" {
121124
labels = var.secret_labels
122125
ttl = var.service_credentials_ttl
123126
endpoint_type = var.endpoint_type
127+
custom_metadata = var.custom_metadata
124128

125129
source_service {
126130
instance {

outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ output "secret_crn" {
1212
value = local.secret_crn
1313
}
1414

15+
output "secret_group_id" {
16+
description = "Secret group ID of the created secret"
17+
value = var.secret_group_id
18+
}
19+
1520
output "secret_rotation" {
1621
description = "Status of auto-rotation for secret"
1722
value = local.secret_auto_rotation

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,10 @@ variable "endpoint_type" {
140140
}
141141
}
142142

143+
variable "custom_metadata" {
144+
type = map(string)
145+
description = "Optional metadata to be added to the secret."
146+
default = null
147+
}
143148

144149
##############################################################################

0 commit comments

Comments
 (0)