Skip to main content

Vaultwarden Common Shared Configuration Module

The Vaultwarden Common module defines the Vaultwarden password manager configuration for the RAD Modules ecosystem. It is a pure configuration module — it creates no GCP resources and produces config and storage_buckets outputs consumed by platform-specific wrapper modules (Vaultwarden CloudRun and Vaultwarden GKE).

1. Overview

Purpose: To centralise all Vaultwarden-specific configuration (container image, database engine detection, health probes, storage bucket, and database initialisation job) in a single module shared by both Cloud Run and GKE deployments.

Architecture:

Layer 3: Application Wrappers
├── Vaultwarden_CloudRun ──┐
└── Vaultwarden_GKE ──┤── instantiate Vaultwarden_Common

Vaultwarden_Common (this module)
Creates: (no GCP resources)
Produces: config, storage_buckets

Layer 2: Platform Modules
├── App_CloudRun (serverless deployment)
└── App_GKE (Kubernetes deployment)

Key characteristics:

  • Supports both PostgreSQL 15 (default) and MySQL 8.0 — detected automatically via database_type regex matching.
  • Creates no GCP resources — no Secret Manager secrets, no IAM bindings.
  • Application-specific environment variables (ROCKET_PORT, SIGNUPS_ALLOWED, DATA_FOLDER, DOMAIN) are injected by the wrapper modules (vaultwarden.tf), not by Vaultwarden Common.
  • Health probes target /alive — Vaultwarden's dedicated lightweight health endpoint.

2. Outputs

config

FieldValue / Description
app_name"vaultwarden"
application_versionVersion tag (default: "1.32.7")
display_namevar.display_name (default: "Vaultwarden")
descriptionvar.description (default: "Vaultwarden password manager")
container_image"vaultwarden/server" (public Docker Hub image)
image_source"custom" — a custom wrapper image is built
enable_image_mirroringvar.enable_image_mirroring (default false)
container_build_configdockerfile_path = "Dockerfile", context_path = abspath("${path.module}/scripts")
container_portvar.container_port (default 80)
database_typevar.database_type (default "POSTGRES_15")
db_nameDatabase name (default: "vaultwarden")
db_userDatabase user (default: "vaultwarden")
enable_cloudsql_volumevar.enable_cloudsql_volume (default true)
cloudsql_volume_mount_path"/cloudsql"
gcs_volumesvar.gcs_volumes
container_resourcesCPU: var.cpu_limit (default "1000m"), Memory: var.memory_limit (default "512Mi")
min_instance_countvar.min_instance_count (default 1)
max_instance_countvar.max_instance_count (default 3)
environment_variablesvar.environment_variables (passed through directly)
secret_environment_variablesvar.secret_environment_variables (default {})
enable_postgres_extensionsfalse
enable_mysql_pluginsfalse
initialization_jobsDefault db-init job (database-type-aware) or custom override — see §5
startup_probevar.startup_probe
liveness_probevar.liveness_probe

storage_buckets

FieldValue
name_suffix"vaultwarden-data" (inferred from module defaults)
storage_class"STANDARD"
versioning_enabledfalse
public_access_prevention"inherited"

3. Input Variables

Application

VariableTypeDefaultDescription
application_namestring"vaultwarden"Application name
application_versionstring"1.32.7"Vaultwarden Docker image tag
display_namestring"Vaultwarden"Human-readable display name
descriptionstring"Vaultwarden password manager"Module description
database_typestring"POSTGRES_15"Database engine. Options: "POSTGRES_15", "MYSQL_8_0". Controls the db-init job image.
db_namestring"vaultwarden"Database name
db_userstring"vaultwarden"Database user
container_portnumber80Vaultwarden's HTTP listen port
cpu_limitstring"1000m"Container CPU limit
memory_limitstring"512Mi"Container memory limit
environment_variablesmap(string){}Environment variables passed through to the container
secret_environment_variablesmap(string){}Secret Manager references
initialization_jobslist(object)[]Custom init jobs; empty triggers the default db-init job
startup_probeobjectsee §4Startup health probe configuration
liveness_probeobjectsee §4Liveness health probe configuration
enable_image_mirroringboolfalseMirror the container image to Artifact Registry
min_instance_countnumber1Minimum running instances
max_instance_countnumber3Maximum running instances

