Skip to content

Commit 1bfadc6

Browse files
committed
adding example to create SQL DB with geo-replication, auto-failover groups and Private Endpoints using existing VNet and Subnets
1 parent 8109b42 commit 1bfadc6

File tree

8 files changed

+320
-5
lines changed

8 files changed

+320
-5
lines changed

examples/SQL_DB_with_Geo-replication_Auto-Failover_Groups_and_Private_Endpoints/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Azure SQL database creation with geo-replication, auto-failover groups and Private Endpoints
1+
# Azure SQL database with geo-replication, auto-failover groups and Private Endpoints
22

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

@@ -46,7 +46,9 @@ module "mssql-server" {
4646
enable_failover_group = true
4747
secondary_sql_server_location = "northeurope"
4848
49-
# enabling the Private Endpoints for Sql servers
49+
# Creating Private Endpoint requires, VNet name and address prefix to create a subnet
50+
# By default this will create a `privatelink.vaultcore.azure.net` DNS zone.
51+
# To use existing private DNS zone specify `existing_private_dns_zone` with valid zone name
5052
enable_private_endpoint = true
5153
virtual_network_name = "vnet-shared-hub-westeurope-001"
5254
private_subnet_address_prefix = ["10.1.5.0/29"]

examples/SQL_DB_with_Geo-replication_Auto-Failover_Groups_and_Private_Endpoints/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ module "mssql-server" {
3939
enable_failover_group = true
4040
secondary_sql_server_location = "northeurope"
4141

42-
# enabling the Private Endpoints for Sql servers
42+
# Creating Private Endpoint requires, VNet name and address prefix to create a subnet
43+
# By default this will create a `privatelink.vaultcore.azure.net` DNS zone.
44+
# To use existing private DNS zone specify `existing_private_dns_zone` with valid zone name
4345
enable_private_endpoint = true
4446
virtual_network_name = "vnet-shared-hub-westeurope-001"
4547
private_subnet_address_prefix = ["10.1.5.0/29"]
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
data "azurerm_virtual_network" "example" {
14+
name = "vnet-shared-hub-westeurope-001"
15+
resource_group_name = "rg-shared-westeurope-01"
16+
}
17+
18+
data "azurerm_subnet" "example" {
19+
name = "snet-private-ep"
20+
virtual_network_name = data.azurerm_virtual_network.example.name
21+
resource_group_name = data.azurerm_virtual_network.example.resource_group_name
22+
}
23+
24+
module "mssql-server" {
25+
source = "kumarvna/mssql-db/azurerm"
26+
version = "1.3.0"
27+
28+
# By default, this module will create a resource group
29+
# proivde a name to use an existing resource group and set the argument
30+
# to `create_resource_group = false` if you want to existing resoruce group.
31+
# If you use existing resrouce group location will be the same as existing RG.
32+
create_resource_group = false
33+
resource_group_name = "rg-shared-westeurope-01"
34+
location = "westeurope"
35+
36+
# SQL Server and Database details
37+
# The valid service objective name for the database include S0, S1, S2, S3, P1, P2, P4, P6, P11
38+
sqlserver_name = "te-sqldbserver01"
39+
database_name = "demomssqldb"
40+
sql_database_edition = "Standard"
41+
sqldb_service_objective_name = "S1"
42+
43+
# SQL server extended auditing policy defaults to `true`.
44+
# To turn off set enable_sql_server_extended_auditing_policy to `false`
45+
# DB extended auditing policy defaults to `false`.
46+
# to tun on set the variable `enable_database_extended_auditing_policy` to `true`
47+
# To enable Azure Defender for database set `enable_threat_detection_policy` to true
48+
enable_threat_detection_policy = true
49+
log_retention_days = 30
50+
51+
# schedule scan notifications to the subscription administrators
52+
# Manage Vulnerability Assessment set `enable_vulnerability_assessment` to `true`
53+
enable_vulnerability_assessment = false
54+
email_addresses_for_alerts = ["[email protected]", "[email protected]"]
55+
56+
# Sql failover group creation. required secondary locaiton input.
57+
enable_failover_group = true
58+
secondary_sql_server_location = "northeurope"
59+
60+
# Creating Private Endpoint requires, VNet name and address prefix to create a subnet
61+
# By default this will create a `privatelink.vaultcore.azure.net` DNS zone.
62+
# To use existing private DNS zone specify `existing_private_dns_zone` with valid zone name
63+
enable_private_endpoint = true
64+
existing_vnet_id = data.azurerm_virtual_network.example.id
65+
existing_subnet_id = data.azurerm_subnet.example.id
66+
# existing_private_dns_zone = "demo.example.com"
67+
68+
# AD administrator for an Azure SQL server
69+
# Allows you to set a user or group as the AD administrator for an Azure SQL server
70+
ad_admin_login_name = "[email protected]"
71+
72+
# (Optional) To enable Azure Monitoring for Azure SQL database including audit logs
73+
# log analytic workspace name required
74+
enable_log_monitoring = true
75+
log_analytics_workspace_name = "loganalytics-we-sharedtest2"
76+
77+
# Firewall Rules to allow azure and external clients and specific Ip address/ranges.
78+
enable_firewall_rules = true
79+
firewall_rules = [
80+
{
81+
name = "access-to-azure"
82+
start_ip_address = "0.0.0.0"
83+
end_ip_address = "0.0.0.0"
84+
},
85+
{
86+
name = "desktop-ip"
87+
start_ip_address = "123.201.36.94"
88+
end_ip_address = "123.201.36.94"
89+
}
90+
]
91+
92+
# Adding additional TAG's to your Azure resources
93+
tags = {
94+
ProjectName = "demo-project"
95+
Env = "dev"
96+
97+
BusinessUnit = "CORP"
98+
ServiceClass = "Gold"
99+
}
100+
}
101+
```
102+
103+
## Terraform Usage
104+
105+
To run this example you need to execute following Terraform commands
106+
107+
```bash
108+
terraform init
109+
terraform plan
110+
terraform apply
111+
```
112+
113+
Run `terraform destroy` when you don't need these resources.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Azurerm provider configuration
2+
provider "azurerm" {
3+
features {}
4+
}
5+
6+
data "azurerm_virtual_network" "example" {
7+
name = "vnet-shared-hub-westeurope-001"
8+
resource_group_name = "rg-shared-westeurope-01"
9+
}
10+
11+
data "azurerm_subnet" "example" {
12+
name = "snet-private-ep"
13+
virtual_network_name = data.azurerm_virtual_network.example.name
14+
resource_group_name = data.azurerm_virtual_network.example.resource_group_name
15+
}
16+
17+
module "mssql-server" {
18+
source = "kumarvna/mssql-db/azurerm"
19+
version = "1.3.0"
20+
21+
# By default, this module will create a resource group
22+
# proivde a name to use an existing resource group and set the argument
23+
# to `create_resource_group = false` if you want to existing resoruce group.
24+
# If you use existing resrouce group location will be the same as existing RG.
25+
create_resource_group = false
26+
resource_group_name = "rg-shared-westeurope-01"
27+
location = "westeurope"
28+
29+
# SQL Server and Database details
30+
# The valid service objective name for the database include S0, S1, S2, S3, P1, P2, P4, P6, P11
31+
sqlserver_name = "te-sqldbserver01"
32+
database_name = "demomssqldb"
33+
sql_database_edition = "Standard"
34+
sqldb_service_objective_name = "S1"
35+
36+
# SQL server extended auditing policy defaults to `true`.
37+
# To turn off set enable_sql_server_extended_auditing_policy to `false`
38+
# DB extended auditing policy defaults to `false`.
39+
# to tun on set the variable `enable_database_extended_auditing_policy` to `true`
40+
# To enable Azure Defender for database set `enable_threat_detection_policy` to true
41+
enable_threat_detection_policy = true
42+
log_retention_days = 30
43+
44+
# schedule scan notifications to the subscription administrators
45+
# Manage Vulnerability Assessment set `enable_vulnerability_assessment` to `true`
46+
enable_vulnerability_assessment = false
47+
email_addresses_for_alerts = ["[email protected]", "[email protected]"]
48+
49+
# Sql failover group creation. required secondary locaiton input.
50+
enable_failover_group = true
51+
secondary_sql_server_location = "northeurope"
52+
53+
# Creating Private Endpoint requires, VNet name and address prefix to create a subnet
54+
# By default this will create a `privatelink.vaultcore.azure.net` DNS zone.
55+
# To use existing private DNS zone specify `existing_private_dns_zone` with valid zone name
56+
enable_private_endpoint = true
57+
existing_vnet_id = data.azurerm_virtual_network.example.id
58+
existing_subnet_id = data.azurerm_subnet.example.id
59+
# existing_private_dns_zone = "demo.example.com"
60+
61+
# AD administrator for an Azure SQL server
62+
# Allows you to set a user or group as the AD administrator for an Azure SQL server
63+
ad_admin_login_name = "[email protected]"
64+
65+
# (Optional) To enable Azure Monitoring for Azure SQL database including audit logs
66+
# log analytic workspace name required
67+
enable_log_monitoring = true
68+
log_analytics_workspace_name = "loganalytics-we-sharedtest2"
69+
70+
# Firewall Rules to allow azure and external clients and specific Ip address/ranges.
71+
enable_firewall_rules = true
72+
firewall_rules = [
73+
{
74+
name = "access-to-azure"
75+
start_ip_address = "0.0.0.0"
76+
end_ip_address = "0.0.0.0"
77+
},
78+
{
79+
name = "desktop-ip"
80+
start_ip_address = "123.201.36.94"
81+
end_ip_address = "123.201.36.94"
82+
}
83+
]
84+
85+
# Adding additional TAG's to your Azure resources
86+
tags = {
87+
ProjectName = "demo-project"
88+
Env = "dev"
89+
90+
BusinessUnit = "CORP"
91+
ServiceClass = "Gold"
92+
}
93+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
output "resource_group_name" {
2+
description = "The name of the resource group in which resources are created"
3+
value = module.mssql-server.resource_group_name
4+
}
5+
6+
output "resource_group_location" {
7+
description = "The location of the resource group in which resources are created"
8+
value = module.mssql-server.resource_group_location
9+
}
10+
11+
output "storage_account_id" {
12+
description = "The ID of the storage account"
13+
value = module.mssql-server.storage_account_id
14+
}
15+
16+
output "storage_account_name" {
17+
description = "The name of the storage account"
18+
value = module.mssql-server.storage_account_name
19+
}
20+
21+
output "primary_sql_server_id" {
22+
description = "The primary Microsoft SQL Server ID"
23+
value = module.mssql-server.primary_sql_server_id
24+
}
25+
26+
output "primary_sql_server_fqdn" {
27+
description = "The fully qualified domain name of the primary Azure SQL Server"
28+
value = module.mssql-server.primary_sql_server_fqdn
29+
}
30+
31+
output "secondary_sql_server_id" {
32+
description = "The secondary Microsoft SQL Server ID"
33+
value = module.mssql-server.secondary_sql_server_id
34+
}
35+
36+
output "secondary_sql_server_fqdn" {
37+
description = "The fully qualified domain name of the secondary Azure SQL Server"
38+
value = module.mssql-server.secondary_sql_server_fqdn
39+
}
40+
41+
output "sql_server_admin_user" {
42+
description = "SQL database administrator login id"
43+
value = module.mssql-server.sql_server_admin_user
44+
sensitive = true
45+
}
46+
47+
output "sql_server_admin_password" {
48+
description = "SQL database administrator login password"
49+
value = module.mssql-server.sql_server_admin_password
50+
sensitive = true
51+
}
52+
53+
output "sql_database_id" {
54+
description = "The SQL Database ID"
55+
value = module.mssql-server.sql_database_id
56+
}
57+
58+
output "sql_database_name" {
59+
description = "The SQL Database Name"
60+
value = module.mssql-server.sql_database_name
61+
}
62+
63+
output "sql_failover_group_id" {
64+
description = "A failover group of databases on a collection of Azure SQL servers."
65+
value = module.mssql-server.sql_failover_group_id
66+
}
67+
68+
output "primary_sql_server_private_endpoint" {
69+
description = "id of the Primary SQL server Private Endpoint"
70+
value = module.mssql-server.primary_sql_server_private_endpoint
71+
}
72+
73+
output "secondary_sql_server_private_endpoint" {
74+
description = "id of the Primary SQL server Private Endpoint"
75+
value = module.mssql-server.secondary_sql_server_private_endpoint
76+
}
77+
78+
output "sql_server_private_dns_zone_domain" {
79+
description = "DNS zone name of SQL server Private endpoints dns name records"
80+
value = module.mssql-server.sql_server_private_dns_zone_domain
81+
}
82+
83+
output "primary_sql_server_private_endpoint_ip" {
84+
description = "Priamary SQL server private endpoint IPv4 Addresses "
85+
value = module.mssql-server.primary_sql_server_private_endpoint_ip
86+
}
87+
88+
output "primary_sql_server_private_endpoint_fqdn" {
89+
description = "Priamary SQL server private endpoint IPv4 Addresses "
90+
value = module.mssql-server.primary_sql_server_private_endpoint_fqdn
91+
}
92+
93+
output "secondary_sql_server_private_endpoint_ip" {
94+
description = "Secondary SQL server private endpoint IPv4 Addresses "
95+
value = module.mssql-server.secondary_sql_server_private_endpoint_ip
96+
}
97+
98+
output "secondary_sql_server_private_endpoint_fqdn" {
99+
description = "Secondary SQL server private endpoint IPv4 Addresses "
100+
value = module.mssql-server.secondary_sql_server_private_endpoint_fqdn
101+
}

examples/SQL_DB_with_Geo-replication_Auto-Failover_Groups_and_Private_Endpoints_using_existing_VNet_and_Subnets/variables.tf

Whitespace-only changes.

examples/Simple_SQL_Single_Database_with_Private_Endpoint_using_existing_VNet_and_Subnets/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ module "mssql-server" {
5353
enable_vulnerability_assessment = false
5454
email_addresses_for_alerts = ["[email protected]", "[email protected]"]
5555
56-
# enabling the Private Endpoints for Sql servers
56+
# Creating Private Endpoint requires, VNet name and address prefix to create a subnet
57+
# By default this will create a `privatelink.vaultcore.azure.net` DNS zone.
58+
# To use existing private DNS zone specify `existing_private_dns_zone` with valid zone name
5759
enable_private_endpoint = true
5860
existing_vnet_id = data.azurerm_virtual_network.example.id
5961
existing_subnet_id = data.azurerm_subnet.example.id

examples/Simple_SQL_Single_Database_with_Private_Endpoint_using_existing_VNet_and_Subnets/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ module "mssql-server" {
4646
enable_vulnerability_assessment = false
4747
email_addresses_for_alerts = ["[email protected]", "[email protected]"]
4848

49-
# enabling the Private Endpoints for Sql servers
49+
# Creating Private Endpoint requires, VNet name and address prefix to create a subnet
50+
# By default this will create a `privatelink.vaultcore.azure.net` DNS zone.
51+
# To use existing private DNS zone specify `existing_private_dns_zone` with valid zone name
5052
enable_private_endpoint = true
5153
existing_vnet_id = data.azurerm_virtual_network.example.id
5254
existing_subnet_id = data.azurerm_subnet.example.id

0 commit comments

Comments
 (0)