Skip to content

Commit ed7ab9a

Browse files
committed
final configuration for version 1.0
1 parent 42a9951 commit ed7ab9a

File tree

6 files changed

+133
-7
lines changed

6 files changed

+133
-7
lines changed

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
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).
44

5+
## Resources are supported
6+
7+
* [MySQL Servers](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_server)
8+
* [MySQL Database](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_database)
9+
* [MySQL Configuration](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_configuration)
10+
* [MySQL Firewall Rules](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_firewall_rule)
11+
* [MySQL Active Directory Administrator](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_active_directory_administrator)
12+
* [MySQL Customer Managed Key](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_server_key)
13+
* [MySQL Virtual Network Rule](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_virtual_network_rule)
14+
* [MySQL Diagnostics](https://docs.microsoft.com/en-us/azure/azure-sql/database/metrics-diagnostic-telemetry-logging-streaming-export-configure?tabs=azure-portal)
15+
516
## Module Usage
617

718
```hcl
@@ -72,3 +83,64 @@ module "mssql-server" {
7283
}
7384
}
7485
```
86+
87+
## Requirements
88+
89+
| Name | Version |
90+
| --------- | --------- |
91+
| terraform | >= 0.13 |
92+
| azurerm | >= 2.59.0 |
93+
94+
## Providers
95+
96+
| Name | Version |
97+
| ------- | --------- |
98+
| azurerm | >= 2.59.0 |
99+
100+
## Inputs
101+
102+
| Name | Description | Type | Default |
103+
|--|--|--|--|
104+
`create_resource_group` | Whether to create resource group and use it for all networking resources | string | `"false"`
105+
`resource_group_name` | The name of the resource group in which resources are created | string | `""`
106+
`location` | The location of the resource group in which resources are created | string | `""`
107+
`log_analytics_workspace_name`|The name of log analytics workspace name|string|`null`
108+
`random_password_length`|The desired length of random password created by this module|string|`24`
109+
`subnet_id`|The resource ID of the subnet|string|`null`
110+
`mysqlserver_name`|MySQL server Name|string|`""`
111+
`admin_username`|The username of the local administrator used for the SQL Server|string|`"sqladmin"`
112+
`admin_password`|The Password which should be used for the local-administrator on this SQL Server|string|`null`
113+
`identity`|If you want your SQL Server to have an managed identity. Defaults to false|string|`false`
114+
`mysqlserver_settings`|MySQL server settings|object({})|`{}`
115+
`storage_account_name`|The name of the storage account name|string|`null`
116+
`enable_threat_detection_policy`|Threat detection policy configuration, known in the API as Server Security Alerts Policy|string|`false`
117+
`email_addresses_for_alerts`|Account administrators email for alerts|`list(any)`|`""`
118+
`disabled_alerts`|Specifies an array of alerts that are disabled. Allowed values are: `Sql_Injection`, `Sql_Injection_Vulnerability`, `Access_Anomaly`, `Data_Exfiltration`, `Unsafe_Action`|list(any)|`[]`
119+
`log_retention_days`|Specifies the number of days to keep in the Threat Detection audit logs|number|`30`
120+
`mysql_configuration`|Sets a MySQL Configuration value on a MySQL Server|map(string)|`{}`
121+
firewall_rules|Range of IP addresses to allow firewall connections|map(object({}))|`null`
122+
`ad_admin_login_name`|The login name of the principal to set as the server administrator|string|`null`
123+
`key_vault_key_id`|The URL to a Key Vault custom managed key|string|`null`
124+
`extaudit_diag_logs`|Database Monitoring Category details for Azure Diagnostic setting|list(string)|`["MySqlSlowLogs", "MySqlAuditLogs"]`
125+
`Tags` | A map of tags to add to all resources | map | `{}`
126+
127+
## Outputs
128+
129+
| Name | Description |
130+
|--|--|
131+
`mysql_server_id`|The resource ID of the MySQL Server
132+
`mysql_server_fqdn`|The FQDN of the MySQL Server
133+
`mysql_database_id`|The resource ID of the MySQL Database
134+
135+
## Resource Graph
136+
137+
![Resource Graph](graph.png)
138+
139+
## Authors
140+
141+
Originally created by [Kumaraswamy Vithanala](mailto:kumarvna@gmail.com)
142+
143+
## Other resources
144+
145+
* [Azure database for MySQL](https://docs.microsoft.com/en-us/azure/mysql/)
146+
* [Terraform AzureRM Provider Documentation](https://www.terraform.io/docs/providers/azurerm/index.html)

example/complete/main.tf

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module "mssql-server" {
2-
source = "kumarvna/mysql-db/azurerm"
3-
version = "1.0.0"
4-
2+
// source = "kumarvna/mysql-db/azurerm"
3+
// version = "1.0.0"
4+
source = "../../"
55
# By default, this module will not create a resource group
66
# proivde a name to use an existing resource group, specify the existing resource group name,
77
# and set the argument to `create_resource_group = false`. Location will be same as existing RG.
@@ -11,9 +11,9 @@ module "mssql-server" {
1111

1212
# MySQL Server and Database settings
1313
mysqlserver_name = "roshmysqldbsrv01"
14-
14+
1515
mysqlserver_settings = {
16-
sku_name = "B_Gen5_2"
16+
sku_name = "GP_Gen5_16"
1717
storage_mb = 5120
1818
version = "5.7"
1919
# Database name, charset and collection arguments
@@ -36,10 +36,23 @@ module "mssql-server" {
3636
interactive_timeout = "600"
3737
}
3838

39+
# Use Virtual Network service endpoints and rules for Azure Database for MySQL
40+
subnet_id = var.subnet_id
41+
42+
# The URL to a Key Vault custom managed key
43+
key_vault_key_id = var.key_vault_key_id
44+
45+
# To enable Azure Defender for database set `enable_threat_detection_policy` to true
46+
enable_threat_detection_policy = true
47+
log_retention_days = 30
48+
email_addresses_for_alerts = ["user@example.com", "firstname.lastname@example.com"]
49+
3950
# AD administrator for an Azure SQL server
4051
# Allows you to set a user or group as the AD administrator for an Azure SQL server
4152
ad_admin_login_name = "firstname.lastname@example.com"
4253

54+
55+
4356
# (Optional) To enable Azure Monitoring for Azure MySQL database
4457
# (Optional) Specify `storage_account_name` to save monitoring logs to storage.
4558
log_analytics_workspace_name = "loganalytics-we-sharedtest2"

example/complete/variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
variable "key_vault_key_id" {
2+
description = "The URL to a Key Vault Key"
3+
default = null
4+
}
5+
6+
variable "subnet_id" {
7+
description = "The resource ID of the subnet"
8+
default = null
9+
}

main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@ resource "azurerm_mysql_server_key" "example" {
172172
key_vault_key_id = var.key_vault_key_id
173173
}
174174

175+
#--------------------------------------------------------------------------------
176+
# Allowing traffic between an Azure SQL server and a subnet - Default is "false"
177+
#--------------------------------------------------------------------------------
178+
resource "azurerm_mysql_virtual_network_rule" "main" {
179+
count = var.subnet_id != null ? 1 : 0
180+
name = format("%s-vnet-rule", var.mysqlserver_name)
181+
resource_group_name = local.resource_group_name
182+
server_name = azurerm_mysql_server.main.name
183+
subnet_id = var.subnet_id
184+
}
185+
175186
#------------------------------------------------------------------
176187
# azurerm monitoring diagnostics - Default is "false"
177188
#------------------------------------------------------------------

output.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,18 @@ output "storage_account_name" {
1818
value = element(concat(azurerm_storage_account.storeacc.*.name, [""]), 0)
1919
}
2020

21+
output "mysql_server_id" {
22+
description = "The resource ID of the MySQL Server"
23+
value = azurerm_mysql_server.main.id
24+
}
25+
26+
output "mysql_server_fqdn" {
27+
description = "The FQDN of the MySQL Server"
28+
value = azurerm_mysql_server.main.fqdn
29+
}
30+
31+
output "mysql_database_id" {
32+
description = "The resource ID of the MySQL Database"
33+
value = azurerm_mysql_database.main.id
34+
}
35+

variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ variable "location" {
1313
default = ""
1414
}
1515

16+
variable "subnet_id" {
17+
description = "The resource ID of the subnet"
18+
default = ""
19+
}
20+
1621
variable "log_analytics_workspace_name" {
1722
description = "The name of log analytics workspace name"
1823
default = null
@@ -24,7 +29,7 @@ variable "random_password_length" {
2429
}
2530

2631
variable "mysqlserver_name" {
27-
description = "SQL server Name"
32+
description = "MySQL server Name"
2833
default = ""
2934
}
3035

@@ -44,6 +49,7 @@ variable "identity" {
4449
}
4550

4651
variable "mysqlserver_settings" {
52+
description = "MySQL server settings"
4753
type = object({
4854
sku_name = string
4955
version = string
@@ -67,7 +73,7 @@ variable "storage_account_name" {
6773
}
6874

6975
variable "enable_threat_detection_policy" {
70-
description = ""
76+
description = "Threat detection policy configuration, known in the API as Server Security Alerts Policy"
7177
default = false
7278
}
7379

0 commit comments

Comments
 (0)