Skip to content

Commit

Permalink
feat(DMVP-3754): created gcp-secret and keeper-to-secret-manager modules
Browse files Browse the repository at this point in the history
  • Loading branch information
viktoryathegreat committed Apr 2, 2024
1 parent 94df9e5 commit c77866a
Show file tree
Hide file tree
Showing 14 changed files with 318 additions and 0 deletions.
57 changes: 57 additions & 0 deletions modules/gcp-secret/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## GCP Secret Manager Module
This Terraform module simplifies the creation of secrets within Google Cloud Platform's Secret Manager. Specifically, it is designed to create individual secrets and then populate them with an initial version, allowing for the centralized management of sensitive information across your GCP resources.

### Usage Example
To use this module to create secrets in GCP Secret Manager, define a module block in your Terraform configuration file like the example below:
```
module "this" {
source = "dasmeta/external-secrets/any//modules/gcp-secret"
secrets = {
"product-dev-service-username" = "admin"
"product-dev-service-password" = "root"
}
labels = {
environment = "development"
team = "backend"
}
}
```
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_google"></a> [google](#requirement\_google) | ~> 5.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | ~> 5.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [google_secret_manager_secret.secret](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/secret_manager_secret) | resource |
| [google_secret_manager_secret_version.secret_version](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/secret_manager_secret_version) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_labels"></a> [labels](#input\_labels) | Custom labels to apply to the secret | `map(string)` | `{}` | no |
| <a name="input_secrets"></a> [secrets](#input\_secrets) | Map of secrets where key is the secret name and value is the secret data | `map(string)` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_secret_id"></a> [secret\_id](#output\_secret\_id) | n/a |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
29 changes: 29 additions & 0 deletions modules/gcp-secret/examples/basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# basic

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_this"></a> [this](#module\_this) | ../.. | n/a |

## Resources

No resources.

## Inputs

No inputs.

## Outputs

No outputs.
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
13 changes: 13 additions & 0 deletions modules/gcp-secret/examples/basic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module "this" {
source = "../.."

secrets = {
"product-dev-service-username" = "admin"
"product-dev-service-password" = "root"
}

labels = {
environment = "development"
team = "backend"
}
}
5 changes: 5 additions & 0 deletions modules/gcp-secret/examples/basic/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
provider "google" {
project = "my-project"
region = "us-east1"
credentials = file("/path/to/gcp/config.json")
}
20 changes: 20 additions & 0 deletions modules/gcp-secret/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "google_secret_manager_secret" "secret" {
for_each = var.secrets

secret_id = each.key

labels = merge({
managed = "terraform"
}, var.labels)

replication {
auto {}
}
}

resource "google_secret_manager_secret_version" "secret_version" {
for_each = var.secrets

secret = google_secret_manager_secret.secret[each.key].id
secret_data = each.value
}
3 changes: 3 additions & 0 deletions modules/gcp-secret/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "secret_id" {
value = google_secret_manager_secret.secret
}
8 changes: 8 additions & 0 deletions modules/gcp-secret/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.0"
}
}
}
10 changes: 10 additions & 0 deletions modules/gcp-secret/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variable "secrets" {
description = "Map of secrets where key is the secret name and value is the secret data"
type = map(string)
}

variable "labels" {
description = "Custom labels to apply to the secret"
type = map(string)
default = {}
}
70 changes: 70 additions & 0 deletions modules/keeper-to-secret-manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
## Keeper-to-Secret-Manager Module
The `keeper-to-secret-manager` Terraform module transfers secrets from Keeper Security to Cloud Secret Manager. It automates the retrieval of secrets stored in Keeper and their subsequent storage in Cloud Secret Manager.

## Configuration
The module uses 2 modules.

1. Keeper Reader Module
This submodule is responsible for fetching secrets from Keeper Security. It requires API credentials and a list of secrets to fetch, identified by their UIDs and types.

2. Cloud Secret Module
After secrets are fetched from Keeper, this submodule handles the creation or updating of secrets in Cloud Secret Manager.

Currently, only GCP Secret Manager is supported.
`secret_manager` variable is used to specify the cloud for Secret Manager.

