I have a fairly simple Bicep script for creating a Cosmos Database as well as a container within it:
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: '/"_etag"/?'}]
}
}
}
}
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:
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: '/"_etag"/?'}]
}
}
}
}
I now have no idea how to link it back to the parent. I cant use parent: within the module because I cant find a way to pass the DB resource into the module via the toplevel file. I cant use parent: 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.
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).