|
| 1 | +# Azure Database for MySQL Terraform Module |
| 2 | + |
| 3 | +Azure Database for MySQL is easy to set up, manage and scale. It automates the management and maintenance of your infrastructure and database server, including routine updates, backups and security. Enjoy maximum control of database management with custom maintenance windows and multiple configuration parameters for fine grained tuning with Flexible Server (Preview). |
| 4 | + |
| 5 | +## Module Usage |
| 6 | + |
| 7 | +```hcl |
| 8 | +module "mssql-server" { |
| 9 | + source = "kumarvna/mysql-db/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 | + # MySQL Server and Database settings |
| 21 | + mysqlserver_name = "roshmysqldbsrv01" |
| 22 | +
|
| 23 | + mysqlserver_settings = { |
| 24 | + sku_name = "GP_Gen5_16" |
| 25 | + storage_mb = 5120 |
| 26 | + version = "5.7" |
| 27 | + # Database name, charset and collection arguments |
| 28 | + database_name = "roshydemomysqldb" |
| 29 | + charset = "utf8" |
| 30 | + collation = "utf8_unicode_ci" |
| 31 | + # Storage Profile and other optional arguments |
| 32 | + auto_grow_enabled = true |
| 33 | + backup_retention_days = 7 |
| 34 | + geo_redundant_backup_enabled = false |
| 35 | + infrastructure_encryption_enabled = false |
| 36 | + public_network_access_enabled = true |
| 37 | + ssl_enforcement_enabled = true |
| 38 | + ssl_minimal_tls_version_enforced = "TLS1_2" |
| 39 | + } |
| 40 | +
|
| 41 | + # MySQL Server Parameters |
| 42 | + # For more information: https://docs.microsoft.com/en-us/azure/mysql/concepts-server-parameters |
| 43 | + mysql_configuration = { |
| 44 | + interactive_timeout = "600" |
| 45 | + } |
| 46 | +
|
| 47 | + # Use Virtual Network service endpoints and rules for Azure Database for MySQL |
| 48 | + subnet_id = var.subnet_id |
| 49 | +
|
| 50 | + # The URL to a Key Vault custom managed key |
| 51 | + key_vault_key_id = var.key_vault_key_id |
| 52 | +
|
| 53 | + # To enable Azure Defender for database set `enable_threat_detection_policy` to true |
| 54 | + enable_threat_detection_policy = true |
| 55 | + log_retention_days = 30 |
| 56 | + email_addresses_for_alerts = ["[email protected]", "[email protected]"] |
| 57 | +
|
| 58 | + # AD administrator for an Azure MySQL server |
| 59 | + # Allows you to set a user or group as the AD administrator for an Azure SQL server |
| 60 | + ad_admin_login_name = "[email protected]" |
| 61 | +
|
| 62 | + # (Optional) To enable Azure Monitoring for Azure MySQL database |
| 63 | + # (Optional) Specify `storage_account_name` to save monitoring logs to storage. |
| 64 | + log_analytics_workspace_name = "loganalytics-we-sharedtest2" |
| 65 | +
|
| 66 | + # Firewall Rules to allow azure and external clients and specific Ip address/ranges. |
| 67 | + firewall_rules = { |
| 68 | + access-to-azure = { |
| 69 | + start_ip_address = "0.0.0.0" |
| 70 | + end_ip_address = "0.0.0.0" |
| 71 | + }, |
| 72 | + desktop-ip = { |
| 73 | + start_ip_address = "49.204.228.223" |
| 74 | + end_ip_address = "49.204.228.223" |
| 75 | + } |
| 76 | + } |
| 77 | +
|
| 78 | + # Tags for Azure Resources |
| 79 | + tags = { |
| 80 | + Terraform = "true" |
| 81 | + Environment = "dev" |
| 82 | + Owner = "test-user" |
| 83 | + } |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +## Terraform Usage |
| 88 | + |
| 89 | +To run this example you need to execute following Terraform commands |
| 90 | + |
| 91 | +```hcl |
| 92 | +terraform init |
| 93 | +
|
| 94 | +terraform plan |
| 95 | +
|
| 96 | +terraform apply |
| 97 | +``` |
| 98 | + |
| 99 | +Run `terraform destroy` when you don't need these resources. |
0 commit comments