Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the database modules and move to AVM #86

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 0 additions & 117 deletions {{cookiecutter.__src_folder_name}}/infra/db.bicep

This file was deleted.

17 changes: 17 additions & 0 deletions {{cookiecutter.__src_folder_name}}/infra/db/cosmos-mongodb.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
param name string
param location string = resourceGroup().location
param tags object = {}
param prefix string
param keyVaultName string
param dbserverDatabaseName string

module dbserver '../core/database/cosmos/mongo/cosmos-mongo-db.bicep' = {
name: name
params: {
accountName: '${take(prefix, 36)}-mongodb' // Max 44 characters
location: location
databaseName: dbserverDatabaseName
tags: tags
keyVaultName: keyVaultName
}
}
29 changes: 29 additions & 0 deletions {{cookiecutter.__src_folder_name}}/infra/db/cosmos-postgres.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// {% set pg_version = 15 %}

param name string
param location string = resourceGroup().location
param tags object = {}
param prefix string
param dbserverDatabaseName string
var dbserverUser = 'citus'
@secure()
param dbserverPassword string

module dbserver '../core/database/cosmos/cosmos-pg-adapter.bicep' = {

Check failure

Code scanning / templateanalyzer

Administrator Username Types. Error

Resource properties can be configured using a hardcoded value or Azure Bicep/ template expressions. When specifying sensitive values use secure parameters such as secureString or secureObject.
Sensitive values that use deterministic expressions such as hardcodes string literals or variables are not secure.
name: name
params: {
name: '${prefix}-postgresql'
location: location
tags: tags
postgresqlVersion: '{{pg_version}}'
administratorLogin: dbserverUser
administratorLoginPassword: dbserverPassword
databaseName: dbserverDatabaseName
allowAzureIPsFirewall: true
coordinatorServerEdition: 'BurstableMemoryOptimized'
coordinatorStorageQuotainMb: 131072
coordinatorVCores: 1
nodeCount: 0
nodeVCores: 4
}
}
21 changes: 21 additions & 0 deletions {{cookiecutter.__src_folder_name}}/infra/db/postgres-addon.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
param containerAppsEnvironmentName string
param name string
param location string = resourceGroup().location
param tags object = {}
param prefix string

resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2022-03-01' existing = {
name: containerAppsEnvironmentName
}

module dbserver '../core/database/postgresql/aca-service.bicep' = {
name: name
params: {
name: '${take(prefix, 29)}-pg' // max 32 characters
location: location
tags: tags
containerAppsEnvironmentId: containerAppsEnvironment.id
}
}

output id string = dbserver.outputs.id
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
param name string
param location string = resourceGroup().location
param tags object = {}
param prefix string

// value is read-only in cosmos
var dbserverUser = 'admin${uniqueString(resourceGroup().id)}'
@secure()
param dbserverPassword string = ''
param dbserverDatabaseName string = ''

module dbserver '../core/database/postgresql/flexibleserver.bicep' = {
name: name
params: {
name: '${prefix}-postgresql'
location: location
tags: tags
sku: {
name: 'Standard_B1ms'
tier: 'Burstable'
}
storage: {
storageSizeGB: 32
}
version: '{{pg_version}}'
administratorLogin: dbserverUser
administratorLoginPassword: dbserverPassword
databaseNames: [dbserverDatabaseName]
allowAzureIPsFirewall: true
}
}

output dbserverDatabaseName string = dbserverDatabaseName
output dbserverUser string = dbserverUser

// "postgres-flexible", "cosmos-postgres"
output dbserverDomainName string = dbserver.outputs.domainName
71 changes: 56 additions & 15 deletions {{cookiecutter.__src_folder_name}}/infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -173,26 +173,56 @@ module roleAssignment 'core/security/role.bicep' = {
}
}

module db 'db.bicep' = {
name: 'db'
var DATABASE_RESOURCE = '{{cookiecutter.db_resource}}'

module cosmosMongoDb 'db/cosmos-mongodb.bicep' = if(DATABASE_RESOURCE == 'cosmos-mongodb') {
name: 'cosmosMongoDb'
scope: resourceGroup
params: {
name: 'dbserver'
location: location
tags: tags
prefix: prefix
{% if "mongodb" in cookiecutter.db_resource %}
keyVaultName: keyVault.outputs.name
{% endif %}
{% if cookiecutter.db_resource != "postgres-addon" %}
dbserverDatabaseName: 'relecloud'
{% endif %}
{% if cookiecutter.db_resource in ("postgres-flexible", "cosmos-postgres")%}
}
}

module cosmosPostgres 'db/cosmos-postgres.bicep' = if(DATABASE_RESOURCE == 'cosmos-postgres') {
name: 'cosmosPostgres'
scope: resourceGroup
params: {
name: 'dbserver'
location: location
tags: tags
prefix: prefix
dbserverDatabaseName: 'relecloud'
dbserverPassword: dbserverPassword
{% endif %}
{% if cookiecutter.db_resource == "postgres-addon" %}
}
}

module postgresAddon 'db/postgres-addon.bicep' = if(DATABASE_RESOURCE == 'postgres-addon') {
name: 'postgresAddon'
scope: resourceGroup
params: {
name: 'dbserver'
location: location
tags: tags
prefix: prefix
containerAppsEnvironmentName: containerApps.outputs.environmentName
{% endif %}
}
}

module postgresFlexible 'db/postgres-flexible.bicep' = if(DATABASE_RESOURCE == 'postgres-flexible') {
name: 'postgresFlexible'
scope: resourceGroup
params: {
name: 'dbserver'
location: location
tags: tags
prefix: prefix
dbserverDatabaseName: 'relecloud'
dbserverPassword: dbserverPassword
}
}

Expand Down Expand Up @@ -252,16 +282,27 @@ module web 'web.bicep' = {
containerRegistryName: containerApps.outputs.registryName
exists: webAppExists
{% endif %}
{% if cookiecutter.db_resource in ("postgres-flexible", "cosmos-postgres") %}
dbserverDomainName: db.outputs.dbserverDomainName
dbserverUser: db.outputs.dbserverUser
dbserverDatabaseName: db.outputs.dbserverDatabaseName

{% if cookiecutter.db_resource == "postgres-flexible" %}
dbserverDomainName: postgresFlexible.outputs.dbserverDomainName
dbserverUser: postgresFlexible.outputs.dbserverUser
dbserverDatabaseName: postgresFlexible.outputs.dbserverDatabaseName
{% endif %}

{% if cookiecutter.db_resource == "cosmos-postgres" %}
dbserverDomainName: cosmosPostgres.outputs.dbserverDomainName
dbserverUser: cosmosPostgres.outputs.dbserverUser
dbserverDatabaseName: cosmosPostgres.outputs.dbserverDatabaseName
{% endif %}

{% if cookiecutter.project_host == "aca" %}
dbserverPassword: dbserverPassword
{% endif %}

{% endif %}

{% if cookiecutter.db_resource == "postgres-addon" %}
postgresServiceId: db.outputs.dbserverID
postgresServiceId: postgresAddon.outputs.id
{% endif %}
}
}
Expand Down
Loading