Skip to content

Add availability zone check for Azure Managed Instance for Apache Cassandra#8

Closed
Copilot wants to merge 25 commits intomainfrom
copilot/check-availability-zones-cassandra
Closed

Add availability zone check for Azure Managed Instance for Apache Cassandra#8
Copilot wants to merge 25 commits intomainfrom
copilot/check-availability-zones-cassandra

Conversation

Copy link

Copilot AI commented Nov 12, 2025

PR Summary

Implements Azure.MICassandra.AvailabilityZone (AZR-000504) to validate that Managed Instance for Apache Cassandra data centers enable availability zones in supported regions.

Rule: Azure.MICassandra.AvailabilityZone (AZR-000504)
Resource Types: Microsoft.DocumentDB/cassandraClusters, Microsoft.DocumentDB/cassandraClusters/dataCenters
API Version: 2024-11-15 (latest stable)
Release: GA
Rule Set: 2025_12
Pillar: Reliability
Category: RE:05 Redundancy
Reviewed: 2025-11-13

The rule checks that Azure Managed Instance for Apache Cassandra data centers have properties.availabilityZone set to true in regions that support availability zones. The rule automatically passes for regions that don't support availability zones.

Key Features

  • Dedicated Rule File: Created Azure.MICassandra.Rule.ps1 for Managed Instance for Apache Cassandra rules
  • Helper Function: Implemented GetCassandraDataCenter function to handle both cluster and datacenter resources (similar to GetMariaDBFirewallRule)
  • Dual Resource Support: Rule evaluates both parent clusters (checking their nested datacenters) and standalone datacenter resources
  • Region-Aware: Uses VMSS zone mappings for region capability detection; auto-passes for regions without AZ support
  • Latest Stable API: Uses API version 2024-11-15 for all resources

Test Coverage

Comprehensive test scenarios include:

  1. Nested resources: Clusters with datacenters declared under the resources property (positioned at top of test file)
  2. Standalone datacenters: Top-level datacenter resources (positioned at bottom of test file)
  3. Mixed scenarios: Clusters with multiple datacenters (some with AZ, some without)
  4. Unsupported regions: Datacenters in regions without availability zone support (e.g., westindia)
  5. All combinations: With AZ enabled, without AZ enabled, in supported/unsupported regions

Test structure follows Cosmos.json organization pattern:

  • Nested resources first, standalone child resources last
  • Consistent naming: clusters as micassandra-{letter}, datacenters as datacenter-{letter} (sequential)
  • Complete metadata: ResourceId, Id, ResourceName, Name, ResourceGroupName, Type, ApiVersion, SubscriptionId
  • Reason assertions matching actual error messages

Test Results: 3 failures (expected) + 6 passes (expected) = 9 resources validated with reason assertions ✅

Files Changed

  • New: src/PSRule.Rules.Azure/rules/Azure.MICassandra.Rule.ps1 (with helper function)
  • New: tests/PSRule.Rules.Azure.Tests/Azure.MICassandra.Tests.ps1 (comprehensive test coverage with reason assertions)
  • New: tests/PSRule.Rules.Azure.Tests/Resources.MICassandra.json (9 test resources using API version 2024-11-15)
  • New: docs/en/rules/Azure.MICassandra.AvailabilityZone.md (rule documentation with ARM, Bicep examples using API version 2024-11-15)
  • Updated: src/PSRule.Rules.Azure/en/PSRule-rules.psd1 (localization strings)
  • Updated: docs/changelog.md (change log entry)

Example

resource dataCenter 'Microsoft.DocumentDB/cassandraClusters/dataCenters@2024-11-15' = {
  properties: {
    availabilityZone: true  // Required in supported regions
    // ...
  }
}

PR Checklist

Original prompt

Check for availability zones for Azure Managed Instance for Apache Cassandra Azure#3592

