Terraform module to create and manage the Azure Flexible Server for database with one of supported engines:

  • MySQL
  • PostgreSQL

This module is meant to be used with an already created Resource Group.

Azure Flexible Server for MySQL and PostgreSQL

Deploys managed MySQL or PostgreSQL engine in Azure Flexible Server
$600
BUY
179
Log in to Corewide IaC registry

Once you have a Corewide Solutions Portal account, this one-time action will use your browser session to retrieve credentials:

 shellterraform login solutions.corewide.com
Provision instructions

Initialize mandatory providers:

Copy and paste into your Terraform configuration and insert the variables:

 hclmodule "tf_azure_database_flexible_server" {
  source  = "solutions.corewide.com/azure/tf-azure-database-flexible-server/azurerm"
  version = "~> 2.0.0"

  # specify module inputs here or try one of the examples below
  ...
}

Initialize the setup:

 shellterraform init
Define update strategy

Corewide DevOps team strictly follows Semantic Versioning Specification to provide our clients with products that have predictable upgrades between versions. We recommend pinning patch versions of our modules using pessimistic constraint operator (~>) to prevent breaking changes during upgrades.

To get new features during the upgrades (without breaking compatibility), use ~> 2.0 and run terraform init -upgrade

For the safest setup, use strict pinning with version = "2.0.0"

v2.0.0 released 7 months ago
New version approx. every 5 weeks

Create MySQL Flexible Server with required parameters only:

 hclresource "azurerm_resource_group" "foo" {
  name     = "foo"
  location = "eastus"
}

module "mysql_flexible_server" {
  source  = "solutions.corewide.com/azure/tf-azure-database-flexible-server/azurerm"
  version = "~> 2.0"

  name            = "bar"
  resource_group  = azurerm_resource_group.foo
  database_engine = "mysql"
}

Create PostgreSQL Flexible Server with custom parameters and pointed to custom subnet:

 hclresource "azurerm_resource_group" "foo" {
  name     = "foo"
  location = "eastus"
}

resource "azurerm_virtual_network" "bar" {
  name                = "bar-vn"
  location            = azurerm_resource_group.foo.location
  resource_group_name = azurerm_resource_group.foo.name
  address_space       = ["10.0.0.0/16"]
}

resource "azurerm_subnet" "baz" {
  name                 = "baz-sn"
  resource_group_name  = azurerm_resource_group.foo.name
  virtual_network_name = azurerm_virtual_network.foo.name
  address_prefixes     = ["10.0.2.0/24"]
  service_endpoints    = ["Microsoft.Storage"]

  delegation {
    name = "fs"

    service_delegation {
      name    = "Microsoft.DBforPostgreSQL/flexibleServers"
      actions = ["Microsoft.Network/virtualNetworks/subnets/join/action"]
    }
  }
}

resource "azurerm_private_dns_zone" "biz" {
  name                = "biz.postgres.database.azure.com"
  resource_group_name = azurerm_resource_group.foo.name
}

resource "azurerm_private_dns_zone_virtual_network_link" "foo" {
  name                  = "foo-postgresql"
  private_dns_zone_name = azurerm_private_dns_zone.biz.name
  virtual_network_id    = azurerm_virtual_network.bar.id
  resource_group_name   = azurerm_resource_group.foo.name
  depends_on            = [azurerm_subnet.baz]
}

module "postgresql_flexible_server" {
  source  = "solutions.corewide.com/azure/tf-azure-database-flexible-server/azurerm"
  version = "~> 2.0"

  name                = "bar"
  resource_group      = azurerm_resource_group.foo
  database_engine     = "postgresql"
  replica_count       = 2
  storage_size        = 128
  delegated_subnet_id = azurerm_subnet.baz.id
  private_dns_zone_id = azurerm_private_dns_zone.biz.id

  configuration = {
    "backslash_quote"  = "on"
    "azure.extensions" = "CUBE,CITEXT,BTREE_GIST"
  }
}
Variable Description Type Default Required Sensitive
database_engine Database engine. Supported values are PostgreSQL and MySQL string yes no
name Flexible Server name string yes no
resource_group Object with attributes of Resource Group in which resources should be created. Keys name and location are required any yes no
administrator_login Administrator login for the Flexible Server string sqladmin no no
administrator_password Password associated with the administrator_login for the Flexible Server. Will be generated if not specified string no yes
backup_retention_days Backup retention days for the Flexible Server number 7 no no
configuration Flexible Server configuration parameter name and value declared in the key-value format. Each parameter must be a valid MySQL or PostgreSQL configuration name, respectively map(any) {} no no
delegated_subnet_id ID of the virtual network subnet to create the Flexible Server in (the private DNS zone is required to declare when setting a delegated subnet). The VNet subnet to place the Flexible Server into should have a service delegation Microsoft.DBforMySQL/flexibleServers for MySQL and Microsoft.DBforPostgreSQL/flexibleServers for PostgreSQL. The provided subnet must not have any other kinds of resources deployed in it string no no
engine_version Version for current database engine. If not specified, these values are considered as default: 5.7 for MySQL and 15 for PostgreSQL string no no
maintenance_window Maintenance window configuration object {} no no
maintenance_window.day Day of the week (Mon, Tue, etc.) the maintenance window occurs string Mon no no
maintenance_window.hour Hour when the maintenance updates are applied, in UTC 24-hour format. Examples: 2, 3, 23 number 2 no no
private_dns_zone_id ID of the private DNS zone to create the Flexible Server in. The private DNS zone for pointing Flexible Server must end with suffix .mysql.database.azure.com for MySQL and with .postgres.database.azure.com for PostgreSQL engine, respectively string no no
replica_count Number of replica servers to create number 0 no no
sku_name Specifies the Machine Size (SKU Name) for the Flexible Server string GP_Standard_D2ds_v4 no no
storage_size Server storage size (Gb). If not specified, these values are considered as default: 20 for MySQL and 32 for PostgreSQL number no no
tags Tags to attach to Flexible Server map(string) {} no no
Output Description Type Sensitive
replicas Contains attributes of replica servers list(computed) yes
server Contains attributes of main Flexible Server computed yes
Dependency Version Kind
terraform >= 1.3 CLI
hashicorp/azurerm ~> 4.0 provider
hashicorp/random ~> 3.3 provider

Not sure where to start?
Let's find your perfect match.