### Usage Example
```
module "keeper_to_gcp" {
source = "dasmeta/external-secrets/any//modules/keeper-to-secret-manager"
keeper_credentials = "/path/to/keeper/config.json"
secret_manager = "gcp"
secrets = [
{
secret_type = "db"
uid = "YwIOVhxwBBONenOZ6ZlPkg"
field = "db_type"
secret_name = "my-db-type"
},
{
secret_type = "login"
uid = "bBdstZ0jCpoA8tZbg1Q8zQ"
field = "login"
secret_name = "my-username"
}
]
}
```
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_keeper-reader"></a> [keeper-reader](#module\_keeper-reader) | dasmeta/shared/any//modules/keeper-reader | n/a |
| <a name="module_secret"></a> [secret](#module\_secret) | ../gcp-secret | n/a |

## Resources

No resources.

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_keeper_credentials"></a> [keeper\_credentials](#input\_keeper\_credentials) | Credentials for accessing Keeper. | `string` | n/a | yes |
| <a name="input_secret_manager"></a> [secret\_manager](#input\_secret\_manager) | The secret manager to use. Currently only `gcp` is supported | `string` | `"gcp"` | no |
| <a name="input_secrets"></a> [secrets](#input\_secrets) | Secrets to fetch from Keeper and create in Cloud Secret Manager | <pre>list(object({<br> secret_type = string<br> uid = string<br> secret_name = string<br> field = string<br> }))</pre> | n/a | yes |

## Outputs

No outputs.
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
29 changes: 29 additions & 0 deletions modules/keeper-to-secret-manager/examples/to-gcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# to-gcp

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_this"></a> [this](#module\_this) | ../../ | n/a |

## Resources

No resources.

## Inputs

No inputs.

## Outputs

No outputs.
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
32 changes: 32 additions & 0 deletions modules/keeper-to-secret-manager/examples/to-gcp/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module "this" {
source = "../../"

keeper_credentials = "/path/to/keeper/config.json"
secret_manager = "gcp"
secrets = [
{
secret_type = "db"
uid = "YwIOVhxwBBONenOZ6ZlPkg"
field = "db_type"
secret_name = "my-db-type"
},
{
secret_type = "login"
uid = "bBdstZ0jCpoA8tZbg1Q8zQ"
field = "login"
secret_name = "my-username"
},
{
secret_type = "login"
uid = "bBdstZ0jCpoA8tZbg1Q8zQ"
field = "password"
secret_name = "my-password"
},
{
secret_type = "db"
uid = "YwIOVhxwBBONenOZ6ZlPkg"
field = "password"
secret_name = "my-db-password"
},
]
}
5 changes: 5 additions & 0 deletions modules/keeper-to-secret-manager/examples/to-gcp/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
provider "google" {
project = "my-project"
region = "us-east1"
credentials = file("/path/to/gcp/config.json")
}
17 changes: 17 additions & 0 deletions modules/keeper-to-secret-manager/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//This module reads from Keeper
module "keeper-reader" {
source = "dasmeta/shared/any//modules/keeper-reader"

keeper_credentials = var.keeper_credentials
secrets = var.secrets
}

//This module writes module.keeper data into GCP secret manager, if var.secret_manager="gcp"
module "secret" {
count = var.secret_manager == "gcp" ? 1 : 0
source = "../gcp-secret"

secrets = {
for index, s in var.secrets : s.secret_name => s.secret_type == "login" ? module.keeper-reader.login_secrets[index][s.field] : s.secret_type == "db" ? module.keeper-reader.db_secrets[index][s.field] : module.keeper-reader.ssh_secrets[index][s.field]
}
}
20 changes: 20 additions & 0 deletions modules/keeper-to-secret-manager/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
variable "secrets" {
description = "Secrets to fetch from Keeper and create in Cloud Secret Manager"
type = list(object({
secret_type = string
uid = string
secret_name = string
field = string
}))
}

variable "keeper_credentials" {
description = "Credentials for accessing Keeper."
type = string
}

variable "secret_manager" {
description = "The secret manager to use. Currently only `gcp` is supported"
type = string
default = "gcp"
}

0 comments on commit c77866a

Please sign in to comment.