Created from VS Code via the GitHub Pull Request extension.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Nov 12, 2025
Copilot AI and others added 2 commits November 12, 2025 11:49
Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>
Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>
Copilot AI changed the title [WIP] Check availability zones for Azure Managed Instance Add availability zone check for Azure Managed Instance for Apache Cassandra Nov 12, 2025
AZR-000498 | [Azure.AppConfig.ReplicaLocation](Azure.AppConfig.ReplicaLocation.md) | The replication location determines the country or region where configuration data is stored and processed. | GA
AZR-000499 | [Azure.Cosmos.MongoEntraID](Azure.Cosmos.MongoEntraID.md) | Cosmos DB accounts should use Entra ID authentication. | GA
AZR-000502 | [Azure.Cosmos.AvailabilityZone](Azure.Cosmos.AvailabilityZone.md) | Use zone redundant Cosmos DB accounts in supported regions to improve reliability. | GA
AZR-000503 | [Azure.Cassandra.AvailabilityZone](Azure.Cassandra.AvailabilityZone.md) | Deploy Azure Managed Instance for Apache Cassandra data centers using availability zones in supported regions to ensure high availability and resilience. | GA
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Remove the changes you have done in this file. This file should not be edited as a part of this PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Reverted all changes to docs/en/rules/index.md in commit 1c27cec.

---
severity: Important
pillar: Reliability
category: RE:05 Regions and availability zones
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot RE:05 Redundancy

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to RE:05 Redundancy in commit 1c27cec.

…E:05 Redundancy

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>
Copy link
Owner

@BenjaminEngeset BenjaminEngeset left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Lets move it out to an own dedicated rule file as the Azure Managed Instance for Apache Cassandra does not really fit into Cosmos DB.

Lets call it Azure.MICassandra.Rule.ps1 and the rule should be named Azure.MICassandra.AvailabliityZone.

Resources file should be Resources.MICassandra.json

… file

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 12, 2025

@copilot Lets move it out to an own dedicated rule file as the Azure Managed Instance for Apache Cassandra does not really fit into Cosmos DB.

Lets call it Azure.MICassandra.Rule.ps1 and the rule sho...

Done. Moved to dedicated Azure.MICassandra.Rule.ps1 file with rule named Azure.MICassandra.AvailabilityZone. Resources file is now Resources.MICassandra.json and test file is Azure.MICassandra.Tests.ps1. All tests passing. See commit 949104f.

#region Rules

