Skip to content

Commit d89c2d2

Browse files
committed
adding example to use existing Vnet and Subnet to create private endpoint
1 parent 926b587 commit d89c2d2

File tree

8 files changed

+290
-17
lines changed

8 files changed

+290
-17
lines changed

examples/Simple_SQL_Single_Database_creation/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ module "mssql-server" {
6666
}
6767
]
6868
69-
# Tags for Azure Resources
69+
# Adding additional TAG's to your Azure resources
7070
tags = {
71-
Terraform = "true"
72-
Environment = "dev"
73-
Owner = "test-user"
71+
ProjectName = "demo-project"
72+
Env = "dev"
73+
74+
BusinessUnit = "CORP"
75+
ServiceClass = "Gold"
7476
}
7577
}
7678
```

examples/Simple_SQL_Single_Database_creation/main.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ module "mssql-server" {
5959
}
6060
]
6161

62-
# Tags for Azure Resources
62+
# Adding additional TAG's to your Azure resources
6363
tags = {
64-
Terraform = "true"
65-
Environment = "dev"
66-
Owner = "test-user"
64+
ProjectName = "demo-project"
65+
Env = "dev"
66+
67+
BusinessUnit = "CORP"
68+
ServiceClass = "Gold"
6769
}
6870
}

examples/Simple_SQL_Single_Database_with_Private_Endpoint/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Simple Azure SQL single database using private Endpoint
1+
# Simple Azure SQL single database with private link Endpoint
22

33
Terraform module to create a SQL server with initial database, Azure AD login, Firewall rules for SQL, optional azure monitoring vulnerability assessment and private endpoints. It also allows creating an SQL server database with a SQL script initialization.
44

@@ -74,11 +74,13 @@ module "mssql-server" {
7474
}
7575
]
7676
77-
# Tags for Azure Resources
77+
# Adding additional TAG's to your Azure resources
7878
tags = {
79-
Terraform = "true"
80-
Environment = "dev"
81-
Owner = "test-user"
79+
ProjectName = "demo-project"
80+
Env = "dev"
81+
82+
BusinessUnit = "CORP"
83+
ServiceClass = "Gold"
8284
}
8385
}
8486
```

examples/Simple_SQL_Single_Database_with_Private_Endpoint/main.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ module "mssql-server" {
6767
}
6868
]
6969

70-
# Tags for Azure Resources
70+
# Adding additional TAG's to your Azure resources
7171
tags = {
72-
Terraform = "true"
73-
Environment = "dev"
74-
Owner = "test-user"
72+
ProjectName = "demo-project"
73+
Env = "dev"
74+
75+
BusinessUnit = "CORP"
76+
ServiceClass = "Gold"
7577
}
7678
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Simple Azure SQL single database with private Endpoint using existing VNet and Subnets
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 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.2.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+
# enabling the Private Endpoints for Sql servers
57+
enable_private_endpoint = true
58+
existing_vnet_id = data.azurerm_virtual_network.example.id
59+
existing_subnet_id = data.azurerm_subnet.example.id
60+
# existing_private_dns_zone = "demo.example.com"
61+
62+
# AD administrator for an Azure SQL server
63+
# Allows you to set a user or group as the AD administrator for an Azure SQL server
64+
ad_admin_login_name = "[email protected]"
65+
66+
# (Optional) To enable Azure Monitoring for Azure SQL database including audit logs
67+
# log analytic workspace name required
68+
enable_log_monitoring = true
69+
log_analytics_workspace_name = "loganalytics-we-sharedtest2"
70+
71+
# Firewall Rules to allow azure and external clients and specific Ip address/ranges.
72+
enable_firewall_rules = true
73+
firewall_rules = [
74+
{
75+
name = "access-to-azure"
76+
start_ip_address = "0.0.0.0"
77+
end_ip_address = "0.0.0.0"
78+
},
79+
{
80+
name = "desktop-ip"
81+
start_ip_address = "123.201.36.94"
82+
end_ip_address = "123.201.36.94"
83+
}
84+
]
85+
86+
# Adding additional TAG's to your Azure resources
87+
tags = {
88+
ProjectName = "demo-project"
89+
Env = "dev"
90+
91+
BusinessUnit = "CORP"
92+
ServiceClass = "Gold"
93+
}
94+
}
95+
```
96+
97+
## Terraform Usage
98+
99+
To run this example you need to execute following Terraform commands
100+
101+
```bash
102+
terraform init
103+
terraform plan
104+
terraform apply
105+
```
106+
107+
Run `terraform destroy` when you don't need these resources.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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.2.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+
# enabling the Private Endpoints for Sql servers
50+
enable_private_endpoint = true
51+
existing_vnet_id = data.azurerm_virtual_network.example.id
52+
existing_subnet_id = data.azurerm_subnet.example.id
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+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 "sql_server_admin_user" {
32+
description = "SQL database administrator login id"
33+
value = module.mssql-server.sql_server_admin_user
34+
sensitive = true
35+
}
36+
37+
output "sql_server_admin_password" {
38+
description = "SQL database administrator login password"
39+
value = module.mssql-server.sql_server_admin_password
40+
sensitive = true
41+
}
42+
43+
output "sql_database_id" {
44+
description = "The SQL Database ID"
45+
value = module.mssql-server.sql_database_id
46+
}
47+
48+
output "sql_database_name" {
49+
description = "The SQL Database Name"
50+
value = module.mssql-server.sql_database_name
51+
}
52+
53+
output "primary_sql_server_private_endpoint" {
54+
description = "id of the Primary SQL server Private Endpoint"
55+
value = module.mssql-server.primary_sql_server_private_endpoint
56+
}
57+
58+
output "sql_server_private_dns_zone_domain" {
59+
description = "DNS zone name of SQL server Private endpoints dns name records"
60+
value = module.mssql-server.sql_server_private_dns_zone_domain
61+
}
62+
63+
output "primary_sql_server_private_endpoint_ip" {
64+
description = "Priamary SQL server private endpoint IPv4 Addresses "
65+
value = module.mssql-server.primary_sql_server_private_endpoint_ip
66+
}
67+
68+
output "primary_sql_server_private_endpoint_fqdn" {
69+
description = "Priamary SQL server private endpoint IPv4 Addresses "
70+
value = module.mssql-server.primary_sql_server_private_endpoint_fqdn
71+
}

examples/Simple_SQL_Single_Database_with_Private_Endpoint_using_existing_VNet_and_Subnets/variables.tf

Whitespace-only changes.

0 commit comments

Comments
 (0)