skip to Main Content

I have a bicep file where I want to create an event topic from a given resource group (let’s say resource-group-a) and I want to connect to that within a different resource group (let’s say resource-group-b).

Almost all my resources are within resource-group-b, but I have some bicep code in the file that looks like this:

resource eventGridTopic 'Microsoft.EventGrid/systemTopcs@2021-12-01' = {
  name: 'my-cool-topic'
  location: location
  properties: {
    source: '/subscriptions/xxx/resourceGroups/resource-group-a/Microsoft.Storage/storageAccounts/nice-storage'
    topicType: 'Microsoft.Storage.StorageAccounts'
  }
}

I try to run it like this:

az deployment group create --name my-cool-group --resource-group resource-group-b --template-file mybicepfile.bicep

But I hit an error saying {"code": "InvalidRequest", "message": "System topic azure subscription id must match with source azure subscription"}

Which makes sense because I’m specifying the resource group when I run the file. So how do I specifify that for that resource I want it in another group?

(I would be really happy to create that resource seperately in a different file, but then I don’t know how to refer to it once its created within this one)

2

Answers


  1. Try using a parameter to specify the resource group name dynamically. Then, you can pass the desired resource group name as a parameter when deploying the Bicep file.

    param targetResourceGroup string
    

    Then use the parameter in the resource block:

    resource eventGridTopic 'Microsoft.EventGrid/systemTopics@2021-12-01' = {
      name: 'my-cool-topic'
      location: resourceGroup().location
      properties: {
      source: '/subscriptions/xxx/resourceGroups/resource-group-a/Microsoft.Storage/storageAccounts/nice-storage'
      topicType: 'Microsoft.Storage.StorageAccounts'
      }
    }
    

    When deploying the Bicep file, specify the value for the targetResourceGroup parameter:

    az deployment group create --name my-cool-group --resource-group resource-group-b --template-file mybicepfile.bicep --parameters targetResourceGroup=resource-group-a
    

    This way, you may create the event topic in a different resource group (resource-group-a) than the one specified in the deployment command (resource-group-b).

    Login or Signup to reply.
  2. If you deploy other resources, such as vm which link to vNet in other resource group using vNet resourceId, it should works well, But event grid system topic is an exception, which must match the source which be in the same resource group, it seems a inner-design, not the matter about your template file.

    I have test it using pure rest api.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search