Azure / bicep

Bicep is a declarative language for describing and deploying Azure resources
MIT License
3.22k stars 746 forks source link

Bicep and Azure Firewall Management IP Configuration #7830

Open tw3lveparsecs opened 2 years ago

tw3lveparsecs commented 2 years ago

Bicep version Bicep CLI version 0.9.1

Describe the bug When using Bicep to deploy Azure firewall using a variable with a condition on the managementIpConfiguration property it fails with error The template variable 'variableName' is not found.

To Reproduce

  1. Create variable with condition
    var firwallMgmtConfig = (deployMgmtConfig) ? {
    name: publicIpFirewallMgmt.name
    properties: {
    subnet: {
      id: mgmtSubnetResourceId
    }
    publicIPAddress: {
      id: publicIpFirewallMgmt.id
    }
    }
    } : null
  2. Set variable on managementIpConfiguration property.
    resource firewall 'Microsoft.Network/azureFirewalls@2022-01-01' = {
    name: name
    location: location
    tags: tags
    properties: {
    sku: {
      name: sku
      tier: tier
    }
    ipConfigurations: [
      {
        name: publicIpFirewall.name
        properties: {
          subnet: {
            id: subnetResourceId
          }
          publicIPAddress: {
            id: publicIpFirewall.id
          }
        }
      }
    ]
    managementIpConfiguration: firwallMgmtConfig
    }
    }

    Additional context When moving the code from the variable directly to the property it works correctly.

    resource firewall 'Microsoft.Network/azureFirewalls@2022-01-01' = {
    name: name
    location: location
    tags: tags
    properties: {
    sku: {
      name: sku
      tier: tier
    }
    ipConfigurations: [
      {
        name: publicIpFirewall.name
        properties: {
          subnet: {
            id: subnetResourceId
          }
          publicIPAddress: {
            id: publicIpFirewall.id
          }
        }
      }
    ]
    managementIpConfiguration: (deployMgmtConfig) ? {
      name: publicIpFirewallMgmt.name
      properties: {
        subnet: {
          id: mgmtSubnetResourceId
        }
        publicIPAddress: {
          id: publicIpFirewallMgmt.id
        }
      }
    } : null
    firewallPolicy: {
      id: firewallPolicy.id
    }
    }
    }
anthony-c-martin commented 2 years ago

Here's a short repro - looks like the engine treats a null variable the same as a variable not being defined:

param timeNow string = utcNow()

var foo = (timeNow == 'blah') ? {
  abc: 'def'
} : null

output foo object = {
  bar: foo
}
brwilkinson commented 2 years ago

Thanks @anthony-c-martin I will remove myself, leave triage on, given you have the repro.

stephaniezyen commented 5 months ago

Can you try using nullable parameters? Here is the issue with more information on nullable parameters/variables: #6418