The key_vault module
A Key Vault with RBAC authorization, purge protection and a deny-by-default network rule, a private endpoint when you name a subnet for it, the engine's database URL as the database-url secret, Key Vault Secrets User for the principal that reads the secrets, Key Vault Secrets Officer for whoever applies (Terraform writes the secret), and the vault's audit log sent to a Log Analytics workspace.
Use it on its own with source = "github.com/cosyte/terraform-azurerm-pathways//modules/key_vault".
This page is generated from the code in modules/key_vault/ by scripts/docs.sh, and CI fails when it no longer matches. Change modules/key_vault/variables.tf or its outputs.tf, then run scripts/docs.sh.
Requirements
| Name | Version |
|---|---|
terraform | >= 1.11.0 |
azurerm | >= 4.42.0, < 5.0.0 |
Resources
azurerm_key_vault.thisazurerm_key_vault_secret.database_urlazurerm_monitor_diagnostic_setting.key_vaultazurerm_private_endpoint.key_vaultazurerm_role_assignment.deployer_secrets_officerazurerm_role_assignment.identity_secrets_userdata.azurerm_client_config.current
Inputs
15 inputs, 5 of them required. The required ones come first, then the rest by name.
location
Required.
The Azure region, such as eastus2.
Type:
string
log_analytics_workspace_id
Required.
The Log Analytics workspace the vault's audit log is sent to.
Type:
string
name
Required.
Short name the vault's name is built from (kv-<name>): 3 to 16 lowercase letters, digits and hyphens, starting with a letter. The vault name is global in Azure, so pick one nobody else uses.
Type:
string
The plan refuses a value that breaks this rule, with this message:
- name must be 3 to 16 lowercase letters, digits and single hyphens, starting with a letter and not ending with a hyphen.
resource_group_name
Required.
The existing resource group the vault is created in.
Type:
string
secrets_reader_principal_id
Required.
The principal that reads the vault's secrets, such as the apps' user-assigned managed identity. It gets Key Vault Secrets User on the vault and nothing more.
Type:
string
allowed_ip_ranges
Optional.
The address ranges allowed through the vault's public endpoint. Has no effect unless public_network_access_enabled is true.
Type:
list(string)
Default: []
The plan refuses a value that breaks this rule, with this message:
- allowed_ip_ranges has no effect unless public_network_access_enabled is true.
database_password
Optional.
The password to put into database_url, as an ephemeral value, such as the value of an ephemeral azurerm_key_vault_secret. The module writes the URL with the password through the secret's write-only value, so neither the plan nor the state holds either. Set with database_password_version; null, the default, writes database_url as it is.
Type:
string
Default: null
database_password_version
Optional.
Set with database_password: Terraform writes the URL with the password only when this number changes, so raise it after the password changes. Null, the default, with no database_password.
Type:
number
Default: null
The plan refuses a value that breaks one of these rules, with its message:
- Set database_password and database_password_version together, or neither: the version says when to write the URL with the password.
- database_password_version must be a whole number, 1 or more.
- With database_password, database_url must be a postgres:// URL with a user and no password, such as postgres://pathways_admin@<host>:5432/pathways: the module puts the password after the user.
database_url
Optional.
The engine's database URL, written to the database-url secret. With no database_password it is written as it is, and the secret's value is in the Terraform state, so pass a URL with no password in it, as the database module's database_url output is. Null with existing_database_url_secret_name, when the URL is a secret you put in the vault yourself.
Type:
string
Default: null
existing_database_url_secret_name
Optional.
The name of a secret you put in this vault yourself, holding the database URL of a PostgreSQL server you already run. The module then writes no database-url secret and never sees the URL, so it stays out of the Terraform state. Null, the default, with database_url: the module writes database-url from it.
Type:
string
Default: null
The plan refuses a value that breaks one of these rules, with its message:
- existing_database_url_secret_name must be a Key Vault secret name: 1 to 127 letters, digits and hyphens.
- Set database_url or existing_database_url_secret_name, one of the two: the module writes the database-url secret from the first, or reads the secret you put in the vault under the second.
private_dns_zone_id
Optional.
The private DNS zone named privatelink.vaultcore.azure.net the private endpoint registers in. Set with private_endpoint_subnet_id, or leave both null.
Type:
string
Default: null
The plan refuses a value that breaks this rule, with this message:
- private_endpoint_subnet_id and private_dns_zone_id are set together or not at all.
private_endpoint_subnet_id
Optional.
A subnet for the vault's private endpoint. Set with private_dns_zone_id, or leave both null.
Type:
string
Default: null
The plan refuses a value that breaks this rule, with this message:
- Nothing could reach the Key Vault: the apps could not read their secrets and the apply could not write database-url. Set private_endpoint_subnet_id and private_dns_zone_id (recommended), or set public_network_access_enabled = true with allowed_ip_ranges naming the runner and the environments' outbound addresses.
public_network_access_enabled
Optional.
Open the vault's public endpoint to the ranges in allowed_ip_ranges. The vault denies every network by default, and the apps and the machine that applies (Terraform writes the database-url secret) both need a way in: a private endpoint (recommended), or this with allowed_ip_ranges naming the runner and the environments' outbound addresses. Container Apps is not a trusted Azure service, so the AzureServices bypass does not let the apps in.
Type:
bool
Default: false
soft_delete_retention_days
Optional.
How long a deleted vault or secret can be recovered: 7 to 90 days. Purge protection is always on.
Type:
number
Default: 90
The plan refuses a value that breaks this rule, with this message:
- soft_delete_retention_days must be from 7 to 90.
tags
Optional.
Tags added to every resource that takes them.
Type:
map(string)
Default: {}
Outputs
7 outputs, by name.
data_plane_id
The Key Vault's resource id, ready only once its private endpoint (when there is one) exists, so a module that writes to the vault's data plane, such as a key, waits for a way in.
database_url_secret_id
The versionless id of the secret that holds the database URL. It is ready only once the reader holds its role, so a container app that reads it can start.
database_url_secret_name
The name of the secret that holds the database URL: database-url, or existing_database_url_secret_name.
id
The Key Vault's resource id.
name
The Key Vault's name.
secrets_writer_id
The Key Vault's resource id, ready only once whoever applies holds Key Vault Secrets Officer on it and its private endpoint (when there is one) exists, so a module that writes a secret to the vault, such as the alarms module, waits for both.
uri
The Key Vault's URI, ending in a slash. A secret's URL is <uri>secrets/<name>.