Terraform module to create and manage the Azure Flexible Server for database with one of supported engines:
This module is meant to be used with an already created Resource Group.
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
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
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"
|
Module
45% off
|
€530
|
| TOTAL | €530 |
Terraform module to create and manage the Azure Flexible Server for database with one of supported engines:
This module is meant to be used with an already created Resource Group.
All notable changes to this project are documented here.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
BREAKING CHANGE: the new version has several breaking changes that are incompatible with previous versions, see the Upgrade Notes section
private_dns_zone_id input for declaring the ID of an existing private DNS zone for networking integrationpublic_network_access_enabled input to toggle public network availability of flexible serverresource_group_name and region inputs to define the resource group and location for the managed resources5.0database_engine input to db_enginedelegated_subnet_id input to subnet_idsku_name input to machine_sizestorage_size input to machine_storage_sizeprivate_dns_zone object input in favor of private_dns_zone_idpostgres_public_network_access_enabled input in favor of public_network_access_enabledresource_group object input in favor of dedicated inputs: resource_group_name and region(Last version compatible with the Azure Terraform provider version 4.0)
postgres as the database engine17 and 18 for PostgreSQL, and 8.4 for MySQL1.9 due to using cross-object referencing for input variable validations4.57firewall_rules variable to manage firewall rules for cluster, replicas, or bothMySQL engine and burstable SKUs (in accordance with scheduled maintenance concepts)postgres_public_network_access_enabled parameter to toggle public network availability of PostgreSQL flexible server (will be ignored and disabled if delegated subnet and private DNS zone are set)BREAKING CHANGE: private_dns_zone_id variable was removed in favor of private_dns_zone variable which contains not only of id but name and resource_group_name of private DNS zone
databases variableprivate_dns_zone, vnet_idprivate_dns_zone_id variablemaintenance_window variable to control effective maintenance window parameters4.0(Last version compatible with the Azure Terraform provider version 3.0)
First stable version
MySQL or PostgreSQL database enginev1.x to v2.xModule from v2.0 has changed Azure Terraform provider version, which isn't compatible with older versions. After the module version is upgraded, re-init the module to upgrade the provider version. Upgrade the Azure provider version at the project level:
hclterraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 4.0"
}
}
}
Upgrade project dependencies:
bashterraform init --upgrade
Update the declaration of the module according to the requirements and examples to match the designed configuration, then the configuration can be applied.
Apply the changes to make sure the state of the resources is up-to-date with the new provider version:
bashterraform apply
v2.x to v3.xModule from v3.0 has changed private DNS zone managing. After the module version is upgraded, private_dns_zone_id value should be set as private_dns_zone.id parameter if used. New required vnet_id variable added, check variables inputs for references.
Update the declaration of the module according to the requirements and examples to match the designed configuration, then the configuration can be applied.
v3.x to v4.xModule from v4.0 has several breaking changes that require attention:
```hcl
module "sql_database_flexible" {
...
# From v3.x format
database_engine = "postgresql"
sku_name = "GP_Standard_D2ds_v4"
storage_size = 32
delegated_subnet_id = "/subscriptions/123-qwerty-456-uiop/resourceGroups/foo/providers/Microsoft.Network/virtualNetworks/bar/subnets/mysubnet"
postgres_public_network_access_enabled = false
verilogresource_group = {
name = "foo"
location = "eastus"
}
private_dns_zone = {
id = "/subscriptions/123-qwerty-456-uiop/resourceGroups/foo/providers/Microsoft.Network/privateDnsZones/bar.postgres.database.azure.com"
name = "bar.postgres.database.azure.com"
resource_group_name = "foo"
}
# To v4.0 format
resource_group_name = "foo"
region = "eastus"
db_engine = "postgresql"
machine_size = "GP_Standard_D2ds_v4"
machine_storage_size = 32
subnet_id = "/subscriptions/123-qwerty-456-uiop/resourceGroups/foo/providers/Microsoft.Network/virtualNetworks/bar/subnets/mysubnet"
private_dns_zone_id = "/subscriptions/123-qwerty-456-uiop/resourceGroups/foo/providers/Microsoft.Network/privateDnsZones/bar.postgres.database.azure.com"
public_network_access_enabled = false
}
```
hcl
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 5.0"
}
}
}
Upgrade project dependencies:
bash
terraform init --upgrade
Apply the changes to make sure the state of the resources is up-to-date with the new provider version:
bashterraform apply
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 |