-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql_server.tf
46 lines (39 loc) · 1.36 KB
/
sql_server.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
resource "random_password" "admin_password" {
count = var.admin_password == null ? 1 : 0
length = 20
special = true
min_numeric = 1
min_upper = 1
min_lower = 1
min_special = 1
}
locals {
admin_password = try(random_password.admin_password[0].result, var.admin_password)
}
resource "azurerm_mssql_server" "server" {
name = "sqlserver-${random_integer.ri.result}"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
administrator_login = var.admin_username
administrator_login_password = local.admin_password
version = "12.0"
}
resource "azurerm_mssql_database" "db" {
name = var.sql_db_name
server_id = azurerm_mssql_server.server.id
}
resource "azurerm_private_endpoint" "terraform_endpoint" {
name = "sql-pe"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
subnet_id = azurerm_subnet.subnet.id
private_service_connection {
name = "sql-pe-serviceconnection"
private_connection_resource_id = azurerm_mssql_server.server.id
subresource_names = ["sqlServer"]
is_manual_connection = false
}
depends_on = [
azurerm_subnet.subnet,
]
}