Bicep部署CosmosDb SQL容器在后续管道运行中引发错误。

huangapple go评论113阅读模式
英文:

Bicep deployments for CosmosDb SQL containers throws error on subsequent pipeline run

问题

I am attempting to create a Bicep CosmosDb library based on the ResourceModules published my the MS Bicep team. I can successfully spin up the CosmosDb instance with Private Endpoints and on the first run the creation of the Sql container also works. On subsequent runs of the pipeline it fails on the Container with the below error message.

> ...{"Errors":["The input content is invalid - "analyticalStorageTtl" is not a valid property in the current payload."]}...

I'm unsure why this is the case as I'm not passing that element to ARM and assume it's defaulted somewhere. Problem is if I do pass it with a valid value I still get the error. Anyone any idea how to get around this?

EDIT:

OK, this is a little strange and more than a little concerning. The issue I was getting on Friday has disappeared and the deployment is now working on subsequent runs. None of the Bicep files or configuration has changed. I'm a little concerned over the stability of Bicep as a direction for our infrastructure deployments now.

Json (snippet)

  1. "cosmosDbSqlwithPrivateEndpoints":{
  2. "value":{
  3. "name": "cosdb-eun-h1s01-dev-iacsql123",
  4. "resourceGroup": "rg-eun-h1s01-dev-iac",
  5. "sqlDatabases": [
  6. {
  7. "name": "mySqlDb",
  8. "throughput": 400,
  9. "containers": [
  10. {
  11. "conflictResolutionPolicy": {
  12. "conflictResolutionPath": "/myId",
  13. "mode": "LastWriterWins"
  14. },
  15. "defaultTtl": 1000,
  16. "indexingPolicy": {
  17. "automatic": true
  18. },
  19. "kind": "Hash",
  20. "name": "container-001",
  21. "paths": [
  22. "/myPartitionKey"
  23. ],
  24. "throughput": 400,
  25. "uniqueKeyPolicyKeys": [
  26. {
  27. "paths": [
  28. "/firstName"
  29. ]
  30. },
  31. {
  32. "paths": [
  33. "/lastName"
  34. ]
  35. }
  36. ]
  37. }
  38. ]
  39. }
  40. ],
  41. "privateEndpoints": [
  42. {
  43. "name": "pep-eun-h1s01-iac-cosdb-eun-iac123-sql",
  44. "resourceGroup": "",
  45. "subnet": {
  46. "name": "snet-eun-h1s01-iac-storagepep",
  47. "virtualNetworkResourceGroupName": "rg-eun-h1s01-dev-iac",
  48. "virtualNetworkName": "vnet-eun-h1s01-iac-storage"
  49. },
  50. "groupIds": ["Sql"],
  51. "ipConfigurations": [
  52. {
  53. "name": "default",
  54. "properties": {
  55. "memberName": "cosdb-eun-h1s01-dev-iacsql123",
  56. "groupId": "Sql",
  57. "privateIPAddress": "10.100.1.13"
  58. }
  59. },
  60. {
  61. "name": "northeurope",
  62. "properties": {
  63. "memberName": "cosdb-eun-h1s01-dev-iacsql123-northeurope",
  64. "groupId": "Sql",
  65. "privateIPAddress": "10.100.1.14"
  66. }
  67. }
  68. // ,
  69. // {
  70. // "name": "westeurope",
  71. // "properties": {
  72. // "memberName": "cosdb-eun-h1s01-dev-iacsql123-westeurope",
  73. // "groupId": "Sql",
  74. // "privateIPAddress": "10.100.1.15"
  75. // }
  76. // }
  77. ],
  78. "privateDns":{
  79. "name" : "privatelink.documents.azure.com",
  80. "resourceGroupName": ""
  81. },
  82. "tags": {
  83. "Application": "Infrastructure as Code",
  84. "CompanyCode": "V025",
  85. "Critcality": "Category 1",
  86. "Description": "CosmosDb private endpoint for Sql",
  87. "Environment": "DEV",
  88. "InternalOrder_CostCenter": "90020989",
  89. "RemedyID": "CR999999",
  90. "Version": "v1.0"
  91. }
  92. }
  93. ],
  94. "diagnosticSettings":{
  95. "storageAccount": {
  96. "resourceGroup": "rg-eun-h1s01-dev-iac",
  97. "accountName": "streundeviacdiag111"
  98. },
  99. "logAnalyticsWorkspace": {
  100. "resourceGroup": "rg-euw-odpdev-shared-analytics",
  101. "accountName": "law-euw-odpdev-7b08-default"
  102. }
  103. },
  104. "tags": {
  105. "Application": "Infrastructure as Code",
  106. "CompanyCode": "V025",
  107. "Critcality": "Category 1",
  108. "Description": "CosmosDb with NoSql for IaC",
  109. "Environment": "DEV",
  110. "InternalOrder_CostCenter": "900209
英文:

I am attempting to create a Bicep CosmosDb library based on the ResourceModules published my the MS Bicep team. I can successfully spin up the CosmosDb instance with Private Endpoints and on the first run the creation of the Sql container also works. On subsequent runs of the pipeline it fails on the Container with the below error message.

> ...{"Errors":["The input content is invalid -
> 'analyticalStorageTtl' is not a valid property in the current
> payload."]}...

I'm unsure why this is the case as I'm not passing that element to ARM and assume it's defaulted somewhere. Problem is if I do pass it with a valid value I still get the error. Anyone any idea how to get around this?

EDIT:

OK, this is a little strange and more than a little concerning. The issue I was getting on Friday has disappeared and the deployment is now working on subsequent runs. None of the Bicep files or configuration has changed. I'm a little concerned over the stability of Bicep as a direction for our infrastructure deployments now.

Json (snippet)

  1. "cosmosDbSqlwithPrivateEndpoints":{
  2. "value":{
  3. "name": "cosdb-eun-h1s01-dev-iacsql123",
  4. "resourceGroup": "rg-eun-h1s01-dev-iac",
  5. "sqlDatabases": [
  6. {
  7. "name": "mySqlDb",
  8. "throughput": 400,
  9. "containers": [
  10. {
  11. "conflictResolutionPolicy": {
  12. "conflictResolutionPath": "/myId",
  13. "mode": "LastWriterWins"
  14. },
  15. "defaultTtl": 1000,
  16. "indexingPolicy": {
  17. "automatic": true
  18. },
  19. "kind": "Hash",
  20. "name": "container-001",
  21. "paths": [
  22. "/myPartitionKey"
  23. ],
  24. "throughput": 400,
  25. "uniqueKeyPolicyKeys": [
  26. {
  27. "paths": [
  28. "/firstName"
  29. ]
  30. },
  31. {
  32. "paths": [
  33. "/lastName"
  34. ]
  35. }
  36. ]
  37. }
  38. ]
  39. }
  40. ],
  41. "privateEndpoints": [
  42. {
  43. "name": "pep-eun-h1s01-iac-cosdb-eun-iac123-sql",
  44. "resourceGroup": "",
  45. "subnet": {
  46. "name": "snet-eun-h1s01-iac-storagepep",
  47. "virtualNetworkResourceGroupName": "rg-eun-h1s01-dev-iac",
  48. "virtualNetworkName": "vnet-eun-h1s01-iac-storage"
  49. },
  50. "groupIds": ["Sql"],
  51. "ipConfigurations": [
  52. {
  53. "name": "default",
  54. "properties": {
  55. "memberName": "cosdb-eun-h1s01-dev-iacsql123",
  56. "groupId": "Sql",
  57. "privateIPAddress": "10.100.1.13"
  58. }
  59. },
  60. {
  61. "name": "northeurope",
  62. "properties": {
  63. "memberName": "cosdb-eun-h1s01-dev-iacsql123-northeurope",
  64. "groupId": "Sql",
  65. "privateIPAddress": "10.100.1.14"
  66. }
  67. }
  68. // ,
  69. // {
  70. // "name": "westeurope",
  71. // "properties": {
  72. // "memberName": "cosdb-eun-h1s01-dev-iacsql123-westeurope",
  73. // "groupId": "Sql",
  74. // "privateIPAddress": "10.100.1.15"
  75. // }
  76. // }
  77. ],
  78. "privateDns":{
  79. "name" : "privatelink.documents.azure.com",
  80. "resourceGroupName": ""
  81. },
  82. "tags": {
  83. "Application": "Infrastructure as Code",
  84. "CompanyCode": "V025",
  85. "Critcality": "Category 1",
  86. "Description": "CosmosDb private endpoint for Sql",
  87. "Environment": "DEV",
  88. "InternalOrder_CostCenter": "90020989",
  89. "RemedyID": "CR999999",
  90. "Version": "v1.0"
  91. }
  92. }
  93. ],
  94. "diagnosticSettings":{
  95. "storageAccount": {
  96. "resourceGroup": "rg-eun-h1s01-dev-iac",
  97. "accountName": "streundeviacdiag111"
  98. },
  99. "logAnalyticsWorkspace": {
  100. "resourceGroup": "rg-euw-odpdev-shared-analytics",
  101. "accountName": "law-euw-odpdev-7b08-default"
  102. }
  103. },
  104. "tags": {
  105. "Application": "Infrastructure as Code",
  106. "CompanyCode": "V025",
  107. "Critcality": "Category 1",
  108. "Description": "CosmosDb with NoSql for IaC",
  109. "Environment": "DEV",
  110. "InternalOrder_CostCenter": "90020989",
  111. "RemedyID": "CR999999",
  112. "Version": "v1.0"
  113. }
  114. }
  115. },

Main.bicep (snippet)

  1. @description('The cosmos db with sql engine configuration from the environment json parameters file')
  2. param cosmosDbSqlwithPrivateEndpoints object
  3. module cosmosDbSql 'br/Storage:cosmosdb:v0.1' = {
  4. name: 'cosmosDbSql-${cosmosDbSqlwithPrivateEndpoints.name}-${uniqueString(cosmosDbSqlwithPrivateEndpoints.name)}'
  5. scope: cosmosDbSqlwithPrivateEndpoints.resourceGroup != '' ? resourceGroup(cosmosDbSqlwithPrivateEndpoints.resourceGroup) : resourceGroup()
  6. params: {
  7. name: cosmosDbSqlwithPrivateEndpoints.name
  8. defaultConsistencyLevel: contains(cosmosDbSqlwithPrivateEndpoints, 'defaultConsistencyLevel') ? cosmosDbSqlwithPrivateEndpoints.defaultConsistencyLevel : 'Session'
  9. enableFreeTier: contains(cosmosDbSqlwithPrivateEndpoints, 'enableFreeTier') ? cosmosDbSqlwithPrivateEndpoints.enableFreeTier : false
  10. capabilitiesToAdd:['EnableServerless']
  11. sqlDatabases: cosmosDbSqlwithPrivateEndpoints.sqlDatabases
  12. privateEndpoints: cosmosDbSqlwithPrivateEndpoints.privateEndpoints
  13. diagnosticStorageAccountId: resourceId(cosmosDbSqlwithPrivateEndpoints.diagnosticSettings.storageAccount.resourceGroup, 'Microsoft.Storage/storageAccounts', cosmosDbSqlwithPrivateEndpoints.diagnosticSettings.storageAccount.accountName)
  14. diagnosticWorkspaceId: resourceId(cosmosDbSqlwithPrivateEndpoints.diagnosticSettings.logAnalyticsWorkspace.resourceGroup, 'Microsoft.OperationalInsights/workspaces', cosmosDbSqlwithPrivateEndpoints.diagnosticSettings.logAnalyticsWorkspace.accountName)
  15. tags: cosmosDbSqlwithPrivateEndpoints.tags
  16. }
  17. }

CosmosDb.bicep

  1. @description('Required. Name of the Database Account.')
  2. param name string
  3. @description('Optional. Location for all resources.')
  4. param location string = resourceGroup().location
  5. @description('Required. An array of private endpoints objects')
  6. param privateEndpoints array
  7. @allowed([
  8. 'Eventual'
  9. 'ConsistentPrefix'
  10. 'Session'
  11. 'BoundedStaleness'
  12. 'Strong'
  13. ])
  14. @description('Optional. The default consistency level of the Cosmos DB account.')
  15. param defaultConsistencyLevel string = 'Session'
  16. @description('Optional. Flag to indicate whether Free Tier is enabled.')
  17. param enableFreeTier bool = false
  18. @description('Optional. SQL Databases configurations.')
  19. param sqlDatabases array = []
  20. @description('Optional. MongoDB Databases configurations.')
  21. param mongodbDatabases array = []
  22. @description('Optional. Gremlin Databases configurations.')
  23. param gremlinDatabases array = []
  24. @allowed([
  25. 'EnableCassandra'
  26. 'EnableTable'
  27. 'EnableGremlin'
  28. 'EnableMongo'
  29. 'DisableRateLimitingResponses'
  30. 'EnableServerless'
  31. ])
  32. @description('Optional. List of Cosmos DB capabilities for the account.')
  33. param capabilitiesToAdd array = []
  34. @description('Optional. Resource ID of the diagnostic storage account.')
  35. param diagnosticStorageAccountId string = ''
  36. @description('Optional. Resource ID of the log analytics workspace.')
  37. param diagnosticWorkspaceId string = ''
  38. @description('Optional. Tags of the Database Account resource.')
  39. param tags object = {}
  40. //Default Values
  41. var backupIntervalInMinutes = 240
  42. var backupPolicyType = 'Continuous'
  43. var backupPolicyContinuousTier = 'Continuous30Days'
  44. var backupRetentionIntervalInHours = 8
  45. var backupStorageRedundancy = 'Local'
  46. var databaseAccountOfferType = 'Standard'
  47. var automaticFailover = true
  48. var maxIntervalInSeconds = 300
  49. var maxStalenessPrefix = 100000
  50. var serverVersion = '4.2'
  51. var systemAssignedIdentity = true
  52. var userAssignedIdentities = {}
  53. var locations = contains(capabilitiesToAdd, 'EnableServerless') ? [
  54. {
  55. failoverPriority: 0
  56. locationName: 'North Europe'
  57. isZoneRedundant: false
  58. }
  59. ] : [
  60. {
  61. failoverPriority: 0
  62. locationName: 'North Europe'
  63. isZoneRedundant: false
  64. }
  65. {
  66. failoverPriority: 1
  67. locationName: 'West Europe'
  68. isZoneRedundant: false
  69. }
  70. ]
  71. //Build diagnostics objects
  72. var diagnosticLogsRetentionInDays = 365
  73. var diagnosticLogCategoriesToEnable = ['allLogs']
  74. var diagnosticMetricsToEnable = ['Requests']
  75. var diagnosticSettingsName = 'diag-${name}-cosmos-log'
  76. var diagnosticsLogsSpecified = [for category in filter(diagnosticLogCategoriesToEnable, item => item != 'allLogs'): {
  77. category: category
  78. enabled: true
  79. retentionPolicy: {
  80. enabled: true
  81. days: diagnosticLogsRetentionInDays
  82. }
  83. }]
  84. var diagnosticsLogs = contains(diagnosticLogCategoriesToEnable, 'allLogs') ? [
  85. {
  86. categoryGroup: 'allLogs'
  87. enabled: true
  88. retentionPolicy: {
  89. enabled: true
  90. days: diagnosticLogsRetentionInDays
  91. }
  92. }
  93. ] : diagnosticsLogsSpecified
  94. var diagnosticsMetrics = [for metric in diagnosticMetricsToEnable: {
  95. category: metric
  96. timeGrain: null
  97. enabled: true
  98. retentionPolicy: {
  99. enabled: true
  100. days: diagnosticLogsRetentionInDays
  101. }
  102. }]
  103. var identityType = systemAssignedIdentity ? (!empty(userAssignedIdentities) ? 'SystemAssigned, UserAssigned' : 'SystemAssigned') : (!empty(userAssignedIdentities) ? 'UserAssigned' : 'None')
  104. var identity = identityType != 'None' ? {
  105. type: identityType
  106. userAssignedIdentities: !empty(userAssignedIdentities) ? userAssignedIdentities : null
  107. } : null
  108. var consistencyPolicy = {
  109. Eventual: {
  110. defaultConsistencyLevel: 'Eventual'
  111. }
  112. ConsistentPrefix: {
  113. defaultConsistencyLevel: 'ConsistentPrefix'
  114. }
  115. Session: {
  116. defaultConsistencyLevel: 'Session'
  117. }
  118. BoundedStaleness: {
  119. defaultConsistencyLevel: 'BoundedStaleness'
  120. maxStalenessPrefix: maxStalenessPrefix
  121. maxIntervalInSeconds: maxIntervalInSeconds
  122. }
  123. Strong: {
  124. defaultConsistencyLevel: 'Strong'
  125. }
  126. }
  127. var databaseAccount_locations = [for location in locations: {
  128. failoverPriority: location.failoverPriority
  129. isZoneRedundant: location.isZoneRedundant
  130. locationName: location.locationName
  131. }]
  132. var kind = !empty(sqlDatabases) || !empty(gremlinDatabases) ? 'GlobalDocumentDB' : (!empty(mongodbDatabases) ? 'MongoDB' : 'Parse')
  133. var capabilities = [for capability in capabilitiesToAdd: {
  134. name: capability
  135. }]
  136. var backupPolicy = backupPolicyType == 'Continuous' ? {
  137. type: backupPolicyType
  138. continuousModeProperties: {
  139. tier: backupPolicyContinuousTier
  140. }
  141. } : {
  142. type: backupPolicyType
  143. periodicModeProperties: {
  144. backupIntervalInMinutes: backupIntervalInMinutes
  145. backupRetentionIntervalInHours: backupRetentionIntervalInHours
  146. backupStorageRedundancy: backupStorageRedundancy
  147. }
  148. }
  149. var databaseAccount_properties = union(
  150. {databaseAccountOfferType: databaseAccountOfferType },
  151. {networkAclBypass: 'AzureServices'},
  152. {publicNetworkAccess: 'Disabled'},
  153. ((!empty(sqlDatabases) || !empty(mongodbDatabases) || !empty(gremlinDatabases)) ? {
  154. // Common properties
  155. consistencyPolicy: consistencyPolicy[defaultConsistencyLevel]
  156. locations: databaseAccount_locations
  157. capabilities: capabilities
  158. enableFreeTier: enableFreeTier
  159. backupPolicy: backupPolicy
  160. } : {}),
  161. (!empty(sqlDatabases) ? {
  162. // SQLDB properties
  163. enableAutomaticFailover: automaticFailover
  164. } : {}),
  165. (!empty(mongodbDatabases) ? {
  166. // MongoDb properties
  167. apiProperties: {
  168. serverVersion: serverVersion
  169. }
  170. } : {})
  171. )
  172. var enableDefaultTelemetry = true
  173. resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (enableDefaultTelemetry) {
  174. name: 'pid-47ed15a6-730a-4827-bcb4-0fd963ffbd82-${uniqueString(deployment().name, location)}'
  175. properties: {
  176. mode: 'Incremental'
  177. template: {
  178. '$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
  179. contentVersion: '1.0.0.0'
  180. resources: []
  181. }
  182. }
  183. }
  184. resource databaseAccount 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' = {
  185. name: name
  186. location: location
  187. tags: tags
  188. identity: identity
  189. kind: kind
  190. properties: databaseAccount_properties
  191. }
  192. resource databaseAccount_diagnosticSettings 'Microsoft.Insights/diagnosticsettings@2021-05-01-preview' = if ((!empty(diagnosticStorageAccountId)) || (!empty(diagnosticWorkspaceId))) {
  193. name: !empty(diagnosticSettingsName) ? diagnosticSettingsName : '${name}-diagnosticSettings'
  194. properties: {
  195. storageAccountId: !empty(diagnosticStorageAccountId) ? diagnosticStorageAccountId : null
  196. workspaceId: !empty(diagnosticWorkspaceId) ? diagnosticWorkspaceId : null
  197. metrics: diagnosticsMetrics
  198. logs: diagnosticsLogs
  199. }
  200. scope: databaseAccount
  201. }
  202. module databaseAccount_sqlDatabases 'br/Storage:cosmosdb/sql:v0.1' = [for sqlDatabase in sqlDatabases: {
  203. name: '${uniqueString(deployment().name, location)}-sqldb-${sqlDatabase.name}'
  204. params: {
  205. databaseAccountName: databaseAccount.name
  206. name: sqlDatabase.name
  207. containers: contains(sqlDatabase, 'containers') ? sqlDatabase.containers : []
  208. throughput: contains(sqlDatabase, 'throughput') ? sqlDatabase.throughput : 400
  209. autoscaleSettingsMaxThroughput: contains(sqlDatabase, 'autoscaleSettingsMaxThroughput') ? sqlDatabase.autoscaleSettingsMaxThroughput : -1
  210. }
  211. }]
  212. module databaseAccount_mongodbDatabases 'br/Storage:cosmosdb/mongo:v0.1' = [for mongodbDatabase in mongodbDatabases: {
  213. name: '${uniqueString(deployment().name, location)}-mongodb-${mongodbDatabase.name}'
  214. params: {
  215. databaseAccountName: databaseAccount.name
  216. name: mongodbDatabase.name
  217. collections: contains(mongodbDatabase, 'collections') ? mongodbDatabase.collections : []
  218. }
  219. }]
  220. module databaseAccount_gremlinDatabases 'br/Storage:cosmosdb/gremlin:v0.1' = [for gremlinDatabase in gremlinDatabases: {
  221. name: '${uniqueString(deployment().name, location)}-gremlin-${gremlinDatabase.name}'
  222. params: {
  223. databaseAccountName: databaseAccount.name
  224. name: gremlinDatabase.name
  225. graphs: contains(gremlinDatabase, 'graphs') ? gremlinDatabase.graphs : []
  226. }
  227. }]
  228. ////////////////////////////////////////////////////////////////////
  229. //Assign Private Endpoint to the Storage account sub resource type//
  230. ////////////////////////////////////////////////////////////////////
  231. module privateEndpointsModule 'br/Network:privateendpoint:v0.1' = [for endpoint in privateEndpoints: {
  232. name: 'pep-${endpoint.name}-${uniqueString(endpoint.name, location)}'
  233. scope: endpoint.resourceGroup != '' ? resourceGroup(endpoint.resourceGroup) : resourceGroup()
  234. params: {
  235. name: endpoint.name
  236. location: location
  237. serviceResourceId: databaseAccount.id
  238. subnetResourceId: resourceId(endpoint.subnet.virtualNetworkResourceGroupName, 'Microsoft.Network/virtualNetworks/subnets', endpoint.subnet.virtualNetworkName, endpoint.subnet.name)
  239. ipConfigurations: endpoint.ipConfigurations
  240. groupIds: endpoint.groupIds
  241. privateDnsZoneGroup: {
  242. name: endpoint.privateDns.name
  243. privateDNSResourceIds: [resourceId(endpoint.privateDns.resourceGroupName != '' ? endpoint.privateDns.resourceGroupName : resourceGroup().name, 'Microsoft.Network/privateDnsZones/', endpoint.privateDns.name)]
  244. }
  245. tags: endpoint.tags
  246. }
  247. }]
  248. @description('The name of the database account.')
  249. output name string = databaseAccount.name
  250. @description('The resource ID of the database account.')
  251. output id string = databaseAccount.id
  252. @description('The name of the resource group the database account was created in.')
  253. output resourceGroupName string = resourceGroup().name
  254. @description('The principal ID of the system assigned identity.')
  255. output systemAssignedPrincipalId string = systemAssignedIdentity && contains(databaseAccount.identity, 'principalId') ? databaseAccount.identity.principalId : ''
  256. @description('The location the resource was deployed into.')
  257. output location string = databaseAccount.location

CosmosSql.bicep

  1. @description('Conditional. The name of the parent Database Account. Required if the template is used in a standalone deployment.')
  2. param databaseAccountName string
  3. @description('Required. Name of the SQL database .')
  4. param name string
  5. @description('Optional. Array of containers to deploy in the SQL database.')
  6. param containers array = []
  7. @description('Optional. Request units per second. Will be set to null if autoscaleSettingsMaxThroughput is used.')
  8. param throughput int = 400
  9. @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.')
  10. param autoscaleSettingsMaxThroughput int = -1
  11. @description('Optional. Tags of the SQL database resource.')
  12. param tags object = {}
  13. @description('Optional. Enable telemetry via a Globally Unique Identifier (GUID).')
  14. var enableDefaultTelemetry = true
  15. resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (enableDefaultTelemetry) {
  16. name: 'pid-47ed15a6-730a-4827-bcb4-0fd963ffbd82-${uniqueString(deployment().name)}'
  17. properties: {
  18. mode: 'Incremental'
  19. template: {
  20. '$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
  21. contentVersion: '1.0.0.0'
  22. resources: []
  23. }
  24. }
  25. }
  26. resource databaseAccount 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' existing = {
  27. name: databaseAccountName
  28. }
  29. resource sqlDatabase 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2022-08-15' = {
  30. name: name
  31. parent: databaseAccount
  32. tags: tags
  33. properties: {
  34. resource: {
  35. id: name
  36. }
  37. options: contains(databaseAccount.properties.capabilities, { name: 'EnableServerless' }) ? null : {
  38. throughput: autoscaleSettingsMaxThroughput == -1 ? throughput : null
  39. autoscaleSettings: autoscaleSettingsMaxThroughput != -1 ? {
  40. maxThroughput: autoscaleSettingsMaxThroughput
  41. } : null
  42. }
  43. }
  44. }
  45. module container 'br/Storage:cosmosdb/sql/containers:v0.1' = [for container in containers: {
  46. name: '${uniqueString(deployment().name, sqlDatabase.name)}-sqldb-${container.name}'
  47. params: {
  48. databaseAccountName: databaseAccountName
  49. sqlDatabaseName: name
  50. name: container.name
  51. autoscaleSettingsMaxThroughput: contains(container, 'autoscaleSettingsMaxThroughput') ? container.autoscaleSettingsMaxThroughput : -1
  52. conflictResolutionPolicy: contains(container, 'conflictResolutionPolicy') ? container.conflictResolutionPolicy : {}
  53. defaultTtl: contains(container, 'defaultTtl') ? container.defaultTtl : -1
  54. indexingPolicy: contains(container, 'indexingPolicy') ? container.indexingPolicy : {}
  55. kind: contains(container, 'kind') ? container.kind : 'Hash'
  56. paths: contains(container, 'paths') ? container.paths : []
  57. throughput: contains(container, 'throughput') ? container.throughput : 400
  58. uniqueKeyPolicyKeys: contains(container, 'uniqueKeyPolicyKeys') ? container.uniqueKeyPolicyKeys : []
  59. }
  60. }]
  61. @description('The name of the SQL database.')
  62. output name string = sqlDatabase.name
  63. @description('The resource ID of the SQL database.')
  64. output resourceId string = sqlDatabase.id
  65. @description('The name of the resource group the SQL database was created in.')
  66. output resourceGroupName string = resourceGroup().name

CosmosSqlDbContainer.bicep

  1. @description('Required. The name of the parent Database Account. Required if the template is used in a standalone deployment.')
  2. param databaseAccountName string
  3. @description('Required. The name of the parent SQL Database. Required if the template is used in a standalone deployment.')
  4. param sqlDatabaseName string
  5. @description('Required. Name of the container.')
  6. param name string
  7. @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.')
  8. param conflictResolutionPolicy object = {}
  9. @maxValue(2147483647)
  10. @minValue(-1)
  11. @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.')
  12. param defaultTtl int = -1
  13. @description('Optional. Request Units per second. Will be set to null if autoscaleSettingsMaxThroughput is used.')
  14. param throughput int = 400
  15. @maxValue(1000000)
  16. @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.')
  17. param autoscaleSettingsMaxThroughput int = -1
  18. @description('Optional. Tags of the SQL Database resource.')
  19. param tags object = {}
  20. @description('Optional. List of paths using which data within the container can be partitioned.')
  21. param paths array = []
  22. @description('Optional. Indexing policy of the container.')
  23. param indexingPolicy object = {}
  24. @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.')
  25. param uniqueKeyPolicyKeys array = []
  26. @description('Optional. Indicates the kind of algorithm used for partitioning.')
  27. @allowed([
  28. 'Hash'
  29. 'MultiHash'
  30. 'Range'
  31. ])
  32. param kind string = 'Hash'
  33. var enableDefaultTelemetry = true
  34. resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (enableDefaultTelemetry) {
  35. name: 'pid-47ed15a6-730a-4827-bcb4-0fd963ffbd82-${uniqueString(deployment().name)}'
  36. properties: {
  37. mode: 'Incremental'
  38. template: {
  39. '$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
  40. contentVersion: '1.0.0.0'
  41. resources: []
  42. }
  43. }
  44. }
  45. resource databaseAccount 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' existing = {
  46. name: databaseAccountName
  47. resource sqlDatabase 'sqlDatabases@2021-07-01-preview' existing = {
  48. name: sqlDatabaseName
  49. }
  50. }
  51. resource container 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2022-08-15' = {
  52. name: name
  53. parent: databaseAccount::sqlDatabase
  54. tags: tags
  55. properties: {
  56. resource: {
  57. conflictResolutionPolicy: conflictResolutionPolicy
  58. defaultTtl: defaultTtl
  59. id: name
  60. indexingPolicy: !empty(indexingPolicy) ? indexingPolicy : null
  61. partitionKey: {
  62. paths: paths
  63. kind: kind
  64. }
  65. uniqueKeyPolicy: !empty(uniqueKeyPolicyKeys) ? {
  66. uniqueKeys: uniqueKeyPolicyKeys
  67. } : null
  68. }
  69. options: contains(databaseAccount.properties.capabilities, { name: 'EnableServerless' }) ? null : {
  70. throughput: autoscaleSettingsMaxThroughput == -1 ? throughput : null
  71. autoscaleSettings: autoscaleSettingsMaxThroughput != -1 ? {
  72. maxThroughput: autoscaleSettingsMaxThroughput
  73. } : null
  74. }
  75. }
  76. }
  77. @description('The name of the container.')
  78. output name string = container.name
  79. @description('The resource ID of the container.')
  80. output resourceId string = container.id
  81. @description('The name of the resource group the container was created in.')
  82. output resourceGroupName string = resourceGroup().name

