I'm deploying Cosmos via bicep templates. Mostly everything is parameterised. We have found a way to deploy multiple stored procedures described below.
Define an array in the bicep
param storedProcedureData array = []
then in the resource section loop around the data:
resource cosmosStoredProcedures 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/storedProcedures@2021-06-15' = [for storedProcedure in storedProcedureData: {
parent: cosmosSQLContainers
name: storedProcedure.name
properties: {
resource: {
id: storedProcedure.name
body: storedProcedure.body
}
}
}]
I have a json file with the stored procedure code in like this:
[
{
"name": "sp1",
"body": "function sp1 etc"
},
{
"name": "sp2",
"body": "function sp2 etc"
}
]
and call it like this from powershell using az commands:
az deployment group create --resource-group rgname `
--name testdeployment `
--template-file "C:\GitHub\bicep\cosmosdb\main.bicep" `
--parameters "C:\GitHub\bicep\cosmosdb\cosmosMain.parameters.json" `
--parameters storedProcedureData=$storedProcedureData
where the stored procedure data is a variable:
$storedProcedureData=(Get-Content "C:\GitHub\bicep\cosmosdb\storedproc.json")
Question is - is there a better way!!! And what if I have multiple containers ...