【发布时间】:2022-08-14 04:17:54
【问题描述】:
我有一个相当简单的 Bicep 脚本来创建 Cosmos 数据库以及其中的容器:
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\"/?\'}]
}
}
}
}
这很好用。但是,我现在想创建多个具有相同结构的容器,因此我尝试将容器定义模板化到一个模块中:
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\"/?\'}]
}
}
}
}
我现在不知道如何将它链接回父级。我不能在模块中使用parent: ,因为我找不到通过顶层文件将数据库资源传递到模块的方法。我不能在模块调用中使用parent: ,因为它不是有效的操作。我不能从父资源中调用模块,因为它不是有效的语法。
如何从我的父文件中调用上述模块并自动解析依赖项,就好像它们都在一个文件中一样?这不支持吗?应该有一个非常基本的方法来做到这一点(除非我遗漏了什么)。
标签: azure azure-cosmosdb infrastructure-as-code azure-bicep