|
1 |
| -# Azure SQL database creation using geo-replication with auto-failover groups and Private Endpoints |
2 |
| - |
3 |
| -Terraform module to create a SQL server with initial database, Azure AD login, Firewall rules for SQL, optional azure monitoring, vulnerability assessment, Geo-replication with auto-failover groups and private endpoints. It also allows creating an SQL server database with a SQL script initialization. |
4 |
| - |
5 |
| -## Module Usage |
6 |
| - |
7 |
| -```hcl |
8 |
| -# Azurerm provider configuration |
9 |
| -provider "azurerm" { |
10 |
| - features {} |
11 |
| -} |
12 |
| -
|
13 |
| -module "mssql-server" { |
14 |
| - source = "kumarvna/mssql-db/azurerm" |
15 |
| - version = "1.2.0" |
16 |
| -
|
17 |
| - # By default, this module will create a resource group |
18 |
| - # proivde a name to use an existing resource group and set the argument |
19 |
| - # to `create_resource_group = false` if you want to existing resoruce group. |
20 |
| - # If you use existing resrouce group location will be the same as existing RG. |
21 |
| - create_resource_group = false |
22 |
| - resource_group_name = "rg-shared-westeurope-01" |
23 |
| - location = "westeurope" |
24 |
| - virtual_network_name = "vnet-shared-hub-westeurope-001" |
25 |
| - private_subnet_address_prefix = ["10.1.5.0/29"] |
26 |
| -
|
27 |
| - # SQL Server and Database details |
28 |
| - # The valid service objective name for the database include S0, S1, S2, S3, P1, P2, P4, P6, P11 |
29 |
| - sqlserver_name = "sqldbserver01" |
30 |
| - database_name = "demomssqldb" |
31 |
| - sql_database_edition = "Standard" |
32 |
| - sqldb_service_objective_name = "S1" |
33 |
| -
|
34 |
| - # SQL server extended auditing policy defaults to `true`. |
35 |
| - # To turn off set enable_sql_server_extended_auditing_policy to `false` |
36 |
| - # DB extended auditing policy defaults to `false`. |
37 |
| - # to tun on set the variable `enable_database_extended_auditing_policy` to `true` |
38 |
| - # To enable Azure Defender for database set `enable_threat_detection_policy` to true |
39 |
| - enable_threat_detection_policy = true |
40 |
| - log_retention_days = 30 |
41 |
| -
|
42 |
| - # schedule scan notifications to the subscription administrators |
43 |
| - # Manage Vulnerability Assessment set `enable_vulnerability_assessment` to `true` |
44 |
| - enable_vulnerability_assessment = false |
45 |
| - email_addresses_for_alerts = ["[email protected]", "[email protected]"] |
46 |
| -
|
47 |
| - # Sql failover group creation. required secondary locaiton input. |
48 |
| - enable_failover_group = true |
49 |
| - secondary_sql_server_location = "northeurope" |
50 |
| -
|
51 |
| - # enabling the Private Endpoints for Sql servers |
52 |
| - enable_private_endpoint = true |
53 |
| -
|
54 |
| - # AD administrator for an Azure SQL server |
55 |
| - # Allows you to set a user or group as the AD administrator for an Azure SQL server |
56 |
| - ad_admin_login_name = "[email protected]" |
57 |
| -
|
58 |
| - # (Optional) To enable Azure Monitoring for Azure SQL database including audit logs |
59 |
| - # log analytic workspace name required |
60 |
| - enable_log_monitoring = true |
61 |
| - log_analytics_workspace_name = "loganalytics-we-sharedtest2" |
62 |
| -
|
63 |
| - # Firewall Rules to allow azure and external clients and specific Ip address/ranges. |
64 |
| - enable_firewall_rules = true |
65 |
| - firewall_rules = [ |
66 |
| - { |
67 |
| - name = "access-to-azure" |
68 |
| - start_ip_address = "0.0.0.0" |
69 |
| - end_ip_address = "0.0.0.0" |
70 |
| - }, |
71 |
| - { |
72 |
| - name = "desktop-ip" |
73 |
| - start_ip_address = "49.204.225.134" |
74 |
| - end_ip_address = "49.204.225.134" |
75 |
| - } |
76 |
| - ] |
77 |
| -
|
78 |
| - # Create and initialize a database with custom SQL script |
79 |
| - # need sqlcmd utility to run this command |
80 |
| - # your desktop public IP must be added to firewall rules to run this command |
81 |
| - initialize_sql_script_execution = true |
82 |
| - sqldb_init_script_file = "../artifacts/db-init-sample.sql" |
83 |
| -
|
84 |
| - # Tags for Azure Resources |
85 |
| - tags = { |
86 |
| - Terraform = "true" |
87 |
| - Environment = "dev" |
88 |
| - Owner = "test-user" |
89 |
| - } |
90 |
| -} |
91 |
| -``` |
92 |
| - |
93 |
| -## Terraform Usage |
94 |
| - |
95 |
| -To run this example you need to execute following Terraform commands |
96 |
| - |
97 |
| -```bash |
98 |
| -terraform init |
99 |
| -terraform plan |
100 |
| -terraform apply |
101 |
| -``` |
102 |
| - |
103 |
| -Run `terraform destroy` when you don't need these resources. |
| 1 | +# Azure SQL database creation with geo-replication, auto-failover groups and Private Endpoints |
| 2 | + |
| 3 | +Terraform module to create a SQL server with initial database, Azure AD login, Firewall rules for SQL, optional azure monitoring, vulnerability assessment, Geo-replication with auto-failover groups and private endpoints. It also allows creating an SQL server database with a SQL script initialization. |
| 4 | + |
| 5 | +## Module Usage |
| 6 | + |
| 7 | +```terraform |
| 8 | +# Azurerm provider configuration |
| 9 | +provider "azurerm" { |
| 10 | + features {} |
| 11 | +} |
| 12 | +
|
| 13 | +module "mssql-server" { |
| 14 | + source = "kumarvna/mssql-db/azurerm" |
| 15 | + version = "1.3.0" |
| 16 | +
|
| 17 | + # By default, this module will create a resource group |
| 18 | + # proivde a name to use an existing resource group and set the argument |
| 19 | + # to `create_resource_group = false` if you want to existing resoruce group. |
| 20 | + # If you use existing resrouce group location will be the same as existing RG. |
| 21 | + create_resource_group = false |
| 22 | + resource_group_name = "rg-shared-westeurope-01" |
| 23 | + location = "westeurope" |
| 24 | +
|
| 25 | + # SQL Server and Database details |
| 26 | + # The valid service objective name for the database include S0, S1, S2, S3, P1, P2, P4, P6, P11 |
| 27 | + sqlserver_name = "te-sqldbserver01" |
| 28 | + database_name = "demomssqldb" |
| 29 | + sql_database_edition = "Standard" |
| 30 | + sqldb_service_objective_name = "S1" |
| 31 | +
|
| 32 | + # SQL server extended auditing policy defaults to `true`. |
| 33 | + # To turn off set enable_sql_server_extended_auditing_policy to `false` |
| 34 | + # DB extended auditing policy defaults to `false`. |
| 35 | + # to tun on set the variable `enable_database_extended_auditing_policy` to `true` |
| 36 | + # To enable Azure Defender for database set `enable_threat_detection_policy` to true |
| 37 | + enable_threat_detection_policy = true |
| 38 | + log_retention_days = 30 |
| 39 | +
|
| 40 | + # schedule scan notifications to the subscription administrators |
| 41 | + # Manage Vulnerability Assessment set `enable_vulnerability_assessment` to `true` |
| 42 | + enable_vulnerability_assessment = false |
| 43 | + email_addresses_for_alerts = ["[email protected]", "[email protected]"] |
| 44 | +
|
| 45 | + # Sql failover group creation. required secondary locaiton input. |
| 46 | + enable_failover_group = true |
| 47 | + secondary_sql_server_location = "northeurope" |
| 48 | +
|
| 49 | + # enabling the Private Endpoints for Sql servers |
| 50 | + enable_private_endpoint = true |
| 51 | + virtual_network_name = "vnet-shared-hub-westeurope-001" |
| 52 | + private_subnet_address_prefix = ["10.1.5.0/29"] |
| 53 | + # existing_private_dns_zone = "demo.example.com" |
| 54 | +
|
| 55 | + # AD administrator for an Azure SQL server |
| 56 | + # Allows you to set a user or group as the AD administrator for an Azure SQL server |
| 57 | + ad_admin_login_name = "[email protected]" |
| 58 | +
|
| 59 | + # (Optional) To enable Azure Monitoring for Azure SQL database including audit logs |
| 60 | + # log analytic workspace name required |
| 61 | + enable_log_monitoring = true |
| 62 | + log_analytics_workspace_name = "loganalytics-we-sharedtest2" |
| 63 | +
|
| 64 | + # Firewall Rules to allow azure and external clients and specific Ip address/ranges. |
| 65 | + enable_firewall_rules = true |
| 66 | + firewall_rules = [ |
| 67 | + { |
| 68 | + name = "access-to-azure" |
| 69 | + start_ip_address = "0.0.0.0" |
| 70 | + end_ip_address = "0.0.0.0" |
| 71 | + }, |
| 72 | + { |
| 73 | + name = "desktop-ip" |
| 74 | + start_ip_address = "123.201.36.94" |
| 75 | + end_ip_address = "123.201.36.94" |
| 76 | + } |
| 77 | + ] |
| 78 | +
|
| 79 | + # Adding additional TAG's to your Azure resources |
| 80 | + tags = { |
| 81 | + ProjectName = "demo-project" |
| 82 | + Env = "dev" |
| 83 | + |
| 84 | + BusinessUnit = "CORP" |
| 85 | + ServiceClass = "Gold" |
| 86 | + } |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +## Terraform Usage |
| 91 | + |
| 92 | +To run this example you need to execute following Terraform commands |
| 93 | + |
| 94 | +```bash |
| 95 | +terraform init |
| 96 | +terraform plan |
| 97 | +terraform apply |
| 98 | +``` |
| 99 | + |
| 100 | +Run `terraform destroy` when you don't need these resources. |
0 commit comments