Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
niragvt opened this issue Feb 17, 2022 · 3 comments

Comments

@niragvt
Copy link

niragvt commented Feb 17, 2022

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.
@alex-frankel
Copy link
Collaborator

Unfortunately, app gateways have a very strange resource schema that involves these circular references. This is an API design anti-pattern, so the proper fix is to redesign the service's API. Given this is not is a common API structure, we probably can't have a general fix for this. We would need to special case it.

@niragvt
Copy link
Author

niragvt commented Feb 17, 2022

Unfortunately, app gateways have a very strange resource schema that involves these circular references. This is an API design anti-pattern, so the proper fix is to redesign the service's API. Given this is not is a common API structure, we probably can't have a general fix for this. We would need to special case it.

Thanks, Alex for the response. Is there a way for me to proceed right now? Is there a working BICEP template I can use for Application Gateway?

@alex-frankel
Copy link
Collaborator

Sorry, meant to include that.

You will need to construct the resource ID yourself using the resource ID function:

        httpListener: {
            id: resourceId('microsoft.network/applicationGateways/httpListeners', applicationGateways_agw_aks_test_scus_001_name, appGatewayHttpListenerName)
        }

Just repeat that pattern for each different id property. Make sure you get the type (the first argument correct, as it will change slightly for each id property)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants