我正在尝试基于 ResourceModules 创建一个 Bicep CosmosDb 库发表了我的 MS Bicep 团队。我可以使用私有(private)端点成功启动 CosmosDb 实例,并且在第一次运行时,Sql 容器的创建也可以工作。在管道的后续运行中,它在容器上失败并显示以下错误消息。
...{"Errors":["The input content is invalid - 'analyticalStorageTtl' is not a valid property in the current payload."]}...
我不确定为什么会出现这种情况,因为我没有将该元素传递给 ARM 并假设它默认在某处。问题是,如果我确实传递了有效值,我仍然会收到错误。有人知道如何解决这个问题吗?
编辑:
好吧,这有点奇怪,而且有点令人担忧。我周五遇到的问题已经消失,部署现在正在后续运行中进行。 Bicep 文件或配置均未更改。我有点担心 Bicep 作为我们现在基础设施部署方向的稳定性。
Json(片段)
"cosmosDbSqlwithPrivateEndpoints":{
"value":{
"name": "cosdb-eun-h1s01-dev-iacsql123",
"resourceGroup": "rg-eun-h1s01-dev-iac",
"sqlDatabases": [
{
"name": "mySqlDb",
"throughput": 400,
"containers": [
{
"conflictResolutionPolicy": {
"conflictResolutionPath": "/myId",
"mode": "LastWriterWins"
},
"defaultTtl": 1000,
"indexingPolicy": {
"automatic": true
},
"kind": "Hash",
"name": "container-001",
"paths": [
"/myPartitionKey"
],
"throughput": 400,
"uniqueKeyPolicyKeys": [
{
"paths": [
"/firstName"
]
},
{
"paths": [
"/lastName"
]
}
]
}
]
}
],
"privateEndpoints": [
{
"name": "pep-eun-h1s01-iac-cosdb-eun-iac123-sql",
"resourceGroup": "",
"subnet": {
"name": "snet-eun-h1s01-iac-storagepep",
"virtualNetworkResourceGroupName": "rg-eun-h1s01-dev-iac",
"virtualNetworkName": "vnet-eun-h1s01-iac-storage"
},
"groupIds": ["Sql"],
"ipConfigurations": [
{
"name": "default",
"properties": {
"memberName": "cosdb-eun-h1s01-dev-iacsql123",
"groupId": "Sql",
"privateIPAddress": "10.100.1.13"
}
},
{
"name": "northeurope",
"properties": {
"memberName": "cosdb-eun-h1s01-dev-iacsql123-northeurope",
"groupId": "Sql",
"privateIPAddress": "10.100.1.14"
}
}
// ,
// {
// "name": "westeurope",
// "properties": {
// "memberName": "cosdb-eun-h1s01-dev-iacsql123-westeurope",
// "groupId": "Sql",
// "privateIPAddress": "10.100.1.15"
// }
// }
],
"privateDns":{
"name" : "privatelink.documents.azure.com",
"resourceGroupName": ""
},
"tags": {
"Application": "Infrastructure as Code",
"CompanyCode": "V025",
"Critcality": "Category 1",
"Description": "CosmosDb private endpoint for Sql",
"Environment": "DEV",
"InternalOrder_CostCenter": "90020989",
"RemedyID": "CR999999",
"Version": "v1.0"
}
}
],
"diagnosticSettings":{
"storageAccount": {
"resourceGroup": "rg-eun-h1s01-dev-iac",
"accountName": "streundeviacdiag111"
},
"logAnalyticsWorkspace": {
"resourceGroup": "rg-euw-odpdev-shared-analytics",
"accountName": "law-euw-odpdev-7b08-default"
}
},
"tags": {
"Application": "Infrastructure as Code",
"CompanyCode": "V025",
"Critcality": "Category 1",
"Description": "CosmosDb with NoSql for IaC",
"Environment": "DEV",
"InternalOrder_CostCenter": "90020989",
"RemedyID": "CR999999",
"Version": "v1.0"
}
}
},
Main.bicep(片段)
@description('The cosmos db with sql engine configuration from the environment json parameters file')
param cosmosDbSqlwithPrivateEndpoints object
module cosmosDbSql 'br/Storage:cosmosdb:v0.1' = {
name: 'cosmosDbSql-${cosmosDbSqlwithPrivateEndpoints.name}-${uniqueString(cosmosDbSqlwithPrivateEndpoints.name)}'
scope: cosmosDbSqlwithPrivateEndpoints.resourceGroup != '' ? resourceGroup(cosmosDbSqlwithPrivateEndpoints.resourceGroup) : resourceGroup()
params: {
name: cosmosDbSqlwithPrivateEndpoints.name
defaultConsistencyLevel: contains(cosmosDbSqlwithPrivateEndpoints, 'defaultConsistencyLevel') ? cosmosDbSqlwithPrivateEndpoints.defaultConsistencyLevel : 'Session'
enableFreeTier: contains(cosmosDbSqlwithPrivateEndpoints, 'enableFreeTier') ? cosmosDbSqlwithPrivateEndpoints.enableFreeTier : false
capabilitiesToAdd:['EnableServerless']
sqlDatabases: cosmosDbSqlwithPrivateEndpoints.sqlDatabases
privateEndpoints: cosmosDbSqlwithPrivateEndpoints.privateEndpoints
diagnosticStorageAccountId: resourceId(cosmosDbSqlwithPrivateEndpoints.diagnosticSettings.storageAccount.resourceGroup, 'Microsoft.Storage/storageAccounts', cosmosDbSqlwithPrivateEndpoints.diagnosticSettings.storageAccount.accountName)
diagnosticWorkspaceId: resourceId(cosmosDbSqlwithPrivateEndpoints.diagnosticSettings.logAnalyticsWorkspace.resourceGroup, 'Microsoft.OperationalInsights/workspaces', cosmosDbSqlwithPrivateEndpoints.diagnosticSettings.logAnalyticsWorkspace.accountName)
tags: cosmosDbSqlwithPrivateEndpoints.tags
}
}
CosmosDb.bicep
@description('Required. Name of the Database Account.')
param name string
@description('Optional. Location for all resources.')
param location string = resourceGroup().location
@description('Required. An array of private endpoints objects')
param privateEndpoints array
@allowed([
'Eventual'
'ConsistentPrefix'
'Session'
'BoundedStaleness'
'Strong'
])
@description('Optional. The default consistency level of the Cosmos DB account.')
param defaultConsistencyLevel string = 'Session'
@description('Optional. Flag to indicate whether Free Tier is enabled.')
param enableFreeTier bool = false
@description('Optional. SQL Databases configurations.')
param sqlDatabases array = []
@description('Optional. MongoDB Databases configurations.')
param mongodbDatabases array = []
@description('Optional. Gremlin Databases configurations.')
param gremlinDatabases array = []
@allowed([
'EnableCassandra'
'EnableTable'
'EnableGremlin'
'EnableMongo'
'DisableRateLimitingResponses'
'EnableServerless'
])
@description('Optional. List of Cosmos DB capabilities for the account.')
param capabilitiesToAdd array = []
@description('Optional. Resource ID of the diagnostic storage account.')
param diagnosticStorageAccountId string = ''
@description('Optional. Resource ID of the log analytics workspace.')
param diagnosticWorkspaceId string = ''
@description('Optional. Tags of the Database Account resource.')
param tags object = {}
//Default Values
var backupIntervalInMinutes = 240
var backupPolicyType = 'Continuous'
var backupPolicyContinuousTier = 'Continuous30Days'
var backupRetentionIntervalInHours = 8
var backupStorageRedundancy = 'Local'
var databaseAccountOfferType = 'Standard'
var automaticFailover = true
var maxIntervalInSeconds = 300
var maxStalenessPrefix = 100000
var serverVersion = '4.2'
var systemAssignedIdentity = true
var userAssignedIdentities = {}
var locations = contains(capabilitiesToAdd, 'EnableServerless') ? [
{
failoverPriority: 0
locationName: 'North Europe'
isZoneRedundant: false
}
] : [
{
failoverPriority: 0
locationName: 'North Europe'
isZoneRedundant: false
}
{
failoverPriority: 1
locationName: 'West Europe'
isZoneRedundant: false
}
]
//Build diagnostics objects
var diagnosticLogsRetentionInDays = 365
var diagnosticLogCategoriesToEnable = ['allLogs']
var diagnosticMetricsToEnable = ['Requests']
var diagnosticSettingsName = 'diag-${name}-cosmos-log'
var diagnosticsLogsSpecified = [for category in filter(diagnosticLogCategoriesToEnable, item => item != 'allLogs'): {
category: category
enabled: true
retentionPolicy: {
enabled: true
days: diagnosticLogsRetentionInDays
}
}]
var diagnosticsLogs = contains(diagnosticLogCategoriesToEnable, 'allLogs') ? [
{
categoryGroup: 'allLogs'
enabled: true
retentionPolicy: {
enabled: true
days: diagnosticLogsRetentionInDays
}
}
] : diagnosticsLogsSpecified
var diagnosticsMetrics = [for metric in diagnosticMetricsToEnable: {
category: metric
timeGrain: null
enabled: true
retentionPolicy: {
enabled: true
days: diagnosticLogsRetentionInDays
}
}]
var identityType = systemAssignedIdentity ? (!empty(userAssignedIdentities) ? 'SystemAssigned, UserAssigned' : 'SystemAssigned') : (!empty(userAssignedIdentities) ? 'UserAssigned' : 'None')
var identity = identityType != 'None' ? {
type: identityType
userAssignedIdentities: !empty(userAssignedIdentities) ? userAssignedIdentities : null
} : null
var consistencyPolicy = {
Eventual: {
defaultConsistencyLevel: 'Eventual'
}
ConsistentPrefix: {
defaultConsistencyLevel: 'ConsistentPrefix'
}
Session: {
defaultConsistencyLevel: 'Session'
}
BoundedStaleness: {
defaultConsistencyLevel: 'BoundedStaleness'
maxStalenessPrefix: maxStalenessPrefix
maxIntervalInSeconds: maxIntervalInSeconds
}
Strong: {
defaultConsistencyLevel: 'Strong'
}
}
var databaseAccount_locations = [for location in locations: {
failoverPriority: location.failoverPriority
isZoneRedundant: location.isZoneRedundant
locationName: location.locationName
}]
var kind = !empty(sqlDatabases) || !empty(gremlinDatabases) ? 'GlobalDocumentDB' : (!empty(mongodbDatabases) ? 'MongoDB' : 'Parse')
var capabilities = [for capability in capabilitiesToAdd: {
name: capability
}]
var backupPolicy = backupPolicyType == 'Continuous' ? {
type: backupPolicyType
continuousModeProperties: {
tier: backupPolicyContinuousTier
}
} : {
type: backupPolicyType
periodicModeProperties: {
backupIntervalInMinutes: backupIntervalInMinutes
backupRetentionIntervalInHours: backupRetentionIntervalInHours
backupStorageRedundancy: backupStorageRedundancy
}
}
var databaseAccount_properties = union(
{databaseAccountOfferType: databaseAccountOfferType },
{networkAclBypass: 'AzureServices'},
{publicNetworkAccess: 'Disabled'},
((!empty(sqlDatabases) || !empty(mongodbDatabases) || !empty(gremlinDatabases)) ? {
// Common properties
consistencyPolicy: consistencyPolicy[defaultConsistencyLevel]
locations: databaseAccount_locations
capabilities: capabilities
enableFreeTier: enableFreeTier
backupPolicy: backupPolicy
} : {}),
(!empty(sqlDatabases) ? {
// SQLDB properties
enableAutomaticFailover: automaticFailover
} : {}),
(!empty(mongodbDatabases) ? {
// MongoDb properties
apiProperties: {
serverVersion: serverVersion
}
} : {})
)
var enableDefaultTelemetry = true
resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (enableDefaultTelemetry) {
name: 'pid-47ed15a6-730a-4827-bcb4-0fd963ffbd82-${uniqueString(deployment().name, location)}'
properties: {
mode: 'Incremental'
template: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
resources: []
}
}
}
resource databaseAccount 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' = {
name: name
location: location
tags: tags
identity: identity
kind: kind
properties: databaseAccount_properties
}
resource databaseAccount_diagnosticSettings 'Microsoft.Insights/diagnosticsettings@2021-05-01-preview' = if ((!empty(diagnosticStorageAccountId)) || (!empty(diagnosticWorkspaceId))) {
name: !empty(diagnosticSettingsName) ? diagnosticSettingsName : '${name}-diagnosticSettings'
properties: {
storageAccountId: !empty(diagnosticStorageAccountId) ? diagnosticStorageAccountId : null
workspaceId: !empty(diagnosticWorkspaceId) ? diagnosticWorkspaceId : null
metrics: diagnosticsMetrics
logs: diagnosticsLogs
}
scope: databaseAccount
}
module databaseAccount_sqlDatabases 'br/Storage:cosmosdb/sql:v0.1' = [for sqlDatabase in sqlDatabases: {
name: '${uniqueString(deployment().name, location)}-sqldb-${sqlDatabase.name}'
params: {
databaseAccountName: databaseAccount.name
name: sqlDatabase.name
containers: contains(sqlDatabase, 'containers') ? sqlDatabase.containers : []
throughput: contains(sqlDatabase, 'throughput') ? sqlDatabase.throughput : 400
autoscaleSettingsMaxThroughput: contains(sqlDatabase, 'autoscaleSettingsMaxThroughput') ? sqlDatabase.autoscaleSettingsMaxThroughput : -1
}
}]
module databaseAccount_mongodbDatabases 'br/Storage:cosmosdb/mongo:v0.1' = [for mongodbDatabase in mongodbDatabases: {
name: '${uniqueString(deployment().name, location)}-mongodb-${mongodbDatabase.name}'
params: {
databaseAccountName: databaseAccount.name
name: mongodbDatabase.name
collections: contains(mongodbDatabase, 'collections') ? mongodbDatabase.collections : []
}
}]
module databaseAccount_gremlinDatabases 'br/Storage:cosmosdb/gremlin:v0.1' = [for gremlinDatabase in gremlinDatabases: {
name: '${uniqueString(deployment().name, location)}-gremlin-${gremlinDatabase.name}'
params: {
databaseAccountName: databaseAccount.name
name: gremlinDatabase.name
graphs: contains(gremlinDatabase, 'graphs') ? gremlinDatabase.graphs : []
}
}]
////////////////////////////////////////////////////////////////////
//Assign Private Endpoint to the Storage account sub resource type//
////////////////////////////////////////////////////////////////////
module privateEndpointsModule 'br/Network:privateendpoint:v0.1' = [for endpoint in privateEndpoints: {
name: 'pep-${endpoint.name}-${uniqueString(endpoint.name, location)}'
scope: endpoint.resourceGroup != '' ? resourceGroup(endpoint.resourceGroup) : resourceGroup()
params: {
name: endpoint.name
location: location
serviceResourceId: databaseAccount.id
subnetResourceId: resourceId(endpoint.subnet.virtualNetworkResourceGroupName, 'Microsoft.Network/virtualNetworks/subnets', endpoint.subnet.virtualNetworkName, endpoint.subnet.name)
ipConfigurations: endpoint.ipConfigurations
groupIds: endpoint.groupIds
privateDnsZoneGroup: {
name: endpoint.privateDns.name
privateDNSResourceIds: [resourceId(endpoint.privateDns.resourceGroupName != '' ? endpoint.privateDns.resourceGroupName : resourceGroup().name, 'Microsoft.Network/privateDnsZones/', endpoint.privateDns.name)]
}
tags: endpoint.tags
}
}]
@description('The name of the database account.')
output name string = databaseAccount.name
@description('The resource ID of the database account.')
output id string = databaseAccount.id
@description('The name of the resource group the database account was created in.')
output resourceGroupName string = resourceGroup().name
@description('The principal ID of the system assigned identity.')
output systemAssignedPrincipalId string = systemAssignedIdentity && contains(databaseAccount.identity, 'principalId') ? databaseAccount.identity.principalId : ''
@description('The location the resource was deployed into.')
output location string = databaseAccount.location
CosmosSql.bicep
@description('Conditional. The name of the parent Database Account. Required if the template is used in a standalone deployment.')
param databaseAccountName string
@description('Required. Name of the SQL database .')
param name string
@description('Optional. Array of containers to deploy in the SQL database.')
param containers array = []
@description('Optional. Request units per second. Will be set to null if autoscaleSettingsMaxThroughput is used.')
param throughput int = 400
@description('Optional. Specifies the Autoscale settings and represents maximum throughput, the resource can scale up to. The autoscale throughput should have valid throughput values between 1000 and 1000000 inclusive in increments of 1000. If value is set to -1, then the property will be set to null and autoscale will be disabled.')
param autoscaleSettingsMaxThroughput int = -1
@description('Optional. Tags of the SQL database resource.')
param tags object = {}
@description('Optional. Enable telemetry via a Globally Unique Identifier (GUID).')
var enableDefaultTelemetry = true
resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (enableDefaultTelemetry) {
name: 'pid-47ed15a6-730a-4827-bcb4-0fd963ffbd82-${uniqueString(deployment().name)}'
properties: {
mode: 'Incremental'
template: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
resources: []
}
}
}
resource databaseAccount 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' existing = {
name: databaseAccountName
}
resource sqlDatabase 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2022-08-15' = {
name: name
parent: databaseAccount
tags: tags
properties: {
resource: {
id: name
}
options: contains(databaseAccount.properties.capabilities, { name: 'EnableServerless' }) ? null : {
throughput: autoscaleSettingsMaxThroughput == -1 ? throughput : null
autoscaleSettings: autoscaleSettingsMaxThroughput != -1 ? {
maxThroughput: autoscaleSettingsMaxThroughput
} : null
}
}
}
module container 'br/Storage:cosmosdb/sql/containers:v0.1' = [for container in containers: {
name: '${uniqueString(deployment().name, sqlDatabase.name)}-sqldb-${container.name}'
params: {
databaseAccountName: databaseAccountName
sqlDatabaseName: name
name: container.name
autoscaleSettingsMaxThroughput: contains(container, 'autoscaleSettingsMaxThroughput') ? container.autoscaleSettingsMaxThroughput : -1
conflictResolutionPolicy: contains(container, 'conflictResolutionPolicy') ? container.conflictResolutionPolicy : {}
defaultTtl: contains(container, 'defaultTtl') ? container.defaultTtl : -1
indexingPolicy: contains(container, 'indexingPolicy') ? container.indexingPolicy : {}
kind: contains(container, 'kind') ? container.kind : 'Hash'
paths: contains(container, 'paths') ? container.paths : []
throughput: contains(container, 'throughput') ? container.throughput : 400
uniqueKeyPolicyKeys: contains(container, 'uniqueKeyPolicyKeys') ? container.uniqueKeyPolicyKeys : []
}
}]
@description('The name of the SQL database.')
output name string = sqlDatabase.name
@description('The resource ID of the SQL database.')
output resourceId string = sqlDatabase.id
@description('The name of the resource group the SQL database was created in.')
output resourceGroupName string = resourceGroup().name
CosmosSqlDbContainer.bicep
@description('Required. The name of the parent Database Account. Required if the template is used in a standalone deployment.')
param databaseAccountName string
@description('Required. The name of the parent SQL Database. Required if the template is used in a standalone deployment.')
param sqlDatabaseName string
@description('Required. Name of the container.')
param name string
@description('Optional. The conflict resolution policy for the container. Conflicts and conflict resolution policies are applicable if the Azure Cosmos DB account is configured with multiple write regions.')
param conflictResolutionPolicy object = {}
@maxValue(2147483647)
@minValue(-1)
@description('Optional. Default time to live (in seconds). With Time to Live or TTL, Azure Cosmos DB provides the ability to delete items automatically from a container after a certain time period. If the value is set to "-1", it is equal to infinity, and items dont expire by default.')
param defaultTtl int = -1
@description('Optional. Request Units per second. Will be set to null if autoscaleSettingsMaxThroughput is used.')
param throughput int = 400
@maxValue(1000000)
@description('Optional. Specifies the Autoscale settings and represents maximum throughput, the resource can scale up to. The autoscale throughput should have valid throughput values between 1000 and 1000000 inclusive in increments of 1000. If value is set to -1, then the property will be set to null and autoscale will be disabled.')
param autoscaleSettingsMaxThroughput int = -1
@description('Optional. Tags of the SQL Database resource.')
param tags object = {}
@description('Optional. List of paths using which data within the container can be partitioned.')
param paths array = []
@description('Optional. Indexing policy of the container.')
param indexingPolicy object = {}
@description('Optional. The unique key policy configuration containing a list of unique keys that enforces uniqueness constraint on documents in the collection in the Azure Cosmos DB service.')
param uniqueKeyPolicyKeys array = []
@description('Optional. Indicates the kind of algorithm used for partitioning.')
@allowed([
'Hash'
'MultiHash'
'Range'
])
param kind string = 'Hash'
var enableDefaultTelemetry = true
resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (enableDefaultTelemetry) {
name: 'pid-47ed15a6-730a-4827-bcb4-0fd963ffbd82-${uniqueString(deployment().name)}'
properties: {
mode: 'Incremental'
template: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
resources: []
}
}
}
resource databaseAccount 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' existing = {
name: databaseAccountName
resource sqlDatabase 'sqlDatabases@2021-07-01-preview' existing = {
name: sqlDatabaseName
}
}
resource container 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2022-08-15' = {
name: name
parent: databaseAccount::sqlDatabase
tags: tags
properties: {
resource: {
conflictResolutionPolicy: conflictResolutionPolicy
defaultTtl: defaultTtl
id: name
indexingPolicy: !empty(indexingPolicy) ? indexingPolicy : null
partitionKey: {
paths: paths
kind: kind
}
uniqueKeyPolicy: !empty(uniqueKeyPolicyKeys) ? {
uniqueKeys: uniqueKeyPolicyKeys
} : null
}
options: contains(databaseAccount.properties.capabilities, { name: 'EnableServerless' }) ? null : {
throughput: autoscaleSettingsMaxThroughput == -1 ? throughput : null
autoscaleSettings: autoscaleSettingsMaxThroughput != -1 ? {
maxThroughput: autoscaleSettingsMaxThroughput
} : null
}
}
}
@description('The name of the container.')
output name string = container.name
@description('The resource ID of the container.')
output resourceId string = container.id
@description('The name of the resource group the container was created in.')
output resourceGroupName string = resourceGroup().name
最佳答案
它实际上是主要为所引用的模块做出贡献的 Microsoft 员工的集合,而不是 Microsoft Bicep 团队。
我建议在存储库上提出问题,以便该团队提供建议。 https://github.com/Azure/ResourceModules/issues
您收到的错误analyticalStorageTtl不是有效的属性
可能是因为底层资源提供程序已更改并且错误已渗透到模块中。即使您没有使用它,这些模块通常也会采用捕获每个可能的属性选项然后中继到底层资源声明的方法。这种方法确实提供了灵 active ,但也产生了更大的误差表面积——设计模块时通常应该考虑到这一点。
该项目通常建议您使用版本中的模块,而不是主分支......也许这也可以帮助您?
Default path: To avoid disruptions, use distinct versions available through releases.
关于azure - CosmosDb SQL 容器的 Bicep 部署在后续管道运行时引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76307088/