Skip to content


Folders and files

Last commit message
Last commit date

Latest commit



12 Commits

Repository files navigation


A module to manage Azure Database for PostgreSQL Read Replica until support for PostgreSQL read replicas is implemented. See issue terraform-provider-azurerm#2819 for more details.

Update: As of version 2.7.0, the Azure provider now supports the creation of replicas. I'll be reviewing what if any purpose this module will now play.


  • The module is dependant on the Azure CLI
  • Changes outside of Terraform are not detected, and re-applying does not resolve this.
  • It's not yet possible to break replication and turn the replica into a primary server.
  • It's not yet possible to specify a different location, i.e. cross-region replication.
  • You cannot use this module to import an existing read replica.


The following example creates a read replica in the same location as the primary, and adds a firewall rule to the read replica.

resource "azurerm_resource_group" "demo" {
  location = "uksouth"
  name     = "demo"

resource "azurerm_postgresql_server" "demo" {
  name                = "pr1mary-demo"
  location            = azurerm_resource_group.demo.location
  resource_group_name =
  ... # shortened for the sake of brevity, see the Azure provider documentation for more details

module demo-replica {
  source                         = "booyaa/terraform-azurerm-postgresql-read-replica"
  resource_group_name            =
  postgresql_primary_server_name =
  postgresql_replica_server_name = "${}-replica"

resource "azurerm_postgresql_firewall_rule" "demo-replica" {
  name                = "office"
  resource_group_name =
  server_name         = module.demo-replica.replica_name
  start_ip_address    = ""
  end_ip_address      = ""

  depends_on = [module.demo-replica]


Mark Sta Ana © 2019