bicep icon indicating copy to clipboard operation
bicep copied to clipboard

Azure Container Apps fails with union(array,array) on environment variables

Open bradygaster opened this issue 4 years ago • 7 comments

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.

bradygaster avatar Sep 14 '22 17:09 bradygaster

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 avatar Sep 15 '22 16:09 alex-frankel

@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
    }
  }
}

glloyd2010f avatar Sep 19 '22 13:09 glloyd2010f

I can confirm @glloyd2010f is accurate. This is specific to ACA's RP.

bradygaster avatar Oct 10 '22 15:10 bradygaster

Do we know who to follow up with on this?

jongio avatar Oct 10 '22 18:10 jongio

I'd start with @anthonychu / @ruslany

alex-frankel avatar Oct 10 '22 18:10 alex-frankel

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.

ruslany avatar Nov 08 '22 23:11 ruslany

Great - thanks @ruslany. Going to close this and track with https://github.com/microsoft/azure-container-apps/issues/391

alex-frankel avatar Nov 09 '22 00:11 alex-frankel