0

I am trying to create a service bus and topic (many topics and their subscriptions) with the azure bicep.

  1. I have main bicep like below

    param topics array;
    
    resource serviceBusNamespace 'Microsoft.ServiceBus/namespaces@2018-01-01-preview' = {
    name: serviceBusNamespaceName
    location: location
     sku: {
       name: skuName
     }
    }
    
    module topicSubscription './sb_topic.bicep' = [for topic in topics: {
    name: 'topicSubscription${topic}'
    params: {
    topic: topic
      }
    }]
    

module file looks like

resource sbTopics 'Microsoft.ServiceBus/namespaces/topics@2022-01-01-preview' = {
  name: topic.name
  parent: ??
  properties: topic.properties

  resource symbolicname 'subscriptions@2022-01-01-preview' =  [for subscription in topic.subscriptions: {
    name: 'string'
    properties: {}
  }]
}

How can pass the parent serviceBusNamespace resource as parent to the child resource inside the module?

Kindly suggest..

Jesse Squire
  • 6,107
  • 1
  • 27
  • 30
sub
  • 527
  • 1
  • 7
  • 24
  • Does this answer your question? [Bicep module reference as a parent in another resource](https://stackoverflow.com/questions/71486988/bicep-module-reference-as-a-parent-in-another-resource) – Thomas Sep 21 '22 at 19:55

1 Answers1

3

In the module reference the namespace with an 'existing' declaration. Something like this

param namespaceName string

resource serviceBusNamespace 'Microsoft.ServiceBus/namespaces@2018-01-01-preview' existing = {
  name: namespaceName
}

resource sbTopics 'Microsoft.ServiceBus/namespaces/topics@2022-01-01-preview' = {
  name: topic.name
  parent: serviceBusNamespace
  properties: topic.properties

  resource symbolicname 'subscriptions@2022-01-01-preview' =  [for subscription in topic.subscriptions: {
    name: 'string'
    properties: {}
  }]
}
Scott Mildenberger
  • 1,456
  • 8
  • 17