Terraform module to create and manage the Azure flexible server for database with one of supported engines:
Key features:
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 = "~> 4.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
~> 4.0 and run
terraform init -upgrade
For the safest setup, use strict pinning with version = "4.0.0"
|
Module
45% off
|
$578
|
| TOTAL | $578 |
Terraform module to create and manage the Azure flexible server for database with one of supported engines:
Key features:
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 = "~> 4.0"
name = "bar"
resource_group_name = azurerm_resource_group.foo.name
region = azurerm_resource_group.foo.location
db_engine = "mysql"
}
Create PostgreSQL flexible server with app database, 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.bar.name
address_prefixes = ["10.0.2.0/24"]
service_endpoint {
service = "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_id = azurerm_private_dns_zone.biz.id
virtual_network_id = azurerm_virtual_network.bar.id
depends_on = [azurerm_subnet.baz]
}
module "postgresql_flexible_server" {
source = "solutions.corewide.com/azure/tf-azure-database-flexible-server/azurerm"
version = "~> 4.0"
name = "bar"
resource_group_name = azurerm_resource_group.foo.name
region = azurerm_resource_group.foo.location
db_engine = "postgresql"
replica_count = 2
machine_storage_size = 128
subnet_id = azurerm_subnet.baz.id
private_dns_zone_id = azurerm_private_dns_zone.biz.id
databases = [
{
name = "app"
charset = "utf8"
collation = "en_US.utf8"
},
]
configuration = {
"backslash_quote" = "on"
"azure.extensions" = "CUBE,CITEXT,BTREE_GIST"
}
firewall_rules = [
{
target = "all"
name = "developer"
cidr = "xxx.xxx.xxx.xxx/32"
},
{
target = "replica"
name = "backend"
start_ip_address = "xxx.xxx.xxx.xxx"
end_ip_address = "yyy.yyy.yyy.yyy"
},
]
depends_on = [
# Private DNS zone network peering must be already created for flexible server with VNet integration
azurerm_private_dns_zone_virtual_network_link.foo,
]
}
| Variable | Description | Type | Default | Required | Sensitive |
|---|---|---|---|---|---|
db_engine |
Database engine. Supported values are PostgreSQL and MySQL |
string |
yes | no | |
name |
Flexible server name | string |
yes | no | |
region |
Resource group location where resources should be created | string |
yes | no | |
resource_group_name |
The resource group name in which resources should be created | string |
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 |
databases |
List of database objects to create | list(object) |
[] |
no | no |
databases[*].charset |
Database charset. If not specified, these values are considered as default: utf8mb4 for MySQL and utf8 for PostgreSQL |
string |
no | no | |
databases[*].collation |
Database collation. If not specified, these values are considered as default: utf8mb4_general_ci for MySQL and en_US.utf8 for PostgreSQL |
string |
no | no | |
databases[*].name |
Database name | string |
yes | 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 | |
firewall_rules |
List of firewall rules to add to the setup | list(object) |
[] |
no | no |
firewall_rules[*].cidr |
CIDR block to allow database access for. Each rule must either specify cidr or both start_ip_address and end_ip_address |
string |
no | no | |
firewall_rules[*].end_ip_address |
End IP Address associated with the Firewall Rule. Each rule must either specify cidr or both start_ip_address and end_ip_address. Use value 0.0.0.0 for all Azure-internal IP addresses |
string |
no | no | |
firewall_rules[*].name |
Firewall name | string |
yes | no | |
firewall_rules[*].start_ip_address |
Start IP Address associated with the Firewall Rule. Each rule must either specify cidr or both start_ip_address and end_ip_address. Use value 0.0.0.0 for all Azure-internal IP addresses |
string |
no | no | |
firewall_rules[*].target |
Rule target. Possible values are: main for main cluster, replica for all replicas and all for both main cluster and all its replicas |
string |
yes | no | |
machine_size |
Specifies the machine size (SKU name) for the flexible server | string |
GP_Standard_D2ds_v4 |
no | no |
machine_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 | |
maintenance_window |
Maintenance window configuration. Not applicable for servers with mysql engine and burstable SKUs |
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 an existing private DNS zone in which resources should be created. Leave unset to omit networking integration | string |
no | no | |
public_network_access_enabled |
Toggle public network availability of flexible server (will be ignored and disabled if delegated subnet and private DNS zone are set) | bool |
true |
no | no |
replica_count |
Number of replica servers to create | number |
0 |
no | no |
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 | |
tags |
Tags to attach to flexible server | map(string) |
{} |
no | no |
vnet_id |
VNet ID to place virtual link into | string |
no | no |
| Output | Description | Type | Sensitive |
|---|---|---|---|
databases |
Databases created by the module | computed |
no |
fqdn |
FQDN of created database server | computed |
no |
replicas |
Contains attributes of replica servers | list(computed) |
yes |
server |
Contains attributes of main flexible server | computed |
yes |
| Dependency | Version | Kind |
|---|---|---|
terraform |
>= 1.9 |
CLI |
hashicorp/azurerm |
~> 5.0 |
provider |
hashicorp/random |
~> 3.3 |
provider |