Azure / Azure/bicep

Error decompiling ARM to BICEP | Application Gateway | Expression is referring it's own declaration

Open
#6,000 3 comments 0 reactions 0 assignees View on GitHub
story: decompiler troubleshooting
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 2h
Merged PRs (30d)
79

Description

**Bicep version**
Bicep CLI version 0.4.1272

**Describe the bug**
1. On converting the Application Gateway ARM template to BICEP using az bicep decompile the template gets converted with the error "Expression is referring its own declaration"
2. In the below piece of code for Properties.httpListeners & Properties.requestRoutingRules we need to refer to the appgateway resource that was created. Example for frontendIPConfiguration but these line errors out with above message
3. App gateway need at least httpListener defined hence not able to create app gateway using BICEP

4. Below is an sample piece of code

```bicep
param applicationGateways_agw_aks_test_scus_001_name string = 'agw-sample-dev-scus-001'
param virtualNetworks_vnet_dev_scus_001_externalid string = '/subscriptions//resourceGroups//providers/Microsoft.Network/virtualNetworks/'
param publicIPAddresses_pip_mw_dev_scus_001_externalid string = '/subscriptions//resourceGroups//providers/Microsoft.Network/publicIPAddresses/'

resource applicationGateways_agw_aks_test_scus_001_name_resource 'Microsoft.Network/applicationGateways@2020-11-01' = {
name: applicationGateways_agw_aks_test_scus_001_name
location: 'southcentralus'
properties: {
sku: {
name: 'Standard_v2'
tier: 'Standard_v2'
capacity: 2
}
httpListeners: [
{
name: 'appGatewayHttpListener'
properties: {
frontendIPConfiguration: {
id: '${applicationGateways_agw_aks_test_scus_001_name_resource.id}/frontendIPConfigurations/appGatewayFrontendIP'
}
frontendPort: {
id: '${applicationGateways_agw_aks_test_scus_001_name_resource.id}/frontendPorts/appGatewayFrontendPort'
}
protocol: 'Http'
hostNames: []
requireServerNameIndication: false
}
}
]
requestRoutingRules: [
{
name: 'rule1'
properties: {
ruleType: 'Basic'
httpListener: {
id: '${applicationGateways_agw_aks_test_scus_001_name_resource.id}/httpListeners/appGatewayHttpListener'
}
backendAddressPool: {
id: '${applicationGateways_agw_aks_test_scus_001_name_resource.id}/backendAddressPools/appGatewayBackendPool'
}
backendHttpSettings: {
id: '${applicationGateways_agw_aks_test_scus_001_name_resource.id}/backendHttpSettingsCollection/appGatewayBackendHttpSettings'
}
}
}
]
}
}

```

**To Reproduce**
1. Open the powershell terminal and run az login command and set the subscription scope
2. Execute below command to create a App Gateway resource
```
az network application-gateway create -n "" -l "" -g "" --sku Standard_v2 --public-ip-address "" --vnet-name "" --subnet ""
```
3. Once the resource is created, go to Automation -> Export and export the ARM template json
4. Convert the ARM json to BICEP using below command
```
az bicep decompile --file .json

```
5. On the BICEP file there will be an error.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue by creating an Azure Application Gateway, exporting its ARM template, and running az bicep decompile --file on the JSON. Investigate how the decompiler handles Application Gateway listener and routing-rule references to the parent resource. Done means the generated Bicep has no self-reference error and can create the Application Gateway.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.