Azure Container Apps fails with union(array,array) on environment variables
When setting up an Azure Container App with custom environment variables, the array must be either a static array or a parameter. One cannot use union(array1, array2) to set the env property on an Azure Container App template item.
For example, I had set up an inheritance scenario in which my leaderboard.bicep contains this:
param name string
param location string
param image string
var containerAppName = 'leaderboard'
module containerApp 'containerapp.bicep' = {
name: 'containerapp-${containerAppName}'
params: {
name: name
location: location
containerAppName: containerAppName
image: image
ingress: true
vars: [
{
name: 'some_private_var'
value: 'this value'
}
]
}
}
And in containerapp.bicep I'd have this:
param vars array = []
var sharedVars = [
{
name: 'ASPNETCORE_ENVIRONMENT'
value: 'Development'
}
{
name: 'AzureStorageConnectionString'
value: 'DefaultEndpointsProtocol=https;AccountName=${storage.name};AccountKey=${storage.listKeys().keys[0].value};EndpointSuffix=${environment().suffixes.storage}'
}
{
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
value: ai.properties.ConnectionString
}
{
name: 'APPLICATIONINSIGHTS_INSTRUMENTATIONKEY'
value: ai.properties.InstrumentationKey
}
{
name: 'ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS'
value: 'true'
}
]
Then later in the container app section, use union to bring these two together as one array:
template: {
containers: [
{
image: image
name: containerAppName
env: union(vars, sharedVars)
}
]
scale: {
minReplicas: 1
maxReplicas: 1
}
}
Using union would always cause deployment exceptions to occur. As such, I had to create far-more verbose bicep files for the individual container apps than I would've preferred.
Using union would always cause deployment exceptions to occur.
What are the deployment exceptions? Is this an issue with Bicep/ARM Template deployments or with the ACA RP?
@alex-frankel I would say this is more related to the ACA RP. I use this method with Azure App Services for the App Settings and it works fine.
App Service Reference
param customAppSettings array = []
param serviceType string
var appSettings = {
default: []
api: []
web: []
function: []
container: []
}
resource appSvc 'Microsoft.Web/sites@2022-03-01' = {
name: resourceName
location: location
tags: tags
kind: appServiceConfig.kind[serviceType]
identity: {
type: 'SystemAssigned'
}
properties: {
serverFarmId: azureConfig.resourceIDs.appServicePlan
clientAffinityEnabled: appServiceConfig.clientAffinityEnabled
reserved: appServiceConfig.reserved
httpsOnly: appServiceConfig.httpsOnly
siteConfig: {
appSettings: union(appSettings.default, appSettings[serviceType], customAppSettings)
netFrameworkVersion: appServiceConfig.netFrameworkVersion
linuxFxVersion: appServiceConfig.linuxFxVersion
phpVersion: appServiceConfig.phpVersion
use32BitWorkerProcess: appServiceConfig.processAs32bit
alwaysOn: appServiceConfig.alwaysOn
defaultDocuments: appServiceConfig.defaultDocuments
minTlsVersion: appServiceConfig.minTlsVersion
ftpsState: appServiceConfig.ftpsState
}
}
}
I can confirm @glloyd2010f is accurate. This is specific to ACA's RP.
Do we know who to follow up with on this?
I'd start with @anthonychu / @ruslany
This looks to be similar to this issue: https://github.com/microsoft/azure-container-apps/issues/391. The fix will be rolled out into prod most likely within a month.
Great - thanks @ruslany. Going to close this and track with https://github.com/microsoft/azure-container-apps/issues/391