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

fix: Environment variable issue related to postgreSQL #48

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 2 additions & 6 deletions infra/app/web.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ var azureBlobStorageInfoUpdated = useKeyVault
// Database-specific settings
var databaseSettings = databaseType == 'CosmosDB'
? {
DATABASE_TYPE: 'CosmosDB'
AZURE_COSMOSDB_ACCOUNT_KEY: (useKeyVault || cosmosDBKeyName == '')
? cosmosDBKeyName
: listKeys(
Expand All @@ -83,10 +82,7 @@ var databaseSettings = databaseType == 'CosmosDB'
'2022-08-15'
).primaryMasterKey
}
: {
DATABASE_TYPE: 'PostgreSQL'
AZURE_POSTGRESQL_INFO: useKeyVault ? postgresInfoName : ''
}
: {}

module web '../core/host/appservice.bicep' = {
name: '${name}-app-module'
Expand Down Expand Up @@ -224,7 +220,7 @@ resource cosmosRoleDefinition 'Microsoft.DocumentDB/databaseAccounts/sqlRoleDefi
name: '${json(appSettings.AZURE_COSMOSDB_INFO).accountName}/00000000-0000-0000-0000-000000000002'
}

module cosmosUserRole '../core/database/cosmos-sql-role-assign.bicep' = if(databaseType == 'CosmosDB') {
module cosmosUserRole '../core/database/cosmos-sql-role-assign.bicep' = if (databaseType == 'CosmosDB') {
name: 'cosmos-sql-user-role-${web.name}'
params: {
accountName: json(appSettings.AZURE_COSMOSDB_INFO).accountName
Expand Down
32 changes: 17 additions & 15 deletions infra/core/database/postgresdb.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ resource serverName_resource 'Microsoft.DBforPostgreSQL/flexibleServers@2023-12-
}
}

// resource delayScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
// name: 'waitForServerReady'
// location: resourceGroup().location
// kind: 'AzurePowerShell'
// properties: {
// azPowerShellVersion: '3.0'
// scriptContent: 'start-sleep -Seconds 300'
// cleanupPreference: 'Always'
// retentionInterval: 'PT1H'
// }
// dependsOn: [
// serverName_resource
// ]
// }
resource delayScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: 'waitForServerReady'
location: resourceGroup().location
kind: 'AzurePowerShell'
properties: {
azPowerShellVersion: '3.0'
scriptContent: 'start-sleep -Seconds 300'
cleanupPreference: 'Always'
retentionInterval: 'PT1H'
}
dependsOn: [
serverName_resource
]
}

resource configurations 'Microsoft.DBforPostgreSQL/flexibleServers/configurations@2023-12-01-preview' = {
name: 'azure.extensions'
Expand All @@ -81,6 +81,9 @@ resource configurations 'Microsoft.DBforPostgreSQL/flexibleServers/configuration
value: 'vector'
source: 'user-override'
}
dependsOn: [
delayScript
]
}