答案1

得分: 1

这是要翻译的内容:

这实际上是一组主要为引用的模块做出贡献的 Microsoft 员工,而不是 Microsoft Bicep 团队。

我建议在该团队的存储库上提出问题以寻求建议。https://github.com/Azure/ResourceModules/issues

您收到的错误“analyticalStorageTtl 不是有效的属性”可能是因为底层资源提供程序发生了变化,而模块中出现了错误。即使您没有使用它,这些模块通常采取捕获每个可能的属性选项然后传递给底层资源声明的方法。这种方法确实提供了灵活性,但也会创建更大的错误表面 - 这通常在设计模块时应考虑到。

该项目通常建议您使用发布中的模块,而不是主分支...也许这也可以帮助您?

默认路径:为避免中断,使用可通过发布获得的不同版本。

英文:

It's actually collection of Microsoft Employees that predominantly contribute to the modules referenced, not the Microsoft Bicep team.

I'd suggest raising an issue on the repository for that team to advise. https://github.com/Azure/ResourceModules/issues

The error you're receiving analyticalStorageTtl is not a valid property is likely because the underlying resource provider has changed and a bug has crept into the modules. Even though you're not using it, those modules generally take an approach of capturing every possible property option and then relaying to the underlying resource declaration. This approach does give flexibility, but also creates a larger error surface area - something that generally should be factored in when designing modules.

The project generally advises you use modules from a release, rather than the main branch... Perhaps this might also help you?

> Default path: To avoid disruptions, use distinct versions available
> through releases.

huangapple
  • 本文由 发表于 2023年5月22日 22:12:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76307088.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定