Skip to content

Commit 42a9951

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

File tree

6 files changed

+234
-20
lines changed

6 files changed

+234
-20
lines changed

README.md

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,74 @@
1-
# terraform-azurerm-mysql-db
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 not create a resource group
13+
# proivde a name to use an existing resource group, specify the existing resource group name,
14+
# and set the argument to `create_resource_group = false`. Location will be same as existing RG.
15+
create_resource_group = false
16+
resource_group_name = "rg-shared-westeurope-01"
17+
location = "westeurope"
18+
19+
# MySQL Server and Database settings
20+
mysqlserver_name = "roshmysqldbsrv01"
21+
22+
mysqlserver_settings = {
23+
sku_name = "B_Gen5_2"
24+
storage_mb = 5120
25+
version = "5.7"
26+
# Database name, charset and collection arguments
27+
database_name = "roshydemomysqldb"
28+
charset = "utf8"
29+
collation = "utf8_unicode_ci"
30+
# Storage Profile and other optional arguments
31+
auto_grow_enabled = true
32+
backup_retention_days = 7
33+
geo_redundant_backup_enabled = false
34+
infrastructure_encryption_enabled = false
35+
public_network_access_enabled = true
36+
ssl_enforcement_enabled = true
37+
ssl_minimal_tls_version_enforced = "TLS1_2"
38+
}
39+
40+
# MySQL Server Parameters
41+
# For more information: https://docs.microsoft.com/en-us/azure/mysql/concepts-server-parameters
42+
mysql_configuration = {
43+
interactive_timeout = "600"
44+
}
45+
46+
# AD administrator for an Azure SQL server
47+
# Allows you to set a user or group as the AD administrator for an Azure SQL server
48+
ad_admin_login_name = "firstname.lastname@example.com"
49+
50+
# (Optional) To enable Azure Monitoring for Azure MySQL database
51+
# (Optional) Specify `storage_account_name` to save monitoring logs to storage.
52+
log_analytics_workspace_name = "loganalytics-we-sharedtest2"
53+
54+
# Firewall Rules to allow azure and external clients and specific Ip address/ranges.
55+
56+
firewall_rules = {
57+
access-to-azure = {
58+
start_ip_address = "0.0.0.0"
59+
end_ip_address = "0.0.0.0"
60+
},
61+
desktop-ip = {
62+
start_ip_address = "49.204.228.223"
63+
end_ip_address = "49.204.228.223"
64+
}
65+
}
66+
67+
# Tags for Azure Resources
68+
tags = {
69+
Terraform = "true"
70+
Environment = "dev"
71+
Owner = "test-user"
72+
}
73+
}
74+
```

example/complete/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 not create a resource group
13+
# proivde a name to use an existing resource group, specify the existing resource group name,
14+
# and set the argument to `create_resource_group = false`. Location will be same as existing RG.
15+
create_resource_group = false
16+
resource_group_name = "rg-shared-westeurope-01"
17+
location = "westeurope"
18+
19+
# MySQL Server and Database settings
20+
mysqlserver_name = "roshmysqldbsrv01"
21+
22+
mysqlserver_settings = {
23+
sku_name = "B_Gen5_2"
24+
storage_mb = 5120
25+
version = "5.7"
26+
# Database name, charset and collection arguments
27+
database_name = "roshydemomysqldb"
28+
charset = "utf8"
29+
collation = "utf8_unicode_ci"
30+
# Storage Profile and other optional arguments
31+
auto_grow_enabled = true
32+
backup_retention_days = 7
33+
geo_redundant_backup_enabled = false
34+
infrastructure_encryption_enabled = false
35+
public_network_access_enabled = true
36+
ssl_enforcement_enabled = true
37+
ssl_minimal_tls_version_enforced = "TLS1_2"
38+
}
39+
40+
# MySQL Server Parameters
41+
# For more information: https://docs.microsoft.com/en-us/azure/mysql/concepts-server-parameters
42+
mysql_configuration = {
43+
interactive_timeout = "600"
44+
}
45+
46+
# AD administrator for an Azure SQL server
47+
# Allows you to set a user or group as the AD administrator for an Azure SQL server
48+
ad_admin_login_name = "firstname.lastname@example.com"
49+
50+
# (Optional) To enable Azure Monitoring for Azure MySQL database
51+
# (Optional) Specify `storage_account_name` to save monitoring logs to storage.
52+
log_analytics_workspace_name = "loganalytics-we-sharedtest2"
53+
54+
# Firewall Rules to allow azure and external clients and specific Ip address/ranges.
55+
56+
firewall_rules = {
57+
access-to-azure = {
58+
start_ip_address = "0.0.0.0"
59+
end_ip_address = "0.0.0.0"
60+
},
61+
desktop-ip = {
62+
start_ip_address = "49.204.228.223"
63+
end_ip_address = "49.204.228.223"
64+
}
65+
}
66+
67+
# Tags for Azure Resources
68+
tags = {
69+
Terraform = "true"
70+
Environment = "dev"
71+
Owner = "test-user"
72+
}
73+
}
74+
```
75+
76+
## Terraform Usage
77+
78+
To run this example you need to execute following Terraform commands
79+
80+
```hcl
81+
terraform init
82+
83+
terraform plan
84+
85+
terraform apply
86+
```
87+
88+
Run `terraform destroy` when you don't need these resources.