# Synopsis: Deploy Azure Managed Instance for Apache Cassandra data centers using availability zones in supported regions to ensure high availability and resilience.
Rule 'Azure.MICassandra.AvailabilityZone' -Ref 'AZR-000503' -Type 'Microsoft.DocumentDB/cassandraClusters/dataCenters' -Tag @{ release = 'GA'; ruleSet = '2025_12'; 'Azure.WAF/pillar' = 'Reliability'; } -Labels @{ 'Azure.WAF/maturity' = 'L1' } {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Change to AZR-000504. AZR-000503 is already taken in another PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to AZR-000504 in commit 13f837b.

Comment on lines 78 to 111
### Configure with Azure CLI

To enable availability zones for a Cassandra data center:

```bash
az managed-cassandra datacenter create \
--resource-group $resourceGroupName \
--cluster-name $clusterName \
--data-center-name $dataCenterName \
--data-center-location $location \
--delegated-subnet-id $delegatedSubnetId \
--node-count 3 \
--sku Standard_E8s_v5 \
--disk-capacity 4 \
--availability-zone true
```

### Configure with Azure PowerShell

To enable availability zones for a Cassandra data center:

```powershell
New-AzManagedCassandraDatacenter `
-ResourceGroupName $resourceGroupName `
-ClusterName $clusterName `
-DataCenterName $dataCenterName `
-Location $location `
-DelegatedSubnetId $delegatedSubnetId `
-NodeCount 3 `
-Sku Standard_E8s_v5 `
-DiskCapacity 4 `
-UseAvailabilityZone $true
```

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Remove this part.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed Azure PowerShell section in commit 13f837b.

Comment on lines 114 to 120
This rule applies when analyzing resources deployed to Azure using *pre-flight* and *in-flight* data.

This rule fails when `properties.availabilityZone` is `false` or not set when there are availability zones available for the given region.

Availability zones are not supported in all Azure regions.
Deployments will fail if you select a region where availability zones are not supported.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Remove this.

Write instead This rule only applies to Azure Managed Instance for Apache Cassandra deployment model.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated NOTES section with the specified text in commit 13f837b.

Comment on lines 123 to 126
- [RE:05 Regions and availability zones](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)
- [Create an Azure Managed Instance for Apache Cassandra cluster](https://learn.microsoft.com/azure/managed-instance-apache-cassandra/create-cluster-cli)
- [Azure regions with availability zones](https://learn.microsoft.com/azure/reliability/availability-zones-region-support)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated LINKS section with the specified Well-Architected Framework links in commit 13f837b.

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>
pillar: Reliability
category: RE:05 Redundancy
resource: Azure Managed Instance for Apache Cassandra
resourceType: Microsoft.DocumentDB/cassandraClusters
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Is it possible to add multiple resources here? So also add Microsoft.DocumentDB cassandraClusters/dataCenters if possible

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, added both resource types: Microsoft.DocumentDB/cassandraClusters, Microsoft.DocumentDB/cassandraClusters/dataCenters in commit cd53d4b.

Comment on lines 10 to 11
# Managed Instance for Apache Cassandra data centers should use Availability zones in supported regions

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Use zone redundant Azure Managed Instance for Apache Cassandra clusters

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated title to "Use zone redundant Azure Managed Instance for Apache Cassandra clusters" in commit cd53d4b.


## SYNOPSIS

Deploy Azure Managed Instance for Apache Cassandra data centers using availability zones in supported regions to ensure high availability and resilience.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Use zone redundant Azure Managed Instance for Apache Cassandra clusters in supported regions to improve reliability.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated SYNOPSIS to match the specified text in commit cd53d4b.


## RECOMMENDATION

Consider enabling availability zones for Azure Managed Instance for Apache Cassandra data centers deployed in supported regions.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Consider using locations configured with zone redundancy to improve workload resiliency of Azure Managed Instance for Apache Cassandra clusters.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated RECOMMENDATION to the specified text in commit cd53d4b.


### Configure with Azure template

To enable availability zones for a Cassandra data center:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot To deploy clusters that pass this rule:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated EXAMPLES section to use "To deploy clusters that pass this rule:" in commit cd53d4b.

Comment on lines 78 to 94
### Configure with Azure CLI

To enable availability zones for a Cassandra data center:

```bash
az managed-cassandra datacenter create \
--resource-group $resourceGroupName \
--cluster-name $clusterName \
--data-center-name $dataCenterName \
--data-center-location $location \
--delegated-subnet-id $delegatedSubnetId \
--node-count 3 \
--sku Standard_E8s_v5 \
--disk-capacity 4 \
--availability-zone true
```

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Remove this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed Azure CLI section in commit cd53d4b.

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>
…smos pattern

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 13, 2025

@copilot Lets name the clusters instead micassandra-a, b, c etc. For the datacenters use datacenter-a, b, c etc.

Looks like you also have forgotten this for the file as well. "ResourceGroupName": "te...

Refactored test resources in commit 170767d:

Naming updates:

  • Clusters: micassandra-a, micassandra-b, micassandra-c, etc.
  • Datacenters: datacenter-a, datacenter-b, datacenter-c, etc.

Structure improvements following Resources.Cosmos.json pattern:

  • Added ResourceId, Id, ResourceName, Name
  • Added ResourceGroupName: "test-rg"
  • Added Type: "Microsoft.DocumentDB/cassandraClusters" or "Microsoft.DocumentDB/cassandraClusters/dataCenters"
  • Added SubscriptionId: "00000000-0000-0000-0000-000000000000"
  • Consistent capitalization (e.g., Location, Properties, Tags)

All tests passing ✅

Copy link
Owner

@BenjaminEngeset BenjaminEngeset left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot The ordering is a bit off. Eg micassandra-i/datacenter-k can be micassandra-i/datacenter-a is it will have a unique name. It doesnt make sense to randomely use k when a doesn't exist. Also add the reason in the test, just like the test for cosmos db.

Also look on cosmos db test, child resorces that is standalone is always configured in the bottom of the json file and when nested within, its on top of the file. This makes better and clearer structure.

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 14, 2025

@copilot The ordering is a bit off. Eg micassandra-i/datacenter-k can be micassandra-i/datacenter-a is it will have a unique name. It doesnt make sense to randomely use k when a doesn't exist. Also ad...

Reorganized test resources and added reason assertions in commit 25a60cd:

Structure improvements:

  • Nested resources now at top (micassandra-a through micassandra-d with nested datacenters)
  • Standalone child resources at bottom (micassandra-e/datacenter-a, micassandra-f/datacenter-a, micassandra-g/datacenter-a)
  • Fixed datacenter naming to use consistent sequencing (datacenter-a, datacenter-b, etc. instead of jumping to random letters)

Added reason assertions matching Cosmos DB pattern:

  • $ruleResult[0].Reason validates exact error message format
  • Checks for proper datacenter name and region in failure messages
  • All 3 failure cases now have reason validation

Test coverage: 9 resources (3 expected failures with validated reasons, 6 passes) ✅

Copy link
Owner

@BenjaminEngeset BenjaminEngeset left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Look on my comment and do the same for the rest of the file.

Copy link
Author

Copilot AI commented Nov 14, 2025

@copilot Look on my comment and do the same for the rest of the file.

The datacenter naming has been corrected in commit 25a60cd. All clusters now have their datacenters named sequentially starting with datacenter-a (micassandra-a has datacenter-a and datacenter-b, micassandra-b has datacenter-a, micassandra-c has datacenter-a and datacenter-b, etc.). The file structure also follows the Cosmos DB pattern with nested resources at the top and standalone child resources at the bottom.

Copy link
Owner

@BenjaminEngeset BenjaminEngeset left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot I've made some minor adjustments. Make sure the resources file uses the latest stable api there is.

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 14, 2025

@copilot I've made some minor adjustments. Make sure the resources file uses the latest stable api there is.

Updated all resources to use the latest stable API version 2024-11-15. Added ApiVersion field to all cluster and datacenter resources in the test file, and updated the documentation examples to match. See commit 04ea23c.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • learn.microsoft.com
    • Triggering command: curl -s REDACTED (dns block)
  • management.azure.com
    • Triggering command: /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/PSRule.Rules.Azure/PSRule.Rules.Azure/tests/PSRule.Rules.Azure.Tests/bin/Debug/net8.0/PSRule.Rules.Azure.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/PSRule.Rules.Azure/PSRule.Rules.Azure/tests/PSRule.Rules.Azure.Tests/bin/Debug/net8.0/PSRule.Rules.Azure.Tests.deps.json /home/REDACTED/work/PSRule.Rules.Azure/PSRule.Rules.Azure/tests/PSRule.Rules.Azure.Tests/bin/Debug/net8.0/testhost.dll --port 33045 --endpoint 127.0.0.1:033045 --role client --parentprocessid 5120 --telemetryoptedin false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

BenjaminEngeset and others added 4 commits November 14, 2025 14:11
* Initial plan

* Add rule Azure.Cosmos.MongoDBvCoreAvailabilityZone for issue Azure#3586

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>

* Address PR feedback: rename rule, add region check, create helper function

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>

* Use $PSRule.TargetType instead of parameter in helper function

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>

* Fix test to show actual region name and reorder test cases

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>

* Update documentation and add comprehensive test scenarios

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>

* Improve documentation description and recommendation sections

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>

* Use 'cluster' terminology for MongoDB vCore and fix documentation formatting

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>

* Update test data and fix LINKS order in documentation

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>

* Add NOTES section to documentation

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>

* Add explicit Pass for regions without AZ support and test case

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>

* Update src/PSRule.Rules.Azure/en/PSRule-rules.psd1

Co-authored-by: Bernie White <bewhite@microsoft.com>

* Update docs/en/rules/Azure.Cosmos.MongoAvailabilityZone.md

Co-authored-by: Bernie White <bewhite@microsoft.com>

* remove helper function

* Update test expectations to match new localized string

Co-authored-by: BenjaminEngeset <99641908+BenjaminEngeset@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Bernie White <bewhite@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants