Service Bus authorization rules inconsistent creation using bicep

Dimitar Grozev 60 Reputation points
2024-06-27T14:35:33.1+00:00

Hey,

I am deploying a Service Bus namespace, a queue and an authorization rule for the namespace using bicep. I get the following error every time I initially run it:

[{"code":"ParentResourceNotFound","message":"Failed to perform 'action' on resource(s) of type 'namespaces/authorizationrules', because the parent resource '/subscriptions/<guid>/resourceGroups/<rg-name>/providers/Microsoft.ServiceBus/namespaces/<namespace-name>' could not be found."}]}

Here is the bicep used to deploy the namespace, queue and authorization rule:

resource serviceBusNamespace 'Microsoft.ServiceBus/namespaces@2022-10-01-preview' = {

  name: serviceBusNamespaceName

  location: location

  sku: {

    name: 'Basic'

  }

  tags: tags

  properties: {

    publicNetworkAccess: 'Enabled'

    minimumTlsVersion: '1.2'

    disableLocalAuth: false

    zoneRedundant: false

  }

}

resource serviceBusQueue 'Microsoft.ServiceBus/namespaces/queues@2022-01-01-preview' = {

  parent: serviceBusNamespace

  name: serviceBusQueueName

  properties: {

    maxSizeInMegabytes: 1024

    maxMessageSizeInKilobytes: 256

    lockDuration: 'PT1M'

    requiresDuplicateDetection: false

    requiresSession: false

    defaultMessageTimeToLive: 'P14D'

    deadLetteringOnMessageExpiration: false

    duplicateDetectionHistoryTimeWindow: 'PT10M'

    maxDeliveryCount: 10

    enablePartitioning: false

    enableExpress: false

    status: 'Active'

    enableBatchedOperations: true

  }

}

resource serviceBusAccessPolicy 'Microsoft.ServiceBus/namespaces/AuthorizationRules@2022-10-01-preview' = {

#disable-next-line no-unnecessary-dependson

  dependsOn: [serviceBusNamespace]

  name: 'listenSendPolicy'

  parent: serviceBusNamespace

  properties: {

    rights: [

      'Listen'

      'Send'

    ]

  }

}

I explicitly added the seviceBusNamespace dependency and the #disable-next-line no-unnecessary-dependson to try and avoid the missing namespace issue.

The second time I run this, however it deploys successfully. Any ideas what I am missing ?
Thanks in advance!

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
575 questions
0 comments No comments
{count} votes