Bug: App/Managent-Environment - Potentiall issue in pre-flight validation (invalid schema)
- Dominant language
- TypeScript
- Stars
- 108
- Forks
- 44
- Avg merge
- 18h 53m
- Merged PRs (30d)
- 29
Description
**Bicep version**
`0.34.44.8038`
**Describe the bug**
There may be an issue with the JSON validation of the `Microsoft.App/managedEnvironments` resource provider.
I recently worked on a PR to rework some parameters of the corresponding AVM module and also introduced a UDT along the way.
However, if I want to provide a specific property (see below) through some logic (e.g., fetching the key for the user), I get the error message:
`Invalid request body for environment. Path: $. 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)`
The property I'm referring to is `appLogsConfiguration` that looks in the schema as follows:
```bicep
appLogsConfiguration: {
destination: string // Can be 'log-analytics' or 'azure-monitor'
logAnalyticsConfiguration: { // Needed if `destination` is 'log-analytics'
customerId: string
sharedKey: string
}
}
```
Which works like a charm if you provide they values exactly like this as input parameters.
Now, in the PR I changed the same to
```bicep
param appLogsConfiguration appLogsConfigurationType?
(...)
appLogsConfiguration: !empty(appLogsConfiguration)
? {
destination: appLogsConfiguration!.destination
...(!empty(appLogsConfiguration.?logAnalyticsWorkspaceResourceId)
? {
logAnalyticsConfiguration: {
customerId: logAnalyticsWorkspace.properties.customerId
sharedKey: logAnalyticsWorkspace.listKeys().primarySharedKey
}
}
: {})
}
: null
```
which in theory should mean
- If I provide no `appLogsConfiguration` the template evaluates to
```bicep
param appLogsConfiguration appLogsConfigurationType?
(...)
appLogsConfiguration: null
```
which works in the my tests ✅
- If I provide a `destination`, and set it to 'log-analytics' and also provide `logAnalyticsWorkspaceResourceId` it should evaluate to
```bicep
param appLogsConfiguration appLogsConfigurationType?
(...)
appLogsConfiguration: {
destination: appLogsConfiguration.destination
logAnalyticsConfiguration: {
customerId: logAnalyticsWorkspace.properties.customerId
sharedKey: logAnalyticsWorkspace.listKeys().primarySharedKey
}
}
```
Which is exactly what I want. The problem, the 2nd test fails with the aforementioned error message
`Invalid request body for environment. Path: $. 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)`
I did run the above snippets in isolation to validate that, what I pass to the RP, is what I expect using this snippet:
Expand to see snippet
```bicep
@description('Optional. The AppLogsConfiguration for the Managed Environment.')
param appLogsConfiguration appLogsConfigurationType?
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2023-09-01' existing = if (!empty(appLogsConfiguration.?logAnalyticsWorkspaceResourceId)) {
name: last(split(appLogsConfiguration.?logAnalyticsWorkspaceResourceId!, '/'))!
scope: resourceGroup(
split(appLogsConfiguration.?logAnalyticsWorkspaceResourceId!, '/')[2],
split(appLogsConfiguration.?logAnalyticsWorkspaceResourceId!, '/')[4]
)
}
var appLogsConfigurationVar = !empty(appLogsConfiguration)
? {
destination: appLogsConfiguration!.destination
...(!empty(appLogsConfiguration.?logAnalyticsWorkspaceResourceId)
? {
logAnalyticsConfiguration: {
customerId: logAnalyticsWorkspace.properties.customerId
sharedKey: logAnalyticsWorkspace.listKeys().primarySharedKey
}
}
: {})
}
: null
output appLogsConfigurationObj object = appLogsConfigurationVar ?? {}
@export()
@discriminator('destination')
@description('The type for the App Logs Configuration.')
type appLogsConfigurationType = appLogsConfigurationMonitorType | appLogsConfigurationLawType
@description('The type for the App Logs Configuration if using azure-monitor.')
type appLogsConfigurationMonitorType = {
@description('Required. The destination of the logs.')
destination: 'azure-monitor'
}
@description('The type for the App Logs Configuration if using log-analytics.')
type appLogsConfigurationLawType = {
@description('Required. The destination of the logs.')
destination: 'log-analytics'
@description('Required. Existing Log Analytics Workspace resource ID.')
logAnalyticsWorkspaceResourceId: string
}
```
Expand to see invocation and result
```pwsh
$o = New-AzDeployment -TemplateFile 'C:\appConfigTest.bicep' -appLogsConfiguration @{ destination = 'log-analytics'; logAnalyticsWorkspaceResourceId = '' } -Location 'WestEurope'
$o.outputs.appLogsConfigurationObj | Convertto-json
# {
# "Type": "Object",
# "Value": {
# "destination": "log-analytics",
# "logAnalyticsConfiguration": {
# "customerId": "11-11-11-11-11",
# "sharedKey": "abcdefg=="
# }
# }
# }
```
Given the error message I can't help but assume that something on the RP side went wrong when interpreting the code. If that's the case, we should forward this to the team to make sure they change whatever needs changing.
**To Reproduce**
Simply try and deploy either the `max` or `waf-aligned` AVM test case of this AVM PR's branch: https://github.com/Azure/bicep-registry-modules/pull/5067
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by deploying the max or waf-aligned AVM test case from PR #5067 and inspect the resulting ManagedEnvironmentInvalidSchema error. Compare the appLogsConfiguration input and evaluated output shown in the issue with the managedEnvironments schema; done means identifying whether the invalid payload is produced by the template or rejected incorrectly by the Microsoft.App resource provider.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100