1
- # Azure SQL Database Using Failover Groups with Private endpoints
1
+ # Azure SQL database creation using geo-replication with auto-failover groups
2
2
3
- Terraform module for Azure to create a SQL server with initial database, Azure AD login, Firewall rules for SQL, Failover Group, Private endpoint, and corresponding private DNS zone for privatelink A records . It also allows creating an SQL server database with a SQL script initialization.
3
+ Terraform module to create a SQL server with initial database, Azure AD login, Firewall rules for SQL, optional azure monitoring, vulnerability assessment and Geo-replication with auto-failover groups . It also allows creating an SQL server database with a SQL script initialization.
4
4
5
5
## Module Usage
6
6
7
- ### Azure SQL database creation using geo-replication with auto-failover groups
8
-
9
- Following example to create a SQL database using geo-replication with auto-failover groups. This module also supports optional AD admin user for DB, Audit Policies, Firewall Rules, and creation of database schema using SQL script.
10
-
11
- ```
7
+ ``` hcl
12
8
module "mssql-server" {
13
- source = "kumarvna/mssql-db/azurerm"
14
- version = "1.0.0"
15
-
16
- # Resource Group, VNet and Subnet declarations
17
- create_resource_group = false
18
- resource_group_name = "rg-demo-westeurope-01"
19
- location = "westeurope"
20
- virtual_network_name = "vnet-demo-westeurope-001"
21
- private_subnet_address_prefix = "10.0.5.0/29"
22
-
23
- # SQL Server and Database scaling options
24
- sqlserver_name = "sqldbserver-db01"
25
- database_name = "demomssqldb"
26
- sql_database_edition = "Standard"
27
- sqldb_service_objective_name = "S1"
28
-
29
- # SQL Server and Database Audit policies
30
- enable_auditing_policy = true
31
- enable_threat_detection_policy = true
32
- log_retention_days = 30
33
- email_addresses_for_alerts = ["[email protected] "]
34
-
35
- # AD administrator for an Azure SQL server
36
- enable_sql_ad_admin = true
37
- ad_admin_login_name = "[email protected] "
38
-
39
- # Firewall Rules to allow azure and external clients
40
- enable_firewall_rules = true
9
+ source = "kumarvna/mssql-db/azurerm"
10
+ version = "1.1.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
+ resource_group_name = "rg-shared-westeurope-01"
16
+ location = "westeurope"
17
+ virtual_network_name = "vnet-shared-hub-westeurope-001"
18
+
19
+ # SQL Server and Database details
20
+ # The valid service objective name for the database include S0, S1, S2, S3, P1, P2, P4, P6, P11
21
+ sqlserver_name = "sqldbserver01"
22
+ database_name = "demomssqldb"
23
+ sql_database_edition = "Standard"
24
+ sqldb_service_objective_name = "S1"
25
+
26
+ # SQL server extended auditing policy defaults to `true`.
27
+ # To turn off set enable_sql_server_extended_auditing_policy to `false`
28
+ # DB extended auditing policy defaults to `false`.
29
+ # to tun on set the variable `enable_database_extended_auditing_policy` to `true`
30
+ # To enable Azure Defender for database set `enable_threat_detection_policy` to true
31
+ enable_threat_detection_policy = true
32
+ log_retention_days = 30
33
+
34
+ # schedule scan notifications to the subscription administrators
35
+ # Manage Vulnerability Assessment set `enable_vulnerability_assessment` to `true`
36
+ enable_vulnerability_assessment = false
37
+ email_addresses_for_alerts = ["[email protected] ", "[email protected] "]
38
+
39
+ # AD administrator for an Azure SQL server
40
+ # Allows you to set a user or group as the AD administrator for an Azure SQL server
41
+ ad_admin_login_name = "[email protected] "
42
+
43
+ # (Optional) To enable Azure Monitoring for Azure SQL database including audit logs
44
+ # log analytic workspace name required
45
+ enable_log_monitoring = true
46
+ log_analytics_workspace_name = "loganalytics-we-sharedtest2"
47
+
48
+ # Sql failover group creation. required secondary locaiton input.
49
+ enable_failover_group = true
50
+ secondary_sql_server_location = "northeurope"
51
+
52
+ # Firewall Rules to allow azure and external clients and specific Ip address/ranges.
53
+ enable_firewall_rules = true
41
54
firewall_rules = [
42
- {name = "access-to-azure"
43
- start_ip_address = "0.0.0.0"
44
- end_ip_address = "0.0.0.0"},
45
- {name = "desktop-ip"
46
- start_ip_address = "123.201.75.71"
47
- end_ip_address = "123.201.75.71"}]
48
-
49
- # Sql failover group
50
- enable_failover_group = true
51
- secondary_sql_server_location = "northeurope"
52
-
53
- # Create and initialize a database with SQL script
54
- initialize_sql_script_execution = false
55
- sqldb_init_script_file = "./artifacts/db-init-sample.sql"
56
-
57
- # Tags for Azure Resources
55
+ {
56
+ name = "access-to-azure"
57
+ start_ip_address = "0.0.0.0"
58
+ end_ip_address = "0.0.0.0"
59
+ },
60
+ {
61
+ name = "desktop-ip"
62
+ start_ip_address = "49.204.225.134"
63
+ end_ip_address = "49.204.225.134"
64
+ }
65
+ ]
66
+
67
+ # Create and initialize a database with custom SQL script
68
+ # need sqlcmd utility to run this command
69
+ # your desktop public IP must be added firewall rules to run this command
70
+ initialize_sql_script_execution = true
71
+ sqldb_init_script_file = "../artifacts/db-init-sample.sql"
72
+
73
+ # Tags for Azure Resources
58
74
tags = {
59
75
Terraform = "true"
60
76
Environment = "dev"
@@ -67,10 +83,10 @@ module "mssql-server" {
67
83
68
84
To run this example you need to execute following Terraform commands
69
85
70
- ```
71
- $ terraform init
72
- $ terraform plan
73
- $ terraform apply
86
+ ``` bash
87
+ terraform init
88
+ terraform plan
89
+ terraform apply
74
90
```
75
91
76
92
Run ` terraform destroy ` when you don't need these resources.
0 commit comments