title: Referencing resource created in one module in another module Azure Bicep?
body: <p>Suppose I have two files/modules in Azure Bicep, both are called in a 'main.bicep'. One is called 'storage.bicep' and contains, among others, the following code to create a storageAccount:</p>
  <pre><code>resource storageAccountTemp 'Microsoft.Storage/storageAccounts@2021-08-01' = {
    name: 'tmpst4dnbnlp'
    location: location
    sku: {
      name: storageAccountSku
    }
    kind: 'StorageV2'
    properties: {
      allowBlobPublicAccess: false
      accessTier: 'Hot'
    }
  }
  </code></pre>
  <p>Another file contains some LogicApp definitions and is called 'orchestration.bicep'. Now in this file, there is a part where I want to reference the 'storageAccountTemp' resource in module 'storage.bicep', as to provide the LogicApp system managed identity access the contributor role for the:</p>
  <pre><code>resource logicAppStorageAccountRoleAssignment 'Microsoft.Authorization/roleAssignments@2020-10-01-preview' = {
    scope: 'xxx'
    name: guid('ra-logicapp-${roleDefinitionId}')
    properties: {
      principalType: 'ServicePrincipal'
      roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleDefinitionId)
      principalId: logicAppTest.identity.principalId
    }
  }
  </code></pre>
  <p>Where I need to specify the scope (that now says 'xxx'). I can't say resourceGroup() since the storage is in a different resource group. Instead, I want to reference the storageAccountTemp object. This seems impossible to do when the object is in a different module (I tried outputting the name and id and using these but this was not accepted by Bicep.</p>
  <p>Is there any way I can actually reference the original storageAccountTemp object from 'storage.bicep' in the 'orchestration.bicep' file?</p>