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

lambda map - null values turning into empty string? #8843

Closed
coolhome opened this issue Oct 31, 2022 · 1 comment
Closed

lambda map - null values turning into empty string? #8843

coolhome opened this issue Oct 31, 2022 · 1 comment

Comments

@coolhome
Copy link

coolhome commented Oct 31, 2022

Bicep version
az bicep version
Bicep CLI version 0.11.1 (030248d)

Describe the bug
Mapping subnets from existing virtualNetwork and unable to make properties null?

To Reproduce
Steps to reproduce the behavior:

targetScope = 'resourceGroup'

param virtualNetworkName string

resource vnet 'Microsoft.Network/virtualNetworks@2022-05-01' existing = {
  name: virtualNetworkName
}

output subnets array = map(vnet.properties.subnets, subnet => {
  name: subnet.name
  addressPrefix: subnet.properties.addressPrefix
  applicationGatewayIpConfigurations: contains(subnet.properties, 'applicationGatewayIpConfigurations') ? subnet.properties.applicationGatewayIpConfigurations : []
  delegations: contains(subnet.properties, 'delegations') ? subnet.properties.delegations : []
  ipAllocations: contains(subnet.properties, 'ipAllocations') ? subnet.properties.ipAllocations : []
  natGatewayId: contains(subnet.properties, 'natGateway') ? subnet.properties.natGateway.id : null
  networkSecurityGroupId: contains(subnet.properties, 'networkSecurityGroup') ? subnet.properties.networkSecurityGroup.id : null
  privateEndpointNetworkPolicies: contains(subnet.properties, 'privateEndpointNetworkPolicies') ? subnet.properties.privateEndpointNetworkPolicies : null
  privateLinkServiceNetworkPolicies: contains(subnet.properties, 'privateLinkServiceNetworkPolicies') ? subnet.properties.privateLinkServiceNetworkPolicies : null
  routeTableId: contains(subnet.properties, 'routeTable') && contains(subnet.properties.routeTable, 'id') && !empty(subnet.properties.routeTable.id) ? subnet.properties.routeTable.id : null
  serviceEndpoints: contains(subnet.properties, 'serviceEndpoints') ? subnet.properties.serviceEndpoints : []
  serviceEndpointPolicies: contains(subnet.properties, 'serviceEndpointPolicies') ? subnet.properties.serviceEndpointPolicies : []
})

output subnetsRaw array = vnet.properties.subnets

image

Why is routeTableId an empty string if it does not exist in subnetsRaw? I imagine the following line would of worked to remove non existing resources?

  routeTableId: contains(subnet.properties, 'routeTable') && contains(subnet.properties.routeTable, 'id') && !empty(subnet.properties.routeTable.id) ? subnet.properties.routeTable.id : null

Example here shows this should work - https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-functions-object#example-1

@coolhome coolhome changed the title lambda map - lambda map - null values turning into empty string? Oct 31, 2022
@alex-frankel
Copy link
Collaborator

Closing and tracking with #8782

@ghost ghost locked as resolved and limited conversation to collaborators May 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants