Azure / Azure/bicep

ARM to Bicep decompile error - The property "scope" expected a value of type "resource" but the provided value is of type "string"

Open
#10,185 1 comment 0 reactions 0 assignees View on GitHub
story: decompiler
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Bicep version**

```az bicep version
Bicep CLI version 0.15.31 (3ba6e06a8d)
```

**Describe the bug**

When attempting to decompile an ARM template for Microsoft.SecurityInsights/alertRules into a Bicep file, the conversion will present the following error:

`/tmp/Fusion_tmp.bicep(7,10) : Error BCP036: The property "scope" expected a value of type "resource" but the provided value is of type "string".`

**To Reproduce**
Steps to reproduce the behavior:

ARM file:

```json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceName": {
"type": "string"
},
"enabled": {
"type": "bool",
"defaultValue": true
}
},
"variables": {
"ruleId": "f71aba3d-28fb-450b-b192-4e76a83015c8"
},
"resources": [
{
"type": "Microsoft.SecurityInsights/alertRules",
"apiVersion": "2023-02-01-preview",
"name": "[variables('ruleId')]",
"scope": "[concat('Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'))]",
"kind": "Fusion",
"properties": {
"enabled": "[parameters('enabled')]",
"alertRuleTemplateName": "f71aba3d-28fb-450b-b192-4e76a83015c8"
}
}
]
}
```

The expected Bicep output (valid):

```bicep
param workspaceName string
param enabled bool = true

var ruleId = 'f71aba3d-28fb-450b-b192-4e76a83015c8'

resource Fusion 'Microsoft.SecurityInsights/alertRules@2022-10-01-preview' = {
scope: workspace
name: ruleId
kind: 'Fusion'
properties: {
enabled: enabled
alertRuleTemplateName: 'f71aba3d-28fb-450b-b192-4e76a83015c8'
}
}
resource workspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' existing = {
name: workspaceName
}
```

**Additional context**

I have tried setting the scope in the ARM file to the exact name of the workspace as well, but I get the same error.

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with the ARM template shown in the issue and trace the ARM-to-Bicep decompiler entry point that handles the alertRules scope expression. Done means the template decompiles to a valid Bicep resource reference for the workspace without BCP036.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.