Skip to content

Commit

Permalink
Fix networking and database connection from API
Browse files Browse the repository at this point in the history
  • Loading branch information
russdaygh committed Apr 21, 2024
1 parent 195e6ea commit 66ae37d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,4 @@ MigrationBackup/
*.tfstate
*.tfstate.backup
terraform/.terraform.lock.hcl
terraform/.terraform.tfstate.lock.info
2 changes: 0 additions & 2 deletions terraform/api_server.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@ resource "azurerm_linux_web_app" "api_server_web_app" {
type = "SQLAzure"
value = local.db_connection_string
}

virtual_network_subnet_id = azurerm_subnet.subnet.id
}
9 changes: 5 additions & 4 deletions terraform/database.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ resource "azurerm_mssql_database" "sqldb" {
}
}

resource "azurerm_mssql_virtual_network_rule" "sqlserver_subnet_rule" {
name = "sql-vnet-rule"
server_id = azurerm_mssql_server.sqlserver.id
subnet_id = azurerm_subnet.subnet.id
resource "azurerm_mssql_firewall_rule" "firewall_rule" {
name = "AllowAllAzureServices"
server_id = azurerm_mssql_server.sqlserver.id
start_ip_address = "0.0.0.0"
end_ip_address = "0.0.0.0"
}
8 changes: 7 additions & 1 deletion terraform/keyvault.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ resource "azurerm_key_vault_secret" "sqldb_connectionstring" {
name = "${local.resource_prefix}-db-connection-string"
value = local.db_connection_string
key_vault_id = azurerm_key_vault.key_vault.id
}
}

resource "azurerm_key_vault_secret" "sqldb_admin_password" {
name = "${local.resource_prefix}-db-admin-password"
value = random_password.admin_password.result
key_vault_id = azurerm_key_vault.key_vault.id
}
4 changes: 2 additions & 2 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resource "random_password" "admin_password" {
}

locals {
db_connection_string = "Server=tcp:${local.sql_server_name}.database.windows.net,1433;Persist Security Info=False;User ID=${random_string.admin_login.result};Password=${random_password.admin_password.result};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
db_connection_string = "Server=tcp:${local.sql_server_name}.database.windows.net,1433;Initial Catalog=pocketddd-dev-sqldatabase;Persist Security Info=False;User ID=${random_string.admin_login.result};Password=${random_password.admin_password.result};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
}

resource "azurerm_virtual_network" "vnet" {
Expand All @@ -40,7 +40,7 @@ resource "azurerm_subnet" "subnet" {

service_delegation {
name = "Microsoft.Web/serverFarms"
actions = ["Microsoft.Network/virtualNetworks/subnets/join/action", "Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action"]
actions = ["Microsoft.Network/virtualNetworks/subnets/action"]
}
}

Expand Down
2 changes: 1 addition & 1 deletion terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "api_server_url" {
value = "https://${azurerm_linux_web_app.api_server_web_app.default_hostname}/"
}
}

0 comments on commit 66ae37d

Please sign in to comment.