Skip to content

Commit e97bb43

Browse files
committed
module update
1 parent 3179f7b commit e97bb43

File tree

4 files changed

+124
-71
lines changed

4 files changed

+124
-71
lines changed
Lines changed: 93 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,73 @@
1-
# Azure SQL Database Using Failover Groups with Private endpoints
1+
# Simple Azure SQL single database creation
22

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.
44

55
## Module Usage
66

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
128
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
4151
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
5471
tags = {
5572
Terraform = "true"
5673
Environment = "dev"
@@ -63,10 +80,35 @@ module "mssql-server" {
6380

6481
To run this example you need to execute following Terraform commands
6582

66-
```
67-
$ terraform init
68-
$ terraform plan
69-
$ terraform apply
83+
```bash
84+
terraform init
85+
terraform plan
86+
terraform apply
7087
```
7188

7289
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

examples/Simple_SQL_Single_Database_creation/main.tf

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

75
# By default, this module will create a resource group, proivde the name here
86
# to use an existing resource group, specify the existing resource group name,
@@ -13,25 +11,35 @@ module "mssql-server" {
1311
virtual_network_name = "vnet-shared-hub-westeurope-001"
1412
private_subnet_address_prefix = ["10.1.5.0/29"]
1513

16-
# SQL Server and Database scaling options
17-
sqlserver_name = "sqldbserver-db01"
14+
# SQL Server and Database details
15+
# The valid service objective name for the database include S0, S1, S2, S3, P1, P2, P4, P6, P11
16+
sqlserver_name = "sqldbserver01"
1817
database_name = "demomssqldb"
1918
sql_database_edition = "Standard"
2019
sqldb_service_objective_name = "S1"
2120

22-
# SQL Server and Database Audit policies
23-
enable_extended_auditing_policy = false
24-
enable_threat_detection_policy = true
25-
log_retention_days = 30
26-
sql_admin_email_addresses = ["[email protected]"]
21+
# SQL Server and Database Audit policies
22+
# By default database servers extended auditing policy enabled. you can turn of using enable_sql_server_extended_auditing_policy
23+
# By default database extended auditing policy is turned off. you can manage the setting by adding `enable_database_extended_auditing_policy`
24+
# To manage Azure Defender for Azure SQL database servers set `enable_threat_detection_policy` to true
25+
enable_threat_detection_policy = true
26+
log_retention_days = 30
27+
28+
# schedule scan notifications to the subscription administrators
29+
# Manages the Vulnerability Assessment for a MS SQL Server set `enable_vulnerability_assessment` to `true`
30+
enable_vulnerability_assessment = true
31+
sql_admin_email_addresses = ["[email protected]", "[email protected]"]
2732

2833
# AD administrator for an Azure SQL server
29-
enable_sql_ad_admin = true
34+
# Allows you to set a user or group as the AD administrator for an Azure SQL server
3035
ad_admin_login_name = "[email protected]"
3136

32-
enable_vulnerability_assessment = false
37+
# (Optional) To enable Azure Monitoring for Azure SQL database including audit logs
38+
# log analytic workspace name required
39+
enable_log_monitoring = true
40+
log_analytics_workspace_name = "loganalytics-we-sharedtest2"
3341

34-
# Firewall Rules to allow azure and external clients
42+
# Firewall Rules to allow azure and external clients and specific Ip address/ranges.
3543
enable_firewall_rules = true
3644
firewall_rules = [
3745
{
@@ -43,9 +51,12 @@ module "mssql-server" {
4351
name = "desktop-ip"
4452
start_ip_address = "49.204.225.134"
4553
end_ip_address = "49.204.225.134"
46-
}]
54+
}
55+
]
4756

48-
# Create and initialize a database with SQL script
57+
# Create and initialize a database with custom SQL script
58+
# need sqlcmd utility to run this command
59+
# your desktop public IP must be added firewall rules to run this command
4960
initialize_sql_script_execution = true
5061
sqldb_init_script_file = "../artifacts/db-init-sample.sql"
5162

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,4 +442,4 @@ resource "azurerm_monitor_diagnostic_setting" "extaudit" {
442442
lifecycle {
443443
ignore_changes = [log, metric]
444444
}
445-
}
445+
}

variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ variable "create_resource_group" {
55

66
variable "resource_group_name" {
77
description = "A container that holds related resources for an Azure solution"
8-
default = "rg-demo-westeurope-01"
8+
default = ""
99
}
1010

1111
variable "storage_account_name" {
@@ -20,7 +20,7 @@ variable "log_analytics_workspace_name" {
2020

2121
variable "location" {
2222
description = "The location/region to keep all your network resources. To get the list of all locations with table format from azure cli, run 'az account list-locations -o table'"
23-
default = "westeurope"
23+
default = ""
2424
}
2525

2626
variable "random_password_length" {
@@ -45,7 +45,7 @@ variable "enable_threat_detection_policy" {
4545

4646
variable "sqlserver_name" {
4747
description = "SQL server Name"
48-
default = "sqldbserver-demodbapp"
48+
default = ""
4949
}
5050

5151
variable "admin_username" {

0 commit comments

Comments
 (0)