Resource

dcloud_app_database_binding

Binds a managed database to an app: every rollout generates {prefix}DATABASE_URL and the PG* variables. mode = "app_role" (default) creates a Postgres role of the app's own, its password filed in Secrets; destroying the binding keeps the role and its data.

Example Usage

resource "dcloud_app_database_binding" "main" {
  app_id         = dcloud_app.web.id
  db_instance_id = dcloud_db_instance.main.id
  database       = "web"
  pooled         = true
  redeploy       = true
}

Schema

Required

  • app_id (String) The id of the parent resource ({id} in the path). Changing it replaces the resource.
  • db_instance_id (String) The managed Postgres database (instance) to bind. 3 to 64 characters.

Optional

  • database (String) Database inside the instance (app_role mode creates it if missing). Default: the app’s slug as a Postgres name; in master mode or for a branch, the instance’s own database. Must match ^[a-z_][a-z0-9_]{0,62}$.
  • db_branch_id (String) A branch of the database (ewbr-…) to connect to instead: the branch's master user and port, no pooler. Must match ^ewbr-[0-9a-f]{12}$.
  • env_prefix (String) Prefix of the generated variables (ANALYTICS_ → ANALYTICS_DATABASE_URL); default none. An app has one database binding per prefix. Import id: <app-id>/<prefix>. Changing it replaces the resource.
  • mode (String) app_role (default): a role of the app’s own, its password kept in Secrets; master: the instance’s master credential One of: app_role, master.
  • pooled (Boolean) Connect through the PgBouncer pooler (default true) or straight to Postgres on 5432; ignored for a branch
  • redeploy (Boolean) Start a deployment so the app gets the variables at once. Never returned by the API: not read back, and empty after an import.

Read-Only

  • generated_keys (List of String) The variables the binding generates.
  • id (String) The resource's id.
  • role_name (String) The app's Postgres role (app_role mode).
  • status (String) ready or error.

Import

Import is supported using the following syntax:

The terraform import command can be used, for example:

# <app-id>/<env-prefix>; a binding without a prefix ends in a slash.
terraform import dcloud_app_database_binding.main <app-id>/

Generated from the provider's schema.