-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathdatabase.tf
More file actions
68 lines (61 loc) · 2.4 KB
/
database.tf
File metadata and controls
68 lines (61 loc) · 2.4 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#Create Random password
resource "random_password" "randompassword" {
length = 16
special = true
override_special = "!#$%&*()-_=+[]{}<>:?"
}
#Create Key Vault Secret
resource "azurerm_key_vault_secret" "sqladminpassword" {
# checkov:skip=CKV_AZURE_41:Expiration not needed
name = "sqladmin"
value = random_password.randompassword.result
key_vault_id = azurerm_key_vault.fg-keyvault.id
content_type = "text/plain"
depends_on = [
azurerm_key_vault.fg-keyvault,azurerm_key_vault_access_policy.kv_access_policy_01,azurerm_key_vault_access_policy.kv_access_policy_02,azurerm_key_vault_access_policy.kv_access_policy_03
]
}
#Azure sql database
resource "azurerm_mssql_server" "azuresql" {
name = "fg-sqldb-prod"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
version = "12.0"
administrator_login = "4adminu$er"
administrator_login_password = random_password.randompassword.result
azuread_administrator {
login_username = "AzureAD Admin"
object_id = "86f50fc0-0d0d-4c26-941d-17dd64ed03a6"
}
}
#add subnet from the backend vnet
#adding a new comment in main branch
resource "azurerm_mssql_virtual_network_rule" "allow-be" {
name = "be-sql-vnet-rule"
server_id = azurerm_mssql_server.azuresql.id
subnet_id = azurerm_subnet.be-subnet.id
depends_on = [
azurerm_mssql_server.azuresql
]
}
resource "azurerm_mssql_database" "fg-database" {
name = "fg-db"
server_id = azurerm_mssql_server.azuresql.id
collation = "SQL_Latin1_General_CP1_CI_AS"
max_size_gb = 2
read_scale = false
sku_name = "S0"
zone_redundant = false
tags = {
Application = "Fitnessgeek-demo"
Env = "Prod"
}
}
resource "azurerm_key_vault_secret" "sqldb_cnxn" {
name = "fgsqldbconstring"
value = "Driver={ODBC Driver 18 for SQL Server};Server=tcp:fg-sqldb-prod.database.windows.net,1433;Database=fg-db;Uid=4adminu$er;Pwd=${random_password.randompassword.result};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;"
key_vault_id = azurerm_key_vault.fg-keyvault.id
depends_on = [
azurerm_mssql_database.fg-database,azurerm_key_vault_access_policy.kv_access_policy_01,azurerm_key_vault_access_policy.kv_access_policy_02,azurerm_key_vault_access_policy.kv_access_policy_03
]
}