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

Subnet Delegation without name property Results in InvalidRequestFormat Error #2366

Open
ipetko96 opened this issue Nov 19, 2024 · 3 comments

Comments

@ipetko96
Copy link

Bicep version
Bicep CLI version 0.31.92 (b06509316a)

Describe the bug
When deploying subnets in a loop using an array, I want to enable subnet delegation for a specific subnet based on a condition. However, the deployment fails with an error indicating a null value for item.name which is definitely not true, because when I comment out the delegation part with the condition, the subnet creates without any issues.

I expect only one subnet with a name containing db should have delegation enabled.
All other subnets should be deployed without delegation.

To Reproduce
Steps to reproduce the behavior:

  1. Define an array of subnet configurations like this: [{"name":"xxx","prefix":"10.0.0.0/28"},{...},...]
  2. Add a condition to enable delegation for subnets whose name contains 'db':
resource subnet 'Microsoft.Network/virtualNetworks/subnets@2024-03-01' = [
  for item in subnets: {
    parent: vnet
    name: '${item.name}-subnet'
    properties: {
      addressPrefixes: [
        item.prefix
      ]
      networkSecurityGroup: {
        id: resourceId('Microsoft.Network/networkSecurityGroups', '${item.name}-nsg')
      }
      delegations: (contains(item.name, 'db')
        ? [
            {
              properties: {
                serviceName: 'Microsoft.DBforMySQL/flexibleServers'
              }
            }
          ]
        : [])
      privateEndpointNetworkPolicies: 'Enabled'
      privateLinkServiceNetworkPolicies: 'Enabled'
    }
  }
]
  1. Deploy the template using the condition above.

The deployment fails with the error:

{"code":"InvalidRequestFormat","message":"System.ArgumentException: item.Name is null"}

The Azure Portal also displays the error:

{"code":"InvalidRequestFormat","message":"Cannot parse the request."}
@jeskew
Copy link
Contributor

jeskew commented Nov 20, 2024

@ipetko96 Does the name property on the delegation need to be set? E.g.,

resource subnet 'Microsoft.Network/virtualNetworks/subnets@2024-03-01' = [
  for item in subnets: {
      ...
      delegations: (contains(item.name, 'db')
        ? [
            {
              name: 'some_name' // <--
              properties: {
                serviceName: 'Microsoft.DBforMySQL/flexibleServers'
              }
            }
          ]
        : [])
      ...
  }
]

It's not marked as required in the docs, but the error message you're seeing indicates that it might be. If that doesn't solve the issue, there is likely something else in the template that expects a name property where one isn't set.

@ipetko96
Copy link
Author

I can confirm that the issue was resolved after I set the name property in the delegation object. Thank you for your assistance. It would be great if the Bicep linter could indicate that this is a required parameter.

@jeskew jeskew transferred this issue from Azure/bicep Nov 22, 2024
@jeskew jeskew changed the title Condition-Based Subnet Delegation Results in InvalidRequestFormat Error Subnet Delegation without name property Results in InvalidRequestFormat Error Nov 22, 2024
@jeskew
Copy link
Contributor

jeskew commented Nov 22, 2024

Whether a property is required or optional is determined by the resource provider's service model. Transferring this issue to the bicep-types-az repo so we can ask the service team to update this upstream of Bicep.

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

No branches or pull requests

3 participants