Bicep Snapshots and union of arrays with function value
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 21m
- Merged PRs (30d)
- 79
Description
**Bicep version**
Bicep CLI version 0.37.4 (27cc8db2ed)
**Describe the bug**
When you have union of arrays and instead of showing the end value as array bicep snapshot shows the value as ARM template functions
**To Reproduce**
Example main.bicep
```bicep
param apiManagementServiceName string
@secure()
param secret string
param clientId string
param authority string
param signinTenant string = subscription().tenantId
param allowedTenants array = []
resource apiManagementService 'Microsoft.ApiManagement/service@2024-06-01-preview' existing = {
name: apiManagementServiceName
}
resource portalIdentity 'Microsoft.ApiManagement/service/identityProviders@2024-06-01-preview' = {
name: 'aad'
parent: apiManagementService
properties: {
type: 'aad'
clientLibrary: 'MSAL-2'
clientId: clientId
clientSecret: secret
authority: authority
signinTenant: signinTenant
allowedTenants: union(
[
signinTenant
],
allowedTenants
)
}
}
```
param.bicepparam
```bicepparam
using 'main.bicep'
param apiManagementServiceName = 'apim001'
param authority = 'https://login.microsoftonline.com'
param clientId = '63512587-15d3-429b-9005-fa8bd53cf85b'
param secret = 'somesecret'
```
The end result is:
```json
{
"predictedResources": [
{
"id": "[format('/subscriptions/f4b90a18-b44d-439b-a1b7-3c7fae8a8d54/resourceGroups/{0}/providers/Microsoft.ApiManagement/service/apim001/identityProviders/aad', resourceGroup().name)]",
"type": "Microsoft.ApiManagement/service/identityProviders",
"name": "apim001/aad",
"apiVersion": "2024-06-01-preview",
"properties": {
"type": "aad",
"clientLibrary": "MSAL-2",
"clientId": "63512587-15d3-429b-9005-fa8bd53cf85b",
"clientSecret": "[parameters('secret')]",
"authority": "https://login.microsoftonline.com",
"signinTenant": "[tenant().tenantId]",
"allowedTenants": "[union(createArray(tenant().tenantId), createArray())]"
}
}
],
"diagnostics": []
}
```
You can see the value of allowedTenants. We have static value and for input we have empty array. Bicep snapshot should easily be able to calculate that the end result should be ` ["[tenant().tenantId]"]`. The result is the same if you have input for allowedTenants. Even in that situation the end result can be calculated. Note that the only way the end result is displayed correctly is when the static value does not use subscription().tenantId as default value.
Also take a note that the input is subscription().tenantId function but it is displayed as tenant().tenantId in end results. Not sure if that is a bug or intended behavior.
**Additional context**
Add any other context about the problem here.
Contributor guide
Research direction
Start by reproducing the snapshot from main.bicep with param.bicepparam using Bicep CLI 0.37.4, then trace the snapshot evaluation of the allowedTenants union. Done means the snapshot emits the calculated array value for both empty and populated inputs and consistently represents subscription().tenantId.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure
- Domain
- cloud, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100