116 lines
4.0 KiB
Markdown
116 lines
4.0 KiB
Markdown
# Google Secret Manager Module
|
|
|
|
Simple Secret Manager module that allows managing one or more secrets, their versions, and IAM bindings.
|
|
|
|
Secret Manager locations are available via the `gcloud secrets locations list` command.
|
|
|
|
**Warning:** managing versions will persist their data (the actual secret you want to protect) in the Terraform state in unencrypted form, accessible to any identity able to read or pull the state file.
|
|
|
|
## Examples
|
|
|
|
### Secrets
|
|
|
|
The secret replication policy is automatically managed if no location is set, or manually managed if a list of locations is passed to the secret.
|
|
|
|
```hcl
|
|
module "secret-manager" {
|
|
source = "./modules/secret-manager"
|
|
project_id = "my-project"
|
|
secrets = {
|
|
test-auto = null
|
|
test-manual = ["europe-west1", "europe-west4"]
|
|
}
|
|
}
|
|
```
|
|
|
|
### Secret IAM bindings
|
|
|
|
IAM bindings can be set per secret in the same way as for most other modules supporting IAM, via `iam_roles` and `iam_members` variables.
|
|
|
|
```hcl
|
|
module "secret-manager" {
|
|
source = "./modules/secret-manager"
|
|
project_id = "my-project"
|
|
secrets = {
|
|
test-auto = null
|
|
test-manual = ["europe-west1", "europe-west4"]
|
|
}
|
|
iam_roles = {
|
|
test-auto = ["roles/secretmanager.secretAccessor"]
|
|
test-manual = ["roles/secretmanager.secretAccessor"]
|
|
}
|
|
iam_members = {
|
|
test-auto = {
|
|
"roles/secretmanager.secretAccessor" = ["group:auto-readers@example.com"]
|
|
}
|
|
test-manual = {
|
|
"roles/secretmanager.secretAccessor" = ["group:manual-readers@example.com"]
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
### Secret versions
|
|
|
|
As mentioned above, please be aware that **version data will be stored in state in unencrypted form**.
|
|
|
|
```hcl
|
|
module "secret-manager" {
|
|
source = "./modules/secret-manager"
|
|
project_id = "my-project"
|
|
secrets = {
|
|
test-auto = null
|
|
test-manual = ["europe-west1", "europe-west4"]
|
|
}
|
|
versions = {
|
|
test-auto = {
|
|
v1 = { enabled = false, data = "auto foo bar baz" }
|
|
v2 = { enabled = true, data = "auto foo bar spam" }
|
|
},
|
|
test-manual = {
|
|
v1 = { enabled = true, data = "manual foo bar spam" }
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
<!-- BEGIN TFDOC -->
|
|
## Variables
|
|
|
|
| name | description | type | required | default |
|
|
|---|---|:---: |:---:|:---:|
|
|
| project_id | Project id where the keyring will be created. | <code title="">string</code> | ✓ | |
|
|
| *iam_members* | IAM members keyed by secret name and role. | <code title="map(map(list(string)))">map(map(list(string)))</code> | | <code title="">{}</code> |
|
|
| *iam_roles* | IAM roles keyed by secret name. | <code title="map(list(string))">map(list(string))</code> | | <code title="">{}</code> |
|
|
| *labels* | Optional labels for each secret. | <code title="map(map(string))">map(map(string))</code> | | <code title="">{}</code> |
|
|
| *secrets* | Map of secrets to manage and their locations. If locations is null, automatic management will be set. | <code title="map(list(string))">map(list(string))</code> | | <code title="">{}</code> |
|
|
| *versions* | Optional versions to manage for each secret. Version names are only used internally to track each version and must be unique for each secret/version pair. | <code title="map(list(object({ enabled = bool data = string name = string })))">map(list(object({...})))</code> | | <code title="">{}</code> |
|
|
|
|
## Outputs
|
|
|
|
| name | description | sensitive |
|
|
|---|---|:---:|
|
|
| ids | Secret ids keyed by secret_ids (names). | |
|
|
| secrets | Secret resources. | |
|
|
| version_ids | Version ids keyed by secret name : version name. | |
|
|
| versions | Secret versions. | |
|
|
<!-- END TFDOC -->
|
|
|
|
## Requirements
|
|
|
|
These sections describe requirements for using this module.
|
|
|
|
### IAM
|
|
|
|
The following roles must be used to provision the resources of this module:
|
|
|
|
- Cloud KMS Admin: `roles/cloudkms.admin` or
|
|
- Owner: `roles/owner`
|
|
|
|
### APIs
|
|
|
|
A project with the following APIs enabled must be used to host the
|
|
resources of this module:
|
|
|
|
- Google Cloud Key Management Service: `cloudkms.googleapis.com`
|