azureazure-resource-managerazure-bicepazure-container-apps

How to set the Container App alocation to have 4CPUs and 8Gb of RAM in bicep


I'm trying to set the Container App allocation to 4CPUs and 8Gb of RAM in the consumption plan.

Through the Azure portal I managed to provision a Container App with that kind of resources, but when I try this using bicep, I get this error in the deployment of a Managed Application (through a Service Catalog Managed Application Definition) "The total requested CPU and memory resources for this application (CPU: 4.0, memory: 8) is invalid. Total CPU and memory for all containers defined in a Container App must add up to one of the following CPU - Memory combinations: [cpu: 0.25, memory: 0.5Gi]; [cpu: 0.5, memory: 1.0Gi]; [cpu: 0.75, memory: 1.5Gi]; [cpu: 1.0, memory: 2.0Gi]; [cpu: 1.25, memory: 2.5Gi]; [cpu: 1.5, memory: 3.0Gi]; [cpu: 1.75, memory: 3.5Gi]; [cpu: 2.0, memory: 4.0Gi]"

I've tried to replicate what the portal has by exporting the ARM of the Container App that I provisioned using the portal, then de-compiling it to bicep and see what is missing, but with no luck so far. I've tested by adding the "workloadProfileName" and set it to 'Consumption', but the deployment fails with this error message: "Cannot specify workload profile name for container app in Consumption Only environment."

This is a section of my bicep file for the Container App

resource containerAppEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' = {
  name: containerAppEnvironmentFullName
  location: location
  properties: {
    workloadProfiles: [
      {
        name: 'Consumption'
        workloadProfileType: 'Consumption'
      }
    ]
    appLogsConfiguration: {
      destination: 'log-analytics'
      logAnalyticsConfiguration: {
        customerId: logAnalyticsWorkspace.properties.customerId
        sharedKey: logAnalyticsWorkspace.listKeys().primarySharedKey
      }
    }
  }
}

resource functionsContainerApp 'Microsoft.App/containerApps@2023-05-01' = {
  name: testContainerAppFullName
  location: location
  identity: {
    type: 'UserAssigned'
    userAssignedIdentities: {
      '${managedIdentity.id}': {}
    }
  }
  dependsOn: [
    acrImport
  ]
  properties: {
    managedEnvironmentId: containerAppEnvironment.id
    configuration: {
      activeRevisionsMode: 'Single'
      secrets: [
        {
          name: 'application-insights-secret'
          value: applicationInsights.properties.ConnectionString
        }
        {
          name: 'app-registration-secret'
          value: appRegistrationSecret
        }
      ]
      registries: [
        {
          server: containerRegistry.properties.loginServer
          username: containerRegistry.name
          passwordSecretRef: 'registry-password'
        }
      ]
    }
    template: {
      containers: [
        {
          name: 'functions-'
          image: '${containerRegistry.properties.loginServer}/${containerAppImageName}:${containerAppTag}'
          resources: {
            cpu: 4
            memory: '8Gi'
          }
          env: [
            {
              name: 'ADMIN_TENANTS'
              value: adminTenants
            }
          ]
        }
      ]
      scale: {
        minReplicas: containerAppBackendMinReplicas
        maxReplicas: containerAppBackendMaxReplicas
      }
    }
  }
}

I've provisioned through the portal a Container App with 4 CPUs and 8Gb of RAM, exported the ARM template and decompiled it to BICEP, replicated the configuration, and tried to create the Container App.


Solution

  • You're missing the workloadProfileName property in the container app resource. This is required as you can have multiple workload profiles in the same container app environment:

    resource functionsContainerApp 'Microsoft.App/containerApps@2023-05-01' = {
      name: testContainerAppFullName
      location: location
      ...
      properties: {
        ...
        workloadProfileName: 'Consumption'
        ...
      }
    }
    

    I imagine it is defaulting to Consumption Only plan when the workloadProfileName is not specified, see Azure Container Apps plan types

    I has able to reproduce your issue using this template and commenting/uncommenting the workloadProfileName in the container app resource:

    param location string = resourceGroup().location
    param containerAppEnvironmentName string = 'cae-thomastest-001'
    param containerAppName string = 'ca-thomastest-001'
    
    resource containerAppEnvironment 'Microsoft.App/managedEnvironments@2024-03-01' = {
      name: containerAppEnvironmentName
      location: location
      properties: {
        appLogsConfiguration: {
          destination: 'azure-monitor'
        }
        workloadProfiles: [
          {
            name: 'Consumption'
            workloadProfileType: 'Consumption'
          }
        ]
      }
    }
    
    resource containerApp 'Microsoft.App/containerApps@2024-03-01' = {
      name: containerAppName
      location: location
      properties: {
        environmentId: containerAppEnvironment.id
        // workloadProfileName: 'Consumption'
        configuration: {
          activeRevisionsMode: 'Single'
          ingress: {
            external: true
            targetPort: 80
          }
        }
        template: {
          containers: [
            {
              name: 'simple-hello-world-container'
              image: 'mcr.microsoft.com/k8se/quickstart:latest'
              command: []
              args: []
              resources: {
                cpu: 4
                memory: '8Gi'
              }
            }
          ]
          scale: {
            minReplicas: 0
          }
        }
      }
    }