forked from Azure/PSRule.Rules.Azure
-
Notifications
You must be signed in to change notification settings - Fork 0
Add availability zone check for Azure Managed Instance for Apache Cassandra #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
459461f
Initial plan
Copilot d5b9093
Add Azure.Cassandra.AvailabilityZone rule and tests
Copilot c43e635
Add documentation for Azure.Cassandra.AvailabilityZone rule
Copilot 1c27cec
Address PR feedback: revert index.md changes and update category to R…
Copilot 949104f
Refactor: Move Cassandra rule to dedicated Azure.MICassandra.Rule.ps1…
Copilot 13f837b
Update rule reference to AZR-000504 and refine documentation
Copilot cd53d4b
Refine documentation with review date and improved content structure
Copilot 5c0aab0
Add helper function and support for both cluster and datacenter resou…
Copilot d0e4e6e
update rule logic
BenjaminEngeset b2a671d
Update test cases to match refactored rule logic
Copilot 2496cb9
updates
BenjaminEngeset bc6b082
fix
BenjaminEngeset d38ef32
property
BenjaminEngeset 1917338
output type
BenjaminEngeset 5d63a07
Add comprehensive test cases with nested and standalone datacenter sc…
Copilot 170767d
Refactor test resources with proper naming and structure following Co…
Copilot 25a60cd
Reorganize test resources and add reason assertions
Copilot 2cc30b5
fix
BenjaminEngeset 0b775db
adjustments
BenjaminEngeset 1161d92
subnet
BenjaminEngeset 04ea23c
Update API version to latest stable (2024-11-15)
Copilot 6174398
fix
BenjaminEngeset 0a53edc
Added Azure.Cosmos.MongoAvailabilityZone (#3589)
BenjaminEngeset d4b59d0
Merge branch 'main' into copilot/check-availability-zones-cassandra
BernieWhite 6bdcbda
Minor doc tweaks
BernieWhite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| --- | ||
| reviewed: 2025-11-10 | ||
| severity: Important | ||
| pillar: Reliability | ||
| category: RE:05 Redundancy | ||
| resource: Cosmos DB | ||
| resourceType: Microsoft.DocumentDB/mongoClusters | ||
| online version: https://azure.github.io/PSRule.Rules.Azure/en/rules/Azure.Cosmos.MongoAvailabilityZone/ | ||
| --- | ||
|
|
||
| # Use zone redundant Cosmos DB MongoDB vCore clusters | ||
|
|
||
| ## SYNOPSIS | ||
|
|
||
| Use zone redundant Cosmos DB vCore clusters in supported regions to improve reliability. | ||
|
|
||
| ## DESCRIPTION | ||
|
|
||
| Azure Cosmos DB for MongoDB vCore clusters support zone redundancy. | ||
| When zone redundancy is enabled, your data is replicated across multiple zones within an Azure region. | ||
|
|
||
| Availability zones are unique physical locations within an Azure region. | ||
| Each zone is made up of one or more datacenters equipped with independent power, cooling, and networking infrastructure. | ||
| This physical separation ensures that if one zone experiences an outage, | ||
| your Cosmos DB cluster continues to serve read and write requests from replicas in other zones without downtime. | ||
|
|
||
| With zone redundancy enabled, Azure Cosmos DB provides: | ||
|
|
||
| - Automatic failover between zones. | ||
| - Continuous availability during zonal failures. | ||
| - Enhanced durability by maintaining multiple copies across separate physical locations. | ||
| - Protection against datacenter-level disasters while maintaining low-latency access. | ||
|
|
||
| Zone redundancy must be configured when you create a Cosmos DB cluster by setting `highAvailability.targetMode` to `ZoneRedundantPreferred`. | ||
| This setting cannot be changed after the account is created. | ||
| Zone redundancy is only available in regions that support availability zones. | ||
|
|
||
| ## RECOMMENDATION | ||
|
|
||
| Consider configuring zone redundant high availability in locations that support availability zones to improve reliability. | ||
|
|
||
| ## EXAMPLES | ||
|
|
||
| ### Configure with Azure template | ||
|
|
||
| To deploy MongoDB vCore clusters that pass this rule: | ||
|
|
||
| - Set the `properties.highAvailability.targetMode` property to `ZoneRedundantPreferred`. | ||
|
|
||
| For example: | ||
|
|
||
| ```json | ||
| { | ||
| "type": "Microsoft.DocumentDB/mongoClusters", | ||
| "apiVersion": "2024-07-01", | ||
| "name": "[parameters('name')]", | ||
| "location": "[parameters('location')]", | ||
| "properties": { | ||
| "serverVersion": "8.0", | ||
| "authConfig": { | ||
| "allowedModes": [ | ||
| "MicrosoftEntraID" | ||
| ] | ||
| }, | ||
| "compute": { | ||
| "tier": "M30" | ||
| }, | ||
| "storage": { | ||
| "sizeGb": 128, | ||
| "type": "PremiumSSD" | ||
| }, | ||
| "highAvailability": { | ||
| "targetMode": "ZoneRedundantPreferred" | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Configure with Bicep | ||
|
|
||
| To deploy MongoDB vCore clusters that pass this rule: | ||
|
|
||
| - Set the `properties.highAvailability.targetMode` property to `ZoneRedundantPreferred`. | ||
|
|
||
| For example: | ||
|
|
||
| ```bicep | ||
| resource mongoCluster 'Microsoft.DocumentDB/mongoClusters@2024-07-01' = { | ||
| name: name | ||
| location: location | ||
| properties: { | ||
| serverVersion: '8.0' | ||
| authConfig: { | ||
| allowedModes: [ | ||
| 'MicrosoftEntraID' | ||
| ] | ||
| } | ||
| compute: { | ||
| tier: 'M30' | ||
| } | ||
| storage: { | ||
| sizeGb: 128 | ||
| type: 'PremiumSSD' | ||
| } | ||
| highAvailability: { | ||
| targetMode: 'ZoneRedundantPreferred' | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## NOTES | ||
|
|
||
| This rule applies to Cosmos DB for MongoDB clusters deployed with the vCore deployment model. | ||
|
|
||
| ## LINKS | ||
|
|
||
| - [RE:05 Redundancy](https://learn.microsoft.com/azure/well-architected/reliability/redundancy) | ||
| - [Azure regions with availability zone support](https://learn.microsoft.com/azure/reliability/availability-zones-service-support) | ||
| - [Reliability: Level 1](https://learn.microsoft.com/azure/well-architected/reliability/maturity-model?tabs=level1) | ||
| - [Architecture strategies for using availability zones and regions](https://learn.microsoft.com/azure/well-architected/reliability/regions-availability-zones) | ||
| - [High availability in Azure Cosmos DB for MongoDB vCore](https://learn.microsoft.com/azure/cosmos-db/mongodb/vcore/high-availability) | ||
| - [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.documentdb/mongoclusters) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| --- | ||
| reviewed: 2025-11-14 | ||
| severity: Important | ||
| pillar: Reliability | ||
| category: RE:05 Redundancy | ||
| resource: Managed Instance for Apache Cassandra | ||
| resourceType: Microsoft.DocumentDB/cassandraClusters,Microsoft.DocumentDB/cassandraClusters/dataCenters | ||
| online version: https://azure.github.io/PSRule.Rules.Azure/en/rules/Azure.MICassandra.AvailabilityZone/ | ||
| --- | ||
|
|
||
| # Use zone redundant Managed Instance for Apache Cassandra clusters | ||
|
|
||
| ## SYNOPSIS | ||
|
|
||
| Use zone redundant Managed Instance for Apache Cassandra clusters in supported regions to improve reliability. | ||
|
|
||
| ## DESCRIPTION | ||
BenjaminEngeset marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Managed Instance for Apache Cassandra supports zone redundancy through availability zones. | ||
| When availability zones are enabled, nodes are physically separated across multiple zones within an Azure region. | ||
|
|
||
| Availability zones are unique physical locations within an Azure region. | ||
| Each zone is made up of one or more datacenters equipped with independent power, cooling, and networking infrastructure. | ||
| This physical separation ensures that if one zone experiences an outage, | ||
| your Cassandra cluster continues to serve read and write requests from nodes in other zones without downtime. | ||
|
|
||
| With zone redundancy enabled, Managed Instance for Apache Cassandra provides: | ||
|
|
||
| - Automatic distribution of nodes across zones. | ||
| - Continuous availability during zonal failures. | ||
| - Enhanced durability by maintaining multiple replicas across separate physical locations. | ||
| - Protection against datacenter-level disasters while maintaining low-latency access. | ||
|
|
||
| Zone redundancy must be configured when you create a data center by setting `availabilityZone` to `true`. | ||
| This setting cannot be changed after the datacenter is created. | ||
| Zone redundancy is only available in regions that support availability zones. | ||
|
|
||
| ## RECOMMENDATION | ||
|
|
||
| Consider enabling availability zones for data center clusters that support them to improve workload resiliency. | ||
|
|
||
| ## EXAMPLES | ||
|
|
||
| ### Configure with Azure template | ||
|
|
||
| To deploy clusters that pass this rule: | ||
|
|
||
| - Set `properties.availabilityZone` to `true`. | ||
|
|
||
| For example: | ||
|
|
||
| ```json | ||
| { | ||
| "type": "Microsoft.DocumentDB/cassandraClusters/dataCenters", | ||
| "apiVersion": "2024-11-15", | ||
| "name": "[format('{0}/{1}', parameters('clusterName'), parameters('dataCenterName'))]", | ||
| "location": "[parameters('location')]", | ||
| "properties": { | ||
| "dataCenterLocation": "[parameters('location')]", | ||
| "delegatedSubnetId": "[parameters('delegatedSubnetId')]", | ||
| "nodeCount": 3, | ||
| "sku": "Standard_E8s_v5", | ||
| "diskCapacity": 4, | ||
| "availabilityZone": true | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Configure with Bicep | ||
|
|
||
| To deploy clusters that pass this rule: | ||
|
|
||
| - Set `properties.availabilityZone` to `true`. | ||
|
|
||
| For example: | ||
|
|
||
| ```bicep | ||
| resource dataCenter 'Microsoft.DocumentDB/cassandraClusters/dataCenters@2024-11-15' = { | ||
| parent: cluster | ||
| name: datacenterName | ||
| location: location | ||
| properties: { | ||
| dataCenterLocation: location | ||
| delegatedSubnetId: delegatedSubnetId | ||
| nodeCount: 3 | ||
| sku: 'Standard_E8s_v5' | ||
| diskCapacity: 4 | ||
| availabilityZone: true | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## NOTES | ||
|
|
||
| This rule only applies to Managed Instance for Apache Cassandra deployment model. | ||
|
|
||
| ## LINKS | ||
|
|
||
| - [RE:05 Redundancy](https://learn.microsoft.com/azure/well-architected/reliability/redundancy) | ||
| - [Azure regions with availability zone support](https://learn.microsoft.com/azure/reliability/availability-zones-service-support) | ||
| - [Reliability: Level 1](https://learn.microsoft.com/azure/well-architected/reliability/maturity-model?tabs=level1) | ||
| - [Architecture strategies for using availability zones and regions](https://learn.microsoft.com/azure/well-architected/reliability/regions-availability-zones) | ||
| - [Best practices for high availability and disaster recovery](https://learn.microsoft.com/azure/managed-instance-apache-cassandra/resilient-applications) | ||
| - [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.documentdb/cassandraclusters/datacenters) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| # | ||
| # Validation rules for Azure Managed Instance for Apache Cassandra | ||
| # | ||
|
|
||
| #region Rules | ||
|
|
||
| # Synopsis: Use zone redundant Azure Managed Instance for Apache Cassandra clusters in supported regions to improve reliability. | ||
| Rule 'Azure.MICassandra.AvailabilityZone' -Ref 'AZR-000504' -Type 'Microsoft.DocumentDB/cassandraClusters', 'Microsoft.DocumentDB/cassandraClusters/dataCenters' -Tag @{ release = 'GA'; ruleSet = '2025_12'; 'Azure.WAF/pillar' = 'Reliability'; } -Labels @{ 'Azure.WAF/maturity' = 'L1' } { | ||
| # Check for availability zones based on virtual machine scale sets, because it is not exposed through the provider for Managed Instance for Apache Cassandra. | ||
| $provider = [PSRule.Rules.Azure.Runtime.Helper]::GetResourceType('Microsoft.Compute', 'virtualMachineScaleSets') | ||
|
|
||
| $dataCenters = @(GetCassandraDataCenter) | ||
| if ($dataCenters.Count -eq 0) { | ||
| return $Assert.Pass() | ||
| } | ||
|
|
||
| foreach ($dataCenter in $dataCenters) { | ||
| $availabilityZones = GetAvailabilityZone -Location $dataCenter.properties.dataCenterLocation -Zone $provider.ZoneMappings | ||
|
|
||
| if ($availabilityZones) { | ||
| $Assert.HasFieldValue($dataCenter, 'properties.availabilityZone', $true). | ||
| ReasonFrom( | ||
| 'properties.availabilityZone', | ||
| $LocalizedData.MICassandraAvailabilityZone, | ||
| $dataCenter.name, | ||
| $dataCenter.properties.dataCenterLocation | ||
| ) | ||
| } | ||
| # Don't flag if the region does not support availability zones. | ||
| else { | ||
| $Assert.Pass() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #endregion Rules | ||
|
|
||
| #region Helper functions | ||
|
|
||
| function global:GetCassandraDataCenter { | ||
| [CmdletBinding()] | ||
| param () | ||
| process { | ||
| if ($PSRule.TargetType -eq 'Microsoft.DocumentDB/cassandraClusters') { | ||
| GetSubResources -ResourceType 'Microsoft.DocumentDB/cassandraClusters/dataCenters' | ||
| } | ||
| elseif ($PSRule.TargetType -eq 'Microsoft.DocumentDB/cassandraClusters/dataCenters') { | ||
| $TargetObject | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #endregion Helper functions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.