|
1 | | -# Azure SQL database creation using geo-replication with auto-failover groups |
2 | | - |
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 | | - |
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 | | -
|
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 = "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 | | - # AD administrator for an Azure SQL server |
46 | | - # Allows you to set a user or group as the AD administrator for an Azure SQL server |
47 | | - ad_admin_login_name = "[email protected]" |
48 | | -
|
49 | | - # (Optional) To enable Azure Monitoring for Azure SQL database including audit logs |
50 | | - # log analytic workspace name required |
51 | | - enable_log_monitoring = true |
52 | | - log_analytics_workspace_name = "loganalytics-we-sharedtest2" |
53 | | -
|
54 | | - # Sql failover group creation. required secondary locaiton input. |
55 | | - enable_failover_group = true |
56 | | - secondary_sql_server_location = "northeurope" |
57 | | -
|
58 | | - # Firewall Rules to allow azure and external clients and specific Ip address/ranges. |
59 | | - enable_firewall_rules = true |
60 | | - firewall_rules = [ |
61 | | - { |
62 | | - name = "access-to-azure" |
63 | | - start_ip_address = "0.0.0.0" |
64 | | - end_ip_address = "0.0.0.0" |
65 | | - }, |
66 | | - { |
67 | | - name = "desktop-ip" |
68 | | - start_ip_address = "49.204.225.134" |
69 | | - end_ip_address = "49.204.225.134" |
70 | | - } |
71 | | - ] |
72 | | -
|
73 | | - # Create and initialize a database with custom SQL script |
74 | | - # need sqlcmd utility to run this command |
75 | | - # your desktop public IP must be added firewall rules to run this command |
76 | | - initialize_sql_script_execution = true |
77 | | - sqldb_init_script_file = "../artifacts/db-init-sample.sql" |
78 | | -
|
79 | | - # Tags for Azure Resources |
80 | | - tags = { |
81 | | - Terraform = "true" |
82 | | - Environment = "dev" |
83 | | - Owner = "test-user" |
84 | | - } |
85 | | -} |
86 | | -``` |
87 | | - |
88 | | -## Terraform Usage |
89 | | - |
90 | | -To run this example you need to execute following Terraform commands |
91 | | - |
92 | | -```bash |
93 | | -terraform init |
94 | | -terraform plan |
95 | | -terraform apply |
96 | | -``` |
97 | | - |
98 | | -Run `terraform destroy` when you don't need these resources. |
| 1 | +# Azure SQL database creation using geo-replication with auto-failover groups |
| 2 | + |
| 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 | + |
| 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 = "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 | + # AD administrator for an Azure SQL server |
| 46 | + # Allows you to set a user or group as the AD administrator for an Azure SQL server |
| 47 | + ad_admin_login_name = "[email protected]" |
| 48 | +
|
| 49 | + # (Optional) To enable Azure Monitoring for Azure SQL database including audit logs |
| 50 | + # log analytic workspace name required |
| 51 | + enable_log_monitoring = true |
| 52 | + log_analytics_workspace_name = "loganalytics-we-sharedtest2" |
| 53 | +
|
| 54 | + # Sql failover group creation. required secondary locaiton input. |
| 55 | + enable_failover_group = true |
| 56 | + secondary_sql_server_location = "northeurope" |
| 57 | +
|
| 58 | + # Firewall Rules to allow azure and external clients and specific Ip address/ranges. |
| 59 | + enable_firewall_rules = true |
| 60 | + firewall_rules = [ |
| 61 | + { |
| 62 | + name = "access-to-azure" |
| 63 | + start_ip_address = "0.0.0.0" |
| 64 | + end_ip_address = "0.0.0.0" |
| 65 | + }, |
| 66 | + { |
| 67 | + name = "desktop-ip" |
| 68 | + start_ip_address = "49.204.225.134" |
| 69 | + end_ip_address = "49.204.225.134" |
| 70 | + } |
| 71 | + ] |
| 72 | +
|
| 73 | + # Adding additional TAG's to your Azure resources |
| 74 | + tags = { |
| 75 | + ProjectName = "demo-project" |
| 76 | + Env = "dev" |
| 77 | + |
| 78 | + BusinessUnit = "CORP" |
| 79 | + ServiceClass = "Gold" |
| 80 | + } |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +## Terraform Usage |
| 85 | + |
| 86 | +To run this example you need to execute following Terraform commands |
| 87 | + |
| 88 | +```bash |
| 89 | +terraform init |
| 90 | +terraform plan |
| 91 | +terraform apply |
| 92 | +``` |
| 93 | + |
| 94 | +Run `terraform destroy` when you don't need these resources. |
0 commit comments