Skip to content

Commit

Permalink
Add subnet for databases
Browse files Browse the repository at this point in the history
  • Loading branch information
tonybaloney committed Jul 17, 2024
1 parent 8f4b6e4 commit 42f0057
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
12 changes: 12 additions & 0 deletions {{cookiecutter.__src_folder_name}}/infra/db/cosmos-mongodb.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ param prefix string
param dbserverDatabaseName string
param sqlRoleAssignmentPrincipalId string
param keyvaultName string
param privateDNSZoneResourceId string
param subnetResourceId string

module databaseAccount 'br/public:avm/res/document-db/database-account:0.5.6' = {
name: name
Expand All @@ -31,6 +33,16 @@ module databaseAccount 'br/public:avm/res/document-db/database-account:0.5.6' =
name: dbserverDatabaseName
}
]
privateEndpoints: [
{
privateDnsZoneResourceIds: [
privateDNSZoneResourceId
]
service: 'MongoDB'
subnetResourceId: subnetResourceId
tags: tags
}
]
}
}

Expand Down
18 changes: 12 additions & 6 deletions {{cookiecutter.__src_folder_name}}/infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ param location string
@description('DBServer administrator password')
param dbserverPassword string
{% else %}
var dbserverPassword = '' // Only used by the linter
var dbserverPassword = guid(name, resourceGroup.name) // Only used by the linter
{% endif %}

{% if cookiecutter.project_backend in ("django", "flask") %}
Expand All @@ -34,6 +34,9 @@ var resourceToken = toLower(uniqueString(subscription().id, name, location))
var prefix = '${name}-${resourceToken}'
var tags = { 'azd-env-name': name }

var DATABASE_RESOURCE = '{{cookiecutter.db_resource}}'
var PROJECT_HOST = '{{cookiecutter.project_host}}'

var secrets = [
{% if cookiecutter.db_resource in ("postgres-flexible", "cosmos-postgres") %}
{
Expand Down Expand Up @@ -92,6 +95,11 @@ module virtualNetwork 'br/public:avm/res/network/virtual-network:0.1.8' = {
}
]
}
{
addressPrefix: '10.0.4.0/23'
name: 'db'
tags: tags
}
]
}
}
Expand Down Expand Up @@ -175,8 +183,6 @@ module roleAssignment 'core/security/role.bicep' = {
}
}

var DATABASE_RESOURCE = '{{cookiecutter.db_resource}}'

module cosmosMongoDb 'db/cosmos-mongodb.bicep' = if(DATABASE_RESOURCE == 'cosmos-mongodb') {
name: 'cosmosMongoDb'
scope: resourceGroup
Expand All @@ -188,6 +194,8 @@ module cosmosMongoDb 'db/cosmos-mongodb.bicep' = if(DATABASE_RESOURCE == 'cosmos
dbserverDatabaseName: 'relecloud'
sqlRoleAssignmentPrincipalId: web.outputs.SERVICE_WEB_IDENTITY_PRINCIPAL_ID
keyvaultName: keyVault.outputs.name
privateDNSZoneResourceId: privateDnsZone.outputs.resourceId
subnetResourceId: virtualNetwork.outputs.subnetResourceIds[2]
}
}

Expand Down Expand Up @@ -242,9 +250,8 @@ module monitoring 'core/monitor/monitoring.bicep' = {
}
}

{% if cookiecutter.project_host == "aca" %}
// Container apps host (including container registry)
module containerApps 'core/host/container-apps.bicep' = {
module containerApps 'core/host/container-apps.bicep' = if (PROJECT_HOST == 'aca') {
name: 'container-apps'
scope: resourceGroup
params: {
Expand All @@ -256,7 +263,6 @@ module containerApps 'core/host/container-apps.bicep' = {
virtualNetworkSubnetId: virtualNetwork.outputs.subnetResourceIds[1]
}
}
{% endif %}

// Web frontend
module web 'web.bicep' = {
Expand Down

0 comments on commit 42f0057

Please sign in to comment.