1
- # Azure SQL Database Using Failover Groups with Private endpoints
1
+ # Simple Azure SQL single database creation
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 and vulnerability assessment . It also allows creating an SQL server database with a SQL script initialization.
4
4
5
5
## Module Usage
6
6
7
- ### Simple Azure SQL single database creation
8
-
9
- Following example is to create a simple database with basic firewall rules to make SQL database available to Azure resources, services and client IP ranges. This module also supports optional AD admin user for DB, Audit Polices, 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 create a resource group, proivde the name here
13
+ # 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
+ virtual_network_name = "vnet-shared-hub-westeurope-001"
19
+ private_subnet_address_prefix = ["10.1.5.0/29"]
20
+
21
+ # SQL Server and Database details
22
+ # The valid service objective name for the database include S0, S1, S2, S3, P1, P2, P4, P6, P11
23
+ sqlserver_name = "sqldbserver01"
24
+ database_name = "demomssqldb"
25
+ sql_database_edition = "Standard"
26
+ sqldb_service_objective_name = "S1"
27
+
28
+ # SQL Server and Database Audit policies
29
+ # By default database servers extended auditing policy enabled. you can turn of using enable_sql_server_extended_auditing_policy
30
+ # By default database extended auditing policy is turned off. you can manage the setting by adding `enable_database_extended_auditing_policy`
31
+ # To manage Azure Defender for Azure SQL database servers set `enable_threat_detection_policy` to true
32
+ enable_threat_detection_policy = true
33
+ log_retention_days = 30
34
+
35
+ # schedule scan notifications to the subscription administrators
36
+ # Manages the Vulnerability Assessment for a MS SQL Server set `enable_vulnerability_assessment` to `true`
37
+ enable_vulnerability_assessment = true
38
+ sql_admin_email_addresses = ["[email protected] ", "[email protected] "]
39
+
40
+ # AD administrator for an Azure SQL server
41
+ # Allows you to set a user or group as the AD administrator for an Azure SQL server
42
+ ad_admin_login_name = "[email protected] "
43
+
44
+ # (Optional) To enable Azure Monitoring for Azure SQL database including audit logs
45
+ # log analytic workspace name required
46
+ enable_log_monitoring = true
47
+ log_analytics_workspace_name = "loganalytics-we-sharedtest2"
48
+
49
+ # Firewall Rules to allow azure and external clients and specific Ip address/ranges.
50
+ enable_firewall_rules = true
41
51
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
- # Create and initialize a database with SQL script
50
- initialize_sql_script_execution = false
51
- sqldb_init_script_file = "./artifacts/db-init-sample.sql"
52
-
53
- # Tags for Azure Resources
52
+ {
53
+ name = "access-to-azure"
54
+ start_ip_address = "0.0.0.0"
55
+ end_ip_address = "0.0.0.0"
56
+ },
57
+ {
58
+ name = "desktop-ip"
59
+ start_ip_address = "49.204.225.134"
60
+ end_ip_address = "49.204.225.134"
61
+ }
62
+ ]
63
+
64
+ # Create and initialize a database with custom SQL script
65
+ # need sqlcmd utility to run this command
66
+ # your desktop public IP must be added firewall rules to run this command
67
+ initialize_sql_script_execution = true
68
+ sqldb_init_script_file = "../artifacts/db-init-sample.sql"
69
+
70
+ # Tags for Azure Resources
54
71
tags = {
55
72
Terraform = "true"
56
73
Environment = "dev"
@@ -63,10 +80,35 @@ module "mssql-server" {
63
80
64
81
To run this example you need to execute following Terraform commands
65
82
66
- ```
67
- $ terraform init
68
- $ terraform plan
69
- $ terraform apply
83
+ ``` bash
84
+ terraform init
85
+ terraform plan
86
+ terraform apply
70
87
```
71
88
72
89
Run ` terraform destroy ` when you don't need these resources.
90
+
91
+ ## Outputs
92
+
93
+ Name | Description
94
+ ---- | -----------
95
+ ` resource_group_name ` | The name of the resource group in which resources are created
96
+ ` resource_group_location ` | The location of the resource group in which resources are created
97
+ ` storage_account_id ` |The ID of the storage account
98
+ ` storage_account_name ` |The name of the storage account
99
+ ` primary_sql_server_id ` |The primary Microsoft SQL Server ID
100
+ ` primary_sql_server_fqdn ` |The fully qualified domain name of the primary Azure SQL Server
101
+ ` secondary_sql_server_id ` |The secondary Microsoft SQL Server ID
102
+ ` secondary_sql_server_fqdn ` |The fully qualified domain name of the secondary Azure SQL Server
103
+ ` sql_server_admin_user ` |SQL database administrator login id
104
+ ` sql_server_admin_password ` |SQL database administrator login password
105
+ ` sql_database_id ` |The SQL Database ID
106
+ ` sql_database_name ` |The SQL Database Name
107
+ ` sql_failover_group_id ` |A failover group of databases on a collection of Azure SQL servers
108
+ ` primary_sql_server_private_endpoint ` |id of the Primary SQL server Private Endpoint
109
+ ` secondary_sql_server_private_endpoint ` |id of the Primary SQL server Private Endpoint
110
+ ` sql_server_private_dns_zone_domain ` |DNS zone name of SQL server Private endpoints dns name records
111
+ ` primary_sql_server_private_endpoint_ip ` |Priamary SQL server private endpoint IPv4 Addresses
112
+ ` primary_sql_server_private_endpoint_fqdn ` |Priamary SQL server private endpoint IPv4 Addresses
113
+ ` secondary_sql_server_private_endpoint_ip ` |Secondary SQL server private endpoint IPv4 Addresses
114
+ ` secondary_sql_server_private_endpoint_fqdn ` |Secondary SQL server private endpoint IPv4 Addresses
0 commit comments