Skip to content

Commit 1272bee

Browse files
feat: added support for custom credentials secret (#355)
1 parent bd69714 commit 1272bee

File tree

14 files changed

+421
-18
lines changed

14 files changed

+421
-18
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The following attributes and parameters are supported for all secret types:
2424
- `secret_type` : The type of the secret.
2525
- `secret_labels` : Any labels to attach to the secret.
2626

27-
The following attributes and paramters are supported when storing arbitrary secrets:
27+
The following attributes and parameters are supported when storing arbitrary secrets:
2828

2929
- `secret_payload_password`: The payload (for arbitrary secrets) or password (for username and password credentials) of the secret.
3030

@@ -80,7 +80,7 @@ module "secrets_manager_arbitrary_secret" {
8080
secrets_manager_guid = "42454b3b-5b06-407b-a4b3-34d9ef323901"
8181
secret_group_id = "432b91f1-ff6d-4b47-9f06-82debc236d90"
8282
secret_name = "example-arbitrary-secret"
83-
secret_description = "Extended description for the arbirtary secret."
83+
secret_description = "Extended description for the arbitrary secret."
8484
secret_type = "arbitrary"
8585
secret_payload_password = "secret-data" #pragma: allowlist secret
8686
}
@@ -191,6 +191,7 @@ No modules.
191191
| Name | Type |
192192
|------|------|
193193
| [ibm_sm_arbitrary_secret.arbitrary_secret](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/sm_arbitrary_secret) | resource |
194+
| [ibm_sm_custom_credentials_secret.custom_credentials_secret](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/sm_custom_credentials_secret) | resource |
194195
| [ibm_sm_imported_certificate.imported_cert](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/sm_imported_certificate) | resource |
195196
| [ibm_sm_kv_secret.kv_secret](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/sm_kv_secret) | resource |
196197
| [ibm_sm_service_credentials_secret.service_credentials_secret](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/sm_service_credentials_secret) | resource |
@@ -200,11 +201,14 @@ No modules.
200201

201202
| Name | Description | Type | Default | Required |
202203
|------|-------------|------|---------|:--------:|
204+
| <a name="input_custom_credentials_configurations"></a> [custom\_credentials\_configurations](#input\_custom\_credentials\_configurations) | The name of the custom credentials secret configuration. | `string` | `null` | no |
205+
| <a name="input_custom_credentials_parameters"></a> [custom\_credentials\_parameters](#input\_custom\_credentials\_parameters) | Whether to create parameters for custom credentials secret or not | `bool` | `false` | no |
203206
| <a name="input_custom_metadata"></a> [custom\_metadata](#input\_custom\_metadata) | Optional metadata to be added to the secret. | `map(string)` | `null` | no |
204207
| <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 |
205208
| <a name="input_imported_cert_certificate"></a> [imported\_cert\_certificate](#input\_imported\_cert\_certificate) | The TLS certificate to import. | `string` | `null` | no |
206209
| <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 |
207210
| <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 |
211+
| <a name="input_job_parameters"></a> [job\_parameters](#input\_job\_parameters) | The parameters that are passed to the Code Engine job. | <pre>object({<br/> integer_values = optional(map(number))<br/> string_values = optional(map(string))<br/> boolean_values = optional(map(bool))<br/> })</pre> | `{}` | no |
208212
| <a name="input_region"></a> [region](#input\_region) | The region where the Secrets Manager instance is deployed. | `string` | n/a | yes |
209213
| <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 |
210214
| <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 |
@@ -215,7 +219,7 @@ No modules.
215219
| <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 |
216220
| <a name="input_secret_name"></a> [secret\_name](#input\_secret\_name) | Name of the secret to create. | `string` | n/a | yes |
217221
| <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 |
218-
| <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 |
222+
| <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, custom\_credentials | `string` | n/a | yes |
219223
| <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 |
220224
| <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 |
221225
| <a name="input_service_credentials_existing_serviceid_crn"></a> [service\_credentials\_existing\_serviceid\_crn](#input\_service\_credentials\_existing\_serviceid\_crn) | The optional parameter 'serviceid\_crn' for creating service credentials. If not passed in, a new Service ID will be created. For more information see https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/sm_service_credentials_secret#parameters | `string` | `null` | no |
@@ -234,7 +238,7 @@ No modules.
234238
| <a name="output_secret_id"></a> [secret\_id](#output\_secret\_id) | ID of the created Secret |
235239
| <a name="output_secret_next_rotation_date"></a> [secret\_next\_rotation\_date](#output\_secret\_next\_rotation\_date) | Next rotation date for secret (if applicable) |
236240
| <a name="output_secret_rotation"></a> [secret\_rotation](#output\_secret\_rotation) | Status of auto-rotation for secret |
237-
| <a name="output_secret_rotation_interval"></a> [secret\_rotation\_interval](#output\_secret\_rotation\_interval) | Rotation frecuency for secret (if applicable) |
241+
| <a name="output_secret_rotation_interval"></a> [secret\_rotation\_interval](#output\_secret\_rotation\_interval) | Rotation frequency for secret (if applicable) |
238242
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
239243

240244
## Contributing

examples/complete/main.tf

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,152 @@ data "ibm_sm_kv_secret" "kv_secret" {
260260
region = local.sm_region
261261
secret_id = module.secrets_manager_key_value_secret.secret_id
262262
}
263+
264+
##############################################################################
265+
# Example working with Custom Credential Engine
266+
##############################################################################
267+
##############################################################################
268+
# Code Engine Project
269+
##############################################################################
270+
module "code_engine_project" {
271+
source = "terraform-ibm-modules/code-engine/ibm//modules/project"
272+
version = "4.5.8"
273+
name = "${var.prefix}-project"
274+
resource_group_id = module.resource_group.resource_group_id
275+
}
276+
277+
##############################################################################
278+
# Code Engine Secret
279+
##############################################################################
280+
module "code_engine_secret" {
281+
source = "terraform-ibm-modules/code-engine/ibm//modules/secret"
282+
version = "4.5.8"
283+
name = "${var.prefix}-rs"
284+
project_id = module.code_engine_project.id
285+
format = "registry"
286+
data = {
287+
"server" = "private.us.icr.io",
288+
"username" = "iamapikey",
289+
"password" = var.ibmcloud_api_key,
290+
}
291+
}
292+
293+
##############################################################################
294+
# Container Registry Namespace
295+
##############################################################################
296+
resource "ibm_cr_namespace" "rg_namespace" {
297+
name = "${var.prefix}-crn"
298+
resource_group_id = module.resource_group.resource_group_id
299+
}
300+
301+
##############################################################################
302+
# Code Engine Build
303+
##############################################################################
304+
locals {
305+
output_image = "private.us.icr.io/${resource.ibm_cr_namespace.rg_namespace.name}/custom-engine-job"
306+
}
307+
308+
module "code_engine_build" {
309+
source = "terraform-ibm-modules/code-engine/ibm//modules/build"
310+
version = "4.5.8"
311+
name = "${var.prefix}-build"
312+
ibmcloud_api_key = var.ibmcloud_api_key
313+
project_id = module.code_engine_project.id
314+
existing_resource_group_id = module.resource_group.resource_group_id
315+
source_url = "https://github.com/IBM/secrets-manager-custom-credentials-providers"
316+
source_context_dir = "ibmcloud-iam-user-apikey-provider-go"
317+
strategy_type = "dockerfile"
318+
output_secret = module.code_engine_secret.name
319+
output_image = local.output_image
320+
}
321+
322+
##############################################################################
323+
# Code Engine Job
324+
##############################################################################
325+
326+
data "http" "job_config" {
327+
url = "https://raw.githubusercontent.com/IBM/secrets-manager-custom-credentials-providers/refs/heads/main/ibmcloud-iam-user-apikey-provider-go/job_config.json"
328+
request_headers = {
329+
Accept = "application/json"
330+
}
331+
}
332+
333+
locals {
334+
job_env_variables = jsondecode(data.http.job_config.response_body).job_env_variables
335+
}
336+
337+
module "code_engine_job" {
338+
depends_on = [module.code_engine_build]
339+
source = "terraform-ibm-modules/code-engine/ibm//modules/job"
340+
version = "4.5.8"
341+
name = "${var.prefix}-job"
342+
image_reference = local.output_image
343+
image_secret = module.code_engine_secret.name
344+
project_id = module.code_engine_project.id
345+
run_env_variables = [
346+
for env_var in local.job_env_variables : {
347+
type = "literal"
348+
name = env_var.name
349+
value = tostring(env_var.value)
350+
}
351+
]
352+
}
353+
354+
##############################################################################
355+
# Custom Credential Engine and secret
356+
##############################################################################
357+
358+
module "custom_credential_engine" {
359+
depends_on = [module.code_engine_job]
360+
source = "terraform-ibm-modules/secrets-manager-custom-credentials-engine/ibm"
361+
version = "1.0.0"
362+
secrets_manager_guid = local.sm_guid
363+
secrets_manager_region = local.sm_region
364+
custom_credential_engine_name = "${var.prefix}-test-custom-engine"
365+
endpoint_type = "public"
366+
code_engine_project_id = module.code_engine_project.project_id
367+
code_engine_job_name = module.code_engine_job.name
368+
code_engine_region = var.existing_sm_instance_region == null ? var.region : var.existing_sm_instance_region
369+
task_timeout = "10m"
370+
service_id_name = "${var.prefix}-test-service-id"
371+
iam_credential_secret_name = "${var.prefix}-test-iam-secret"
372+
}
373+
374+
resource "ibm_iam_api_key" "api_key" {
375+
name = "${var.prefix}-api-key"
376+
description = "created for secrets-manager-secret complete example"
377+
}
378+
379+
# create arbitrary secret
380+
module "secrets_manager_custom_arbitrary_secret" {
381+
source = "../.."
382+
region = local.sm_region
383+
secrets_manager_guid = local.sm_guid
384+
secret_group_id = module.secrets_manager_group.secret_group_id
385+
secret_name = "${var.prefix}-custom-arbitrary-secret"
386+
secret_description = "created by secrets-manager-secret-module complete example"
387+
secret_type = "arbitrary" #checkov:skip=CKV_SECRET_6
388+
secret_payload_password = ibm_iam_api_key.api_key.apikey
389+
secret_labels = local.secret_labels
390+
custom_metadata = { "metadata_custom_key" : "metadata_custom_value" } # can add any custom metadata here
391+
}
392+
393+
# create custom credentials secret
394+
module "secret_manager_custom_credential" {
395+
depends_on = [module.custom_credential_engine]
396+
source = "../.."
397+
secret_type = "custom_credentials" #checkov:skip=CKV_SECRET_6
398+
region = local.sm_region
399+
secrets_manager_guid = local.sm_guid
400+
secret_name = "${var.prefix}-custom-credentials"
401+
secret_group_id = module.secrets_manager_group.secret_group_id
402+
secret_description = "created by secrets-manager-secret-module complete example"
403+
custom_credentials_configurations = module.custom_credential_engine.custom_config_engine_name
404+
custom_metadata = { "metadata_custom_key" : "metadata_custom_value" } # can add any custom metadata here
405+
custom_credentials_parameters = true
406+
job_parameters = {
407+
string_values = {
408+
apikey_secret_id = module.secrets_manager_custom_arbitrary_secret.secret_id
409+
}
410+
}
411+
}

examples/complete/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,13 @@ output "kv_secret_payload" {
105105
sensitive = true
106106
description = "accessing key value secret"
107107
}
108+
109+
output "custom_credential_secret_id" {
110+
description = "ID of the created custom_credential secret"
111+
value = module.secret_manager_custom_credential.secret_id
112+
}
113+
114+
output "custom_credential_secret_crn" {
115+
description = "CRN of the created custom_credential secret"
116+
value = module.secret_manager_custom_credential.secret_crn
117+
}

examples/complete/variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ variable "ibmcloud_api_key" {
77
variable "prefix" {
88
type = string
99
description = "Prefix to use for naming of all resource created by this example"
10-
default = "test-sm-secret-module"
10+
default = "sm-secret-complete"
1111
}
1212

1313
variable "sm_service_plan" {
@@ -19,7 +19,7 @@ variable "sm_service_plan" {
1919
variable "region" {
2020
type = string
2121
description = "Region to provision Secrets Manager in if not passing a value for var.existing_sm_instance_guid"
22-
default = "au-syd"
22+
default = "us-south" # Region is defaulted to us-south so as to restrict the code engine project to be created in the same region and have a hardcoded output image as `private.us`
2323
}
2424

2525
variable "resource_group" {
@@ -36,7 +36,7 @@ variable "resource_tags" {
3636

3737
variable "existing_sm_instance_guid" {
3838
type = string
39-
description = "Existing Secrets Manager GUID. If not provided an new instance will be provisioned"
39+
description = "Existing Secrets Manager GUID. If not provided an new instance will be provisioned. If existing_sm_instance_guid needs to be used make sure the instance passed belongs to us-south region"
4040
default = null
4141

4242
validation {

examples/complete/version.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ terraform {
99
source = "hashicorp/tls"
1010
version = ">= 4.0.4"
1111
}
12+
http = {
13+
source = "hashicorp/http"
14+
version = "3.2.1" # Use a compatible version
15+
}
1216
}
1317
}

0 commit comments

Comments
 (0)