Azure / Azure/bicep

The Bicep file generated by the Bicep CLI decompile causes a BCP138 error.

Open
#18,414 0 comments 0 reactions 0 assignees View on GitHub
bug Quality Sprint
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 4h
Merged PRs (30d)
81

Description

**Bicep version**
Bicep CLI version 0.38.33

**Describe the bug**
Use Bicep CLI to decompile the following ARM JSON template:

```json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"itemCount": {
"type": "int",
"defaultValue": 5
}
},
"variables": {
"topLevelObject": {
"sampleProperty": "sampleValue",
"copy": [
{
"name": "disks",
"count": "[parameters('itemCount')]",
"input": {
"name": "[concat('myDataDisk', copyIndex('disks', 1))]",
"diskSizeGB": "1",
"diskIndex": "[copyIndex('disks')]"
}
}
]
}
},
"resources": [],
"outputs": {
"objectResult": {
"type": "object",
"value": "[variables('topLevelObject')]"
}
}
}
```
The decompile process produces the following Bicep file which causes BCP138:

```bicep
param itemCount int = 5

var topLevelObject = {
sampleProperty: 'sampleValue'
disks: [
for j in range(0, itemCount): {
name: 'myDataDisk${(j+1)}'
diskSizeGB: 1
diskIndex: j
}
]
}

output objectResult object = topLevelObject
```

The following output can avoid the error code:

```bicep
param itemCount int = 5

var disks = [
for j in range(0, itemCount): {
name: 'myDataDisk${(j+1)}'
diskSizeGB: 1
diskIndex: j
}
]

var topLevelObject = {
sampleProperty: 'sampleValue'
disks: disks
}

output objectResult object = topLevelObject
```

**To Reproduce**
See the issue description for the reproduce steps.

**Additional context**
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue by running the Bicep CLI decompile process on the ARM JSON template in the issue and inspect the generated Bicep. Compare the nested-loop output with the alternative shown, then verify that the result no longer produces BCP138 and preserves the expected object output.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cli, compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.