resource azureADAdministrator 'Microsoft.DBforPostgreSQL/flexibleServers/administrators@2022-12-01' = {
Expand All @@ -105,7 +108,6 @@ resource azureADAdministrator 'Microsoft.DBforPostgreSQL/flexibleServers/adminis
// }
// }]


resource firewall_all 'Microsoft.DBforPostgreSQL/flexibleServers/firewallRules@2023-12-01-preview' = if (allowAllIPsFirewall) {
parent: serverName_resource
name: 'allow-all-IPs'
Expand Down
85 changes: 45 additions & 40 deletions infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ module postgresDBModule './core/database/postgresdb.bicep' = if (databaseType ==
solutionLocation: 'eastus2'
managedIdentityObjectId: managedIdentityModule.outputs.managedIdentityOutput.objectId
managedIdentityObjectName: managedIdentityModule.outputs.managedIdentityOutput.name
allowAzureIPsFirewall: true
}
scope: rg
}
Expand Down Expand Up @@ -676,9 +677,7 @@ module web './app/web.bicep' = if (hostingModel == 'code') {
ORCHESTRATION_STRATEGY: orchestrationStrategy
CONVERSATION_FLOW: conversationFlow
LOGLEVEL: logLevel

// Add database type to settings
AZURE_DATABASE_TYPE: databaseType
DATABASE_TYPE: databaseType
},
// Conditionally add database-specific settings
databaseType == 'CosmosDB'
Expand All @@ -688,11 +687,11 @@ module web './app/web.bicep' = if (hostingModel == 'code') {
}
: databaseType == 'PostgreSQL'
? {
AZURE_POSTGRESDB_INFO: string({
AZURE_POSTGRESQL_INFO: string({
host: postgresDBModule.outputs.postgresDbOutput.postgreSQLServerName
dbname: postgresDBModule.outputs.postgresDbOutput.postgreSQLDatabaseName
user: websiteName
})
})
}
: {}
)
Expand Down Expand Up @@ -783,9 +782,7 @@ module web_docker './app/web.bicep' = if (hostingModel == 'container') {
ORCHESTRATION_STRATEGY: orchestrationStrategy
CONVERSATION_FLOW: conversationFlow
LOGLEVEL: logLevel

// Add database type to settings
AZURE_DATABASE_TYPE: databaseType
DATABASE_TYPE: databaseType
},
// Conditionally add database-specific settings
databaseType == 'CosmosDB'
Expand All @@ -795,7 +792,7 @@ module web_docker './app/web.bicep' = if (hostingModel == 'container') {
}
: databaseType == 'PostgreSQL'
? {
AZURE_POSTGRESDB_INFO: string({
AZURE_POSTGRESQL_INFO: string({
host: postgresDBModule.outputs.postgresDbOutput.postgreSQLServerName
dbname: postgresDBModule.outputs.postgresDbOutput.postgreSQLDatabaseName
user: '${websiteName}-docker'
Expand Down Expand Up @@ -877,13 +874,14 @@ module adminweb './app/adminweb.bicep' = if (hostingModel == 'code') {
FUNCTION_KEY: clientKey
ORCHESTRATION_STRATEGY: orchestrationStrategy
LOGLEVEL: logLevel
AZURE_POSTGRESDB_INFO: databaseType == 'PostgreSQL'
? string({
host: postgresDBModule.outputs.postgresDbOutput.postgreSQLServerName
dbname: postgresDBModule.outputs.postgresDbOutput.postgreSQLDatabaseName
user: adminWebsiteName
})
: {}
DATABASE_TYPE: databaseType
AZURE_POSTGRESQL_INFO: databaseType == 'PostgreSQL'
? string({
host: postgresDBModule.outputs.postgresDbOutput.postgreSQLServerName
dbname: postgresDBModule.outputs.postgresDbOutput.postgreSQLDatabaseName
user: adminWebsiteName
})
: {}
}
}
}
Expand Down Expand Up @@ -958,13 +956,14 @@ module adminweb_docker './app/adminweb.bicep' = if (hostingModel == 'container')
FUNCTION_KEY: clientKey
ORCHESTRATION_STRATEGY: orchestrationStrategy
LOGLEVEL: logLevel
AZURE_POSTGRESDB_INFO: databaseType == 'PostgreSQL'
? string({
host: postgresDBModule.outputs.postgresDbOutput.postgreSQLServerName
dbname: postgresDBModule.outputs.postgresDbOutput.postgreSQLDatabaseName
user: '${adminWebsiteName}-docker'
})
: {}
DATABASE_TYPE: databaseType
AZURE_POSTGRESQL_INFO: databaseType == 'PostgreSQL'
? string({
host: postgresDBModule.outputs.postgresDbOutput.postgreSQLServerName
dbname: postgresDBModule.outputs.postgresDbOutput.postgreSQLDatabaseName
user: '${adminWebsiteName}-docker'
})
: {}
}
}
}
Expand Down Expand Up @@ -1061,13 +1060,14 @@ module function './app/function.bicep' = if (hostingModel == 'code') {
LOGLEVEL: logLevel
AZURE_OPENAI_SYSTEM_MESSAGE: azureOpenAISystemMessage
AZURE_SEARCH_TOP_K: azureSearchTopK
AZURE_POSTGRESDB_INFO: databaseType == 'PostgreSQL'
? string({
host: postgresDBModule.outputs.postgresDbOutput.postgreSQLServerName
dbname: postgresDBModule.outputs.postgresDbOutput.postgreSQLDatabaseName
user: functionName
})
: {}
DATABASE_TYPE: databaseType
AZURE_POSTGRESQL_INFO: databaseType == 'PostgreSQL'
? string({
host: postgresDBModule.outputs.postgresDbOutput.postgreSQLServerName
dbname: postgresDBModule.outputs.postgresDbOutput.postgreSQLDatabaseName
user: functionName
})
: {}
}
}
}
Expand Down Expand Up @@ -1129,13 +1129,14 @@ module function_docker './app/function.bicep' = if (hostingModel == 'container')
LOGLEVEL: logLevel
AZURE_OPENAI_SYSTEM_MESSAGE: azureOpenAISystemMessage
AZURE_SEARCH_TOP_K: azureSearchTopK
AZURE_POSTGRESDB_INFO: databaseType == 'PostgreSQL'
? string({
host: postgresDBModule.outputs.postgresDbOutput.postgreSQLServerName
dbname: postgresDBModule.outputs.postgresDbOutput.postgreSQLDatabaseName
user: '${functionName}-docker'
})
: {}
DATABASE_TYPE: databaseType
AZURE_POSTGRESQL_INFO: databaseType == 'PostgreSQL'
? string({
host: postgresDBModule.outputs.postgresDbOutput.postgreSQLServerName
dbname: postgresDBModule.outputs.postgresDbOutput.postgreSQLDatabaseName
user: '${functionName}-docker'
})
: {}
}
}
}
Expand Down Expand Up @@ -1292,8 +1293,12 @@ module createIndex './core/database/deploy_create_table_script.bicep' = if (data
keyVaultName: keyvault.outputs.name
postgresSqlServerName: postgresDBModule.outputs.postgresDbOutput.postgresSQLName
webAppPrincipalName: hostingModel == 'code' ? web.outputs.FRONTEND_API_NAME : web_docker.outputs.FRONTEND_API_NAME
adminAppPrincipalName: hostingModel == 'code' ? adminweb.outputs.WEBSITE_ADMIN_NAME : adminweb_docker.outputs.WEBSITE_ADMIN_NAME
functionAppPrincipalName: hostingModel == 'code' ? function.outputs.functionName : function_docker.outputs.functionName
adminAppPrincipalName: hostingModel == 'code'
? adminweb.outputs.WEBSITE_ADMIN_NAME
: adminweb_docker.outputs.WEBSITE_ADMIN_NAME
functionAppPrincipalName: hostingModel == 'code'
? function.outputs.functionName
: function_docker.outputs.functionName
managedIdentityName: managedIdentityModule.outputs.managedIdentityOutput.name
}
scope: rg
Expand Down Expand Up @@ -1370,4 +1375,4 @@ output AZURE_ML_WORKSPACE_NAME string = orchestrationStrategy == 'prompt_flow'
: ''
output RESOURCE_TOKEN string = resourceToken
output AZURE_COSMOSDB_INFO string = azureCosmosDBInfo
output AZURE_POSTGRESDB_INFO string = azurePostgresDBInfo
output AZURE_POSTGRESQL_INFO string = azurePostgresDBInfo
Loading
Loading