example/complete/main.tf

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module "mssql-server" {
2-
// source = "kumarvna/mysql-db/azurerm"
3-
// version = "1.0.0"
4-
//source = "../../"
5-
source = "github.com/kumarvna/terraform-azurerm-mysql-db?ref=develop"
2+
source = "kumarvna/mysql-db/azurerm"
3+
version = "1.0.0"
64

75
# By default, this module will not create a resource group
86
# proivde a name to use an existing resource group, specify the existing resource group name,
@@ -12,8 +10,8 @@ module "mssql-server" {
1210
location = "westeurope"
1311

1412
# MySQL Server and Database settings
15-
#
1613
mysqlserver_name = "roshmysqldbsrv01"
14+
1715
mysqlserver_settings = {
1816
sku_name = "B_Gen5_2"
1917
storage_mb = 5120
@@ -32,28 +30,20 @@ module "mssql-server" {
3230
ssl_minimal_tls_version_enforced = "TLS1_2"
3331
}
3432

33+
# MySQL Server Parameters
34+
# For more information: https://docs.microsoft.com/en-us/azure/mysql/concepts-server-parameters
3535
mysql_configuration = {
3636
interactive_timeout = "600"
3737
}
38-
# SQL server extended auditing policy defaults to `true`.
39-
# To turn off set enable_sql_server_extended_auditing_policy to `false`
40-
# DB extended auditing policy defaults to `false`.
41-
# to tun on set the variable `enable_database_extended_auditing_policy` to `true`
42-
# To enable Azure Defender for database set `enable_threat_detection_policy` to true
43-
enable_threat_detection_policy = false
44-
#log_retention_days = 30
45-
#email_addresses_for_alerts = ["user@example.com", "firstname.lastname@example.com"]
4638

4739
# AD administrator for an Azure SQL server
4840
# Allows you to set a user or group as the AD administrator for an Azure SQL server
4941
ad_admin_login_name = "firstname.lastname@example.com"
5042

51-
/*
52-
# (Optional) To enable Azure Monitoring for Azure SQL database including audit logs
53-
# log analytic workspace name required
54-
enable_log_monitoring = true
43+
# (Optional) To enable Azure Monitoring for Azure MySQL database
44+
# (Optional) Specify `storage_account_name` to save monitoring logs to storage.
5545
log_analytics_workspace_name = "loganalytics-we-sharedtest2"
56-
*/
46+
5747
# Firewall Rules to allow azure and external clients and specific Ip address/ranges.
5848

5949
firewall_rules = {

main.tf

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ locals {
1010
charset = "utf8"
1111
collation = "utf8_unicode_ci"
1212
})
13-
1413
}
1514

1615
#---------------------------------------------------------
@@ -172,3 +171,37 @@ resource "azurerm_mysql_server_key" "example" {
172171
server_id = azurerm_mysql_server.main.id
173172
key_vault_key_id = var.key_vault_key_id
174173
}
174+
175+
#------------------------------------------------------------------
176+
# azurerm monitoring diagnostics - Default is "false"
177+
#------------------------------------------------------------------
178+
resource "azurerm_monitor_diagnostic_setting" "extaudit" {
179+
count = var.log_analytics_workspace_name != null ? 1 : 0
180+
name = lower("extaudit-${var.mysqlserver_name}-diag")
181+
target_resource_id = azurerm_mysql_server.main.id
182+
log_analytics_workspace_id = data.azurerm_log_analytics_workspace.logws.0.id
183+
storage_account_id = var.enable_threat_detection_policy ? azurerm_storage_account.storeacc.0.id : null
184+
185+
dynamic "log" {
186+
for_each = var.extaudit_diag_logs
187+
content {
188+
category = log.value
189+
enabled = true
190+
retention_policy {
191+
enabled = false
192+
}
193+
}
194+
}
195+
196+
metric {
197+
category = "AllMetrics"
198+
199+
retention_policy {
200+
enabled = false
201+
}
202+
}
203+
204+
lifecycle {
205+
ignore_changes = [log, metric]
206+
}
207+
}

output.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
output "resource_group_name" {
2+
description = "The name of the resource group in which resources are created"
3+
value = local.resource_group_name
4+
}
5+
6+
output "resource_group_location" {
7+
description = "The location of the resource group in which resources are created"
8+
value = local.location
9+
}
10+
11+
output "storage_account_id" {
12+
description = "The ID of the storage account"
13+
value = element(concat(azurerm_storage_account.storeacc.*.id, [""]), 0)
14+
}
15+
16+
output "storage_account_name" {
17+
description = "The name of the storage account"
18+
value = element(concat(azurerm_storage_account.storeacc.*.name, [""]), 0)
19+
}
20+

variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ variable "ad_admin_login_name" {
108108
default = null
109109
}
110110

111+
variable "key_vault_key_id" {
112+
description = "The URL to a Key Vault Key"
113+
default = null
114+
}
115+
116+
variable "extaudit_diag_logs" {
117+
description = "Database Monitoring Category details for Azure Diagnostic setting"
118+
default = ["MySqlSlowLogs", "MySqlAuditLogs"]
119+
}
120+
111121
variable "tags" {
112122
description = "A map of tags to add to all resources"
113123
type = map(string)

0 commit comments

Comments
 (0)