Skip to content

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

Open

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

    param applicationGateways_agw_aks_test_scus_001_name string = 'agw-sample-dev-scus-001'
    param virtualNetworks_vnet_dev_scus_001_externalid string = '/subscriptions/<SUB_ID>/resourceGroups/<RESOURCE_NAME>/providers/Microsoft.Network/virtualNetworks/<VNET_NAME>'
    param publicIPAddresses_pip_mw_dev_scus_001_externalid string = '/subscriptions/<SUB_ID>/resourceGroups/<RESOURCE_NAME>/providers/Microsoft.Network/publicIPAddresses/<PUBLIC_IP_NAME>'
    
    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 "<GATEWAY_NAME>" -l "<AZURE_LOCATION>" -g "<RESOURCE_GROUP>" --sku Standard_v2 --public-ip-address "<PUBLIC_IP_ADDRESS>" --vnet-name "<VNET_NAME>" --subnet "<SUBNET_NAME>"
    
  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 <FILE_NAME>.json
    
    
  5. On the BICEP file there will be an error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions