|
| 1 | +# Azure Database for MariaDB Terraform Module |
| 2 | + |
| 3 | +Azure Database for MariaDB is a relational database service based on the open-source MariaDB Server engine. It's a fully managed database as a service offering that can handle mission-critical workloads with predictable performance and dynamic scalability. |
| 4 | + |
| 5 | +## Module Usage (MariaDB with optional resources) |
| 6 | + |
| 7 | +```terraform |
| 8 | +module "mariadb" { |
| 9 | + source = "kumarvna/mariadb-server/azurerm" |
| 10 | + version = "1.0.0" |
| 11 | +
|
| 12 | + # By default, this module will create a resource group |
| 13 | + # proivde a name to use an existing resource group and set the argument |
| 14 | + # to `create_resource_group = false` if you want to existing resoruce group. |
| 15 | + # If you use existing resrouce group location will be the same as existing RG. |
| 16 | + create_resource_group = false |
| 17 | + resource_group_name = "rg-shared-westeurope-01" |
| 18 | + location = "westeurope" |
| 19 | +
|
| 20 | + # MariaDB Server and Database settings |
| 21 | + mariadb_server_name = "mariadbsqlsrv01" |
| 22 | +
|
| 23 | + mariadb_settings = { |
| 24 | + sku_name = "GP_Gen5_16" |
| 25 | + storage_mb = 5120 |
| 26 | + version = "10.2" |
| 27 | + # default admin user `sqladmin` and can be specified as per the choice here |
| 28 | + # by default random password created by this module. required password can be specified here |
| 29 | + admin_username = "sqladmin" |
| 30 | + admin_password = "H@Sh1CoR3!" |
| 31 | + # Database name, charset and collection arguments |
| 32 | + database_name = "demomariadb01" |
| 33 | + charset = "utf8" |
| 34 | + collation = "utf8_unicode_ci" |
| 35 | + # Storage Profile and other optional arguments |
| 36 | + auto_grow_enabled = true |
| 37 | + backup_retention_days = 7 |
| 38 | + geo_redundant_backup_enabled = false |
| 39 | + public_network_access_enabled = true |
| 40 | + ssl_enforcement_enabled = true |
| 41 | + } |
| 42 | +
|
| 43 | + # Sets a MariaDB Configuration value on a MariaDB Server. |
| 44 | + # For more information: https://mariadb.com/kb/en/server-system-variables/ |
| 45 | + mariadb_configuration = { |
| 46 | + interactive_timeout = "600" |
| 47 | + } |
| 48 | +
|
| 49 | + # Use Virtual Network service endpoints and rules for Azure Database for MariaDB |
| 50 | + subnet_id = var.subnet_id |
| 51 | +
|
| 52 | + # (Optional) To enable Azure Monitoring for Azure MariaDB database |
| 53 | + # (Optional) Specify `enable_logs_to_storage_account` to save monitoring logs to storage. |
| 54 | + # Create required storage account by specifying optional `storage_account_name` variable. |
| 55 | + log_analytics_workspace_name = "loganalytics-we-sharedtest2" |
| 56 | + enable_logs_to_storage_account = true |
| 57 | + storage_account_name = "mariadblogdignostics" |
| 58 | +
|
| 59 | + # Firewall Rules to allow azure and external clients and specific Ip address/ranges. |
| 60 | + firewall_rules = { |
| 61 | + access-to-azure = { |
| 62 | + start_ip_address = "0.0.0.0" |
| 63 | + end_ip_address = "0.0.0.0" |
| 64 | + }, |
| 65 | + desktop-ip = { |
| 66 | + start_ip_address = "49.204.228.223" |
| 67 | + end_ip_address = "49.204.228.223" |
| 68 | + } |
| 69 | + } |
| 70 | +
|
| 71 | + # Tags for Azure Resources |
| 72 | + tags = { |
| 73 | + Terraform = "true" |
| 74 | + Environment = "dev" |
| 75 | + Owner = "test-user" |
| 76 | + } |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +## Module Usage (MariaDB with Private Endpoint and other optional resources) |
| 81 | + |
| 82 | +```hcl |
| 83 | +module "mariadb" { |
| 84 | + source = "kumarvna/mariadb-server/azurerm" |
| 85 | + version = "1.0.0" |
| 86 | +
|
| 87 | + # By default, this module will create a resource group |
| 88 | + # proivde a name to use an existing resource group and set the argument |
| 89 | + # to `create_resource_group = false` if you want to existing resoruce group. |
| 90 | + # If you use existing resrouce group location will be the same as existing RG. |
| 91 | + create_resource_group = false |
| 92 | + resource_group_name = "rg-shared-westeurope-01" |
| 93 | + location = "westeurope" |
| 94 | +
|
| 95 | + # MariaDB Server and Database settings |
| 96 | + mariadb_server_name = "mariadbsqlsrv01" |
| 97 | +
|
| 98 | + mariadb_settings = { |
| 99 | + sku_name = "GP_Gen5_16" |
| 100 | + storage_mb = 5120 |
| 101 | + version = "10.2" |
| 102 | + # default admin user `sqladmin` and can be specified as per the choice here |
| 103 | + # by default random password created by this module. required password can be specified here |
| 104 | + admin_username = "sqladmin" |
| 105 | + admin_password = "H@Sh1CoR3!" |
| 106 | + # Database name, charset and collection arguments |
| 107 | + database_name = "demomariadb01" |
| 108 | + charset = "utf8" |
| 109 | + collation = "utf8_unicode_ci" |
| 110 | + # Storage Profile and other optional arguments |
| 111 | + auto_grow_enabled = true |
| 112 | + backup_retention_days = 7 |
| 113 | + geo_redundant_backup_enabled = false |
| 114 | + public_network_access_enabled = true |
| 115 | + ssl_enforcement_enabled = true |
| 116 | + } |
| 117 | +
|
| 118 | + # Sets a MariaDB Configuration value on a MariaDB Server. |
| 119 | + # For more information: https://mariadb.com/kb/en/server-system-variables/ |
| 120 | + mariadb_configuration = { |
| 121 | + interactive_timeout = "600" |
| 122 | + } |
| 123 | +
|
| 124 | + # Use Virtual Network service endpoints and rules for Azure Database for MariaDB |
| 125 | + subnet_id = var.subnet_id |
| 126 | +
|
| 127 | + # (Optional) To enable Azure Monitoring for Azure MariaDB database |
| 128 | + # (Optional) Specify `enable_logs_to_storage_account` to save monitoring logs to storage. |
| 129 | + # Create required storage account by specifying optional `storage_account_name` variable. |
| 130 | + log_analytics_workspace_name = "loganalytics-we-sharedtest2" |
| 131 | + enable_logs_to_storage_account = true |
| 132 | + storage_account_name = "mariadblogdignostics" |
| 133 | +
|
| 134 | + # Creating Private Endpoint requires, VNet name and address prefix to create a subnet |
| 135 | + # By default this will create a `privatelink.mysql.database.azure.com` DNS zone. |
| 136 | + # To use existing private DNS zone specify `existing_private_dns_zone` with valid zone name |
| 137 | + enable_private_endpoint = true |
| 138 | + virtual_network_name = "vnet-shared-hub-westeurope-001" |
| 139 | + private_subnet_address_prefix = ["10.1.5.0/29"] |
| 140 | + # existing_private_dns_zone = "demo.example.com" |
| 141 | +
|
| 142 | + # Firewall Rules to allow azure and external clients and specific Ip address/ranges. |
| 143 | + firewall_rules = { |
| 144 | + access-to-azure = { |
| 145 | + start_ip_address = "0.0.0.0" |
| 146 | + end_ip_address = "0.0.0.0" |
| 147 | + }, |
| 148 | + desktop-ip = { |
| 149 | + start_ip_address = "49.204.228.223" |
| 150 | + end_ip_address = "49.204.228.223" |
| 151 | + } |
| 152 | + } |
| 153 | +
|
| 154 | + # Tags for Azure Resources |
| 155 | + tags = { |
| 156 | + Terraform = "true" |
| 157 | + Environment = "dev" |
| 158 | + Owner = "test-user" |
| 159 | + } |
| 160 | +} |
| 161 | +``` |
| 162 | + |
| 163 | +## Terraform Usage |
| 164 | + |
| 165 | +To run this example you need to execute following Terraform commands |
| 166 | + |
| 167 | +```hcl |
| 168 | +terraform init |
| 169 | +
|
| 170 | +terraform plan |
| 171 | +
|
| 172 | +terraform apply |
| 173 | +``` |
| 174 | + |
| 175 | +Run `terraform destroy` when you don't need these resources. |
0 commit comments