Storage & Volumes

VariableTypeDefaultDescription
enable_cloudsql_volumebooltrueMount Cloud SQL Auth Proxy sidecar socket
gcs_volumeslist(object)[]GCS Fuse volume mounts
regionstring"us-central1"Region for GCS bucket

4. Health Probes

Default probe values (used when startup_probe and liveness_probe are not overridden):

ProbePathInitial DelayTimeoutPeriodFailure Threshold
Startup/alive30s5s10s6
Liveness/alive30s5s30s3

Vaultwarden starts quickly as a compiled Rust binary, so the probe delays are shorter than Node.js or Python-based modules.


5. Initialization Job

Vaultwarden Common detects the database engine from database_type and supplies an appropriate db-init job:

database_typeJob ImageDescription
POSTGRES_15 (or any non-MySQL value)postgres:15-alpineInitialises Vaultwarden PostgreSQL database and user
MYSQL_8_0 (or any value starting with MYSQL)mysql:8.0-debianInitialises Vaultwarden MySQL database and user

Detection logic: is_mysql = length(regexall("^MYSQL", upper(database_type))) > 0

FieldValue
Job namedb-init
execute_on_applytrue
Timeout600s
Max retries3
CPU / Memory1000m / 512Mi
env_vars{ DB_ENGINE = "mysql" or "postgres" }

Override initialization_jobs with a non-empty list to replace this default.


6. Scripts and Container Image

All supporting files are in scripts/. The scripts/ directory is used as the Docker build context.

Dockerfile

Wraps the public vaultwarden/server:<version> image. Copies any runtime configuration scripts needed for the Auth Proxy integration.

db-init.sh

Database initialisation script. Creates the Vaultwarden database and user, granting full privileges. Behaviour adapts based on the DB_ENGINE environment variable (mysql or postgres).


7. Platform-Specific Differences

AspectVaultwarden CloudRunVaultwarden GKE
workload_typeCloud Run serviceStatefulSet (default)
DATA_FOLDER/data (injected by wrapper)/data (PVC mount at /data)
min_instance_count11
session_affinityNot applicable (Cloud Run)"ClientIP" (default)
PVCNot applicable10Gi at /data (default)
DB_HOSTCloud SQL Auth Proxy socketCloud SQL private IP

8. Implementation Pattern

# Example: how Vaultwarden_CloudRun instantiates Vaultwarden_Common

module "vaultwarden_app" {
source = "../Vaultwarden_Common"

application_name = var.application_name
application_version = var.application_version
display_name = var.display_name
description = var.description
database_type = var.database_type
db_name = var.db_name
db_user = var.db_user
container_port = var.container_port
cpu_limit = var.cpu_limit
memory_limit = var.memory_limit
startup_probe = var.startup_probe
liveness_probe = var.liveness_probe
enable_cloudsql_volume = var.enable_cloudsql_volume
gcs_volumes = var.gcs_volumes
region = var.region
}

# Application-specific env vars are injected by the wrapper (not Vaultwarden_Common)
locals {
module_env_vars = merge(
{
ROCKET_PORT = tostring(var.container_port)
SIGNUPS_ALLOWED = tostring(var.signups_allowed)
WEB_VAULT_ENABLED = tostring(var.web_vault_enabled)
DATA_FOLDER = "/data"
},
var.domain != "" ? { DOMAIN = var.domain } : {}
)
module_secret_env_vars = module.vaultwarden_app.secret_ids
module_storage_buckets = module.vaultwarden_app.storage_buckets
}