Azure / Azure/bicep-types-az

[Microsoft.App/managedEnvironments] Deployment of Container Apps Managed Environment fails when the 'appLogsConfiguration' property uses conditions

Open
#1,407 12 comments 3 reactions 0 assignees View on GitHub
ContainerApp inaccuracy Service Attention
Dominant language
TypeScript
Stars
108
Forks
44
Avg merge
18h 53m
Merged PRs (30d)
29

Description

**Bicep version**
Bicep CLI version 0.14.85 (f4a4d485ba)

**Describe the bug**
Trying to develop a module that deploys an [Azure Container Apps Managed Environment](https://learn.microsoft.com/en-us/azure/templates/microsoft.app/2022-10-01/managedenvironments?pivots=deployment-language-bicep). One of the properties of this service is to specify the [appLogsConfiguration](https://learn.microsoft.com/en-us/azure/templates/microsoft.app/2022-10-01/managedenvironments?pivots=deployment-language-bicep#applogsconfiguration).

In this property, we can specify the 'destination' type. Although the documentation does not call out the supported types, using the Azure Portal, we determined there are three options that can be supported: ['', 'log-analytics', 'azure-monitor'].

![image](https://user-images.githubusercontent.com/28486158/222634933-244ef419-644f-4c68-811c-5ab853ae658a.png)

Based on that we wanted to apply these options in the module. The below shows the bicep code:

```bicep

@description('Required. Name of the Container Apps Managed Environment.')
param name string

@description('Optional. Location for all Resources.')
param location string = resourceGroup().location

@description('Conditional. Existing Log Analytics Workspace resource ID. Required if "logDestination" is set to "log-analytics".')
param logAnalyticsWorkspaceResourceId string = ''

@allowed([
'azure-monitor'
'log-analytics'
''
])
@description('Optional. Logs destination. Default value streams logs without storing them.')
param logsDestination string = ''

resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' existing = if (!empty(logAnalyticsWorkspaceResourceId)) {
name: last(split(logAnalyticsWorkspaceResourceId, '/'))!
scope: resourceGroup(split(logAnalyticsWorkspaceResourceId, '/')[2], split(logAnalyticsWorkspaceResourceId, '/')[4])
}

resource managedEnvironment 'Microsoft.App/managedEnvironments@2022-10-01' = {
name: name
location: location
properties: {
appLogsConfiguration: !empty(logsDestination) ? {
destination: logsDestination
logAnalyticsConfiguration: logsDestination == 'log-analytics' ? {
customerId: logAnalyticsWorkspace.properties.customerId
sharedKey: logAnalyticsWorkspace.listKeys().primarySharedKey
} : null
} : {}
}
}
```

In this template, we wrote a condition for the `logAnalyticsConfiguration` so that it is only used when the `logAnalyticsWorkspaceResourceId` is provided, but set to `null` if not.

When deploying this template with the following spec:
- logsDestination = '' --> Success
- logsDestination = 'azure-monitor' --> Success
- logsDestination = 'log-analytics' --> Fail and we get the below error:

```pwsh
Deployed failed with provisioning state [Failed]. Error Message: [The template deployment 'cinjzsv67eycm-test-amecom' is not valid according to the validation procedure. The tracking id is '352dfe6d-77bd-4248-9b96-fe5553ba4700'. See inner errors for details. (Code: InvalidTemplateDeployment) - Validation failed for a resource. Check 'Error.Details[0]' for more information. (Code: ValidationForResourceFailed)
- Invalid request body for environment. Path: $.appLogsConfiguration. Does not conform to Managed Environment schema, please visit for more information https://docs.microsoft.com/azure/container-apps/azure-resource-manager-api-spec?tabs=arm-template#container-apps-environment (Code:ManagedEnvironmentInvalidSchema)

]. Please review the Azure logs of deployment [a-me-common-t1-20230303T1503488392Z] in scope [subscription] for further details.
```

What we noticed, is that conditions just don't work when they are near this property, so the only way we got this template to work is by only supporting one logDestination and that is `log-analytics`, like the below:

```bicep

resource managedEnvironment 'Microsoft.App/managedEnvironments@2022-10-01' = {
name: name
location: location
properties: {
appLogsConfiguration: {
destination: 'log-analytics'
logAnalyticsConfiguration: {
customerId: logAnalyticsWorkspace.properties.customerId
sharedKey: logAnalyticsWorkspace.listKeys().primarySharedKey
}
}
}
}
```

**To Reproduce**

Deploy the first template referenced in this issue, and set the `logDestination` to `log-analytics` and provide the `logAnalyticsWorkspaceResourceId`.

**Additional context**

We realize this may not be an issue related to bicep, but we thought of raising it here as a start and get guidance on the error related to the schema

" Invalid request body for environment. Path: $.appLogsConfiguration. Does not conform to Managed Environment schema"

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the first Bicep template in the report and reproduce the failure with logsDestination set to 'log-analytics' and a workspace resource ID. Compare that request with the 2022-10-01 Microsoft.App/managedEnvironments schema and determine whether the conditional appLogsConfiguration shape is represented correctly or rejected by Azure. Done means the reported conditional cases have a confirmed fix or a documented upstream limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.