Skip to main content

The database module

A PostgreSQL flexible server with private access only (a delegated subnet and a private DNS zone), TLS required at version 1.2 or later, an optional Entra administrator, an optional zone-redundant standby, and the pathways database.

Use it on its own with source = "github.com/cosyte/terraform-azurerm-pathways//modules/database".

This page is generated from the code in modules/database/ by scripts/docs.sh, and CI fails when it no longer matches. Change modules/database/variables.tf or its outputs.tf, then run scripts/docs.sh.

Requirements​

NameVersion
terraform>= 1.11.0
azurerm>= 4.42.0, < 5.0.0

Resources​

  • azurerm_postgresql_flexible_server.this
  • azurerm_postgresql_flexible_server_active_directory_administrator.engine
  • azurerm_postgresql_flexible_server_active_directory_administrator.this
  • azurerm_postgresql_flexible_server_configuration.require_secure_transport
  • azurerm_postgresql_flexible_server_configuration.ssl_min_protocol_version
  • azurerm_postgresql_flexible_server_database.pathways
  • data.azurerm_client_config.current

Inputs​

17 inputs, 5 of them required. The required ones come first, then the rest by name.

delegated_subnet_id​

Required.

A subnet delegated to Microsoft.DBforPostgreSQL/flexibleServers. The server has private access only.

Type:

string

location​

Required.

The Azure region, such as eastus2.

Type:

string

name​

Required.

Short name the server's name is built from (psql-<name>): 3 to 16 lowercase letters, digits and hyphens, starting with a letter. The server 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.

private_dns_zone_id​

Required.

A private DNS zone whose name ends in .postgres.database.azure.com, linked to the virtual network.

Type:

string

The plan refuses a value that breaks this rule, with this message:

  • private_dns_zone_id must be a private DNS zone whose name ends in .postgres.database.azure.com.

resource_group_name​

Required.

The existing resource group the server is created in.

Type:

string

administrator_password​

Optional.

The password of the server's password administrator, pathways_admin, as an ephemeral value: read it from your own Key Vault with an ephemeral azurerm_key_vault_secret and pass its value. It reaches the server only through a write-only argument, so neither the plan nor the state holds it. Null, the default, keeps password authentication off. Set with administrator_password_version.

Type:

string

Default: null

administrator_password_version​

Optional.

Turns password authentication on beside Microsoft Entra ID, and the engine then signs in with administrator_password. Terraform writes the password to the server only when this number changes, so raise it after you change the secret. Null, the default, keeps password authentication off.

Type:

number

Default: null

The plan refuses a value that breaks one of these rules, with its message:

  • administrator_password_version must be a whole number, 1 or more: the password is written again only when it changes.
  • Set administrator_password and administrator_password_version together, or neither: the version turns password authentication on and the password is what it writes.

backup_retention_days​

Optional.

How long backups are kept: 7 to 35 days.

Type:

number

Default: 35

The plan refuses a value that breaks this rule, with this message:

  • backup_retention_days must be from 7 to 35.

engine_identity​

Optional.

The managed identity the engine and the migrate job run as: its principal id and its name. By default it is made a Microsoft Entra administrator of the server, and the database URL signs in as it with no password. Required unless administrator_password_version is set.

Type:

object({
object_id = string
principal_name = string
})

Default: null

The plan refuses a value that breaks this rule, with this message:

  • Set engine_identity, so the engine signs in with Microsoft Entra ID, or administrator_password_version with administrator_password, for a password: the engine needs one way to sign in to the server.

entra_administrator​

Optional.

A Microsoft Entra principal made an administrator of the server, such as a group of the people who run it. Null makes none. Entra authentication is on either way.

Type:

object({
object_id = string
principal_name = string
principal_type = string
})

Default: null

The plan refuses a value that breaks this rule, with this message:

  • entra_administrator.principal_type must be User, Group or ServicePrincipal.

geo_redundant_backup_enabled​

Optional.

Keep backups in the paired region as well.

Type:

bool

Default: false

high_availability_standby_zone​

Optional.

The availability zone of a zone-redundant standby. Null creates no standby.

Type:

string

Default: null

postgres_version​

Optional.

The PostgreSQL major version.

Type:

string

Default: "16"

sku_name​

Optional.

The server's SKU.

Type:

string

Default: "GP_Standard_D2ds_v5"

storage_mb​

Optional.

The server's storage in MB.

Type:

number

Default: 32768

tags​

Optional.

Tags added to the server.

Type:

map(string)

Default: {}

zone​

Optional.

The availability zone of the primary. Null lets Azure choose.

Type:

string

Default: null

Outputs​

7 outputs, by name.

administrator_login​

The password administrator's login, pathways_admin, with administrator_password_version. Null by default: the server has no password administrator.

database​

The database the engine uses.

database_url​

The engine's database URL, postgres://<database_user>@<host>:5432/pathways. It never holds a password: with administrator_password_version, give the password and its version to the key_vault module as database_password and database_password_version, which writes the URL with the password into the vault through a write-only argument.

database_user​

The role the engine signs in as: engine_identity.principal_name by default, or pathways_admin with administrator_password_version.

fqdn​

The PostgreSQL server's host name, resolvable through the private DNS zone.

id​

The PostgreSQL server's resource id.

name​

The PostgreSQL server's name.