title: How do I reference a resource from a module in Azure Bicep?
body: <p>I have a fairly simple Bicep script for creating a Cosmos Database as well as a container within it:</p>
  <pre><code>resource cosmos_db_live 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2022-05-15' = {
      parent: cosmos_account
      name: 'live'
      properties: {
          resource: {
              id: 'live'
          }
          options: {
              throughput: 600
          }
      }
  }
  
  resource cosmos_container 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2022-05-15' = {
      parent: cosmos_db_live
      name: 'container_name'
      properties: {
          resource: {
              id: 'container_name'
              partitionKey: {
                  paths: ['/partition']
              }
              conflictResolutionPolicy: {
                  mode: 'LastWriterWins'
                  conflictResolutionPath: '/_ts'
              }
              indexingPolicy: {
                  indexingMode: 'consistent'
                  automatic: true
                  includedPaths: [{path: '/*'}]
                  excludedPaths: [{path: '/&quot;_etag&quot;/?'}]
              }
          }
      }
  }
  </code></pre>
  <p>This works great. However I now want to create multiple containers all with the same structure so I am attempting to template the container definition out to a module:</p>
  <pre><code>param name string
  param partition string
  
  resource cosmos_container 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2022-05-15' = {
      name: name
      properties: {
          resource: {
              id: name
              partitionKey: {
                  paths: ['/${partition}']
              }
              conflictResolutionPolicy: {
                  mode: 'LastWriterWins'
                  conflictResolutionPath: '/_ts'
              }
              indexingPolicy: {
                  indexingMode: 'consistent'
                  automatic: true
                  includedPaths: [{path: '/*'}]
                  excludedPaths: [{path: '/&quot;_etag&quot;/?'}]
              }
          }
      }
  }
  </code></pre>
  <p>I now have no idea how to link it back to the parent. I cant use <code>parent: </code> within the module because I cant find a way to pass the DB resource into the module via the toplevel file. I cant use <code>parent: </code> within the module call because it is not a valid operation. I cant call the module from within the parent resource because it is not valid syntax.</p>
  <p>How can I call the above module from my parent file and have dependencies automatically resolved as if it was all in one file? Is this not supported? There should be a very basic way to do this (unless I am missing something).</p>