Fix: Enable Flexible Availability Zone Configuration for Reliable Re-deployments #847
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.
Problem
Re-deploying AVD Landing Zone Accelerator would fail with validation errors when attempting to change availability zone configurations between deployments. Users encountered the error:
The Azure Portal would display a warning: "The template has specified a default value which is not present in the list of allowed values" for the Availability Zones field (see screenshot in issue).
This issue occurred specifically when:
The deployment failure forced teams to manually delete all resources and redeploy from scratch, adding hours of manual cleanup work and scheduling friction during iterative customer deployments.
Root Cause
Three interrelated issues caused the deployment failures:
Overly Restrictive Parameter Validation: The
availabilityZonesparameter used@allowed(['1', '2', '3'])decorators that enforced an exact match to all three zones. This prevented deployments in regions that support only a subset of zones or no zones at all.Static Portal UI Defaults: The portal UI definition (
portal-ui-baseline.json) had hardcoded default values["Zone 1", "Zone 2", "Zone 3"]that didn't adapt to the actual zones available in the selected region. When the region didn't support all three zones, the default value wouldn't match the dynamically generated list of allowed values.Missing Defensive Logic: The session hosts deployment module (
avdSessionHosts/deploy.bicep) didn't safely handle empty availability zone arrays, which could cause array access errors whenlength(varZones)was zero.Solution
This PR implements minimal, surgical changes to enable flexible availability zone configuration:
Bicep Parameter Flexibility
Files Modified:
deploy-baseline.bicep,brownfield/newSessionHosts/deploy.bicepRemoved the restrictive
@allowed(['1', '2', '3'])decorator and updated parameter descriptions to clarify support for flexible configurations:This enables valid configurations like:
['1', '2', '3']- All zones (default)['1', '2']- Subset of zones['1']- Single zone[]- No zones (for non-zoned regions)Dynamic Portal UI Defaults
Files Modified:
portal-ui-baseline.json,portalUiNewSessionHosts.jsonChanged the Availability Zones dropdown from static defaults to dynamic defaults that match the region's actual capabilities:
This ensures the default value is always synchronized with the allowed values list, preventing validation mismatches.
Defensive Empty Array Handling
File Modified:
avdSessionHosts/deploy.bicepAdded a safety check before accessing the zones array:
This prevents division-by-zero and array access errors when the zones array is empty.
Testing
All modified Bicep files validated successfully with Azure CLI:
Portal UI JSON files validated with Python json.tool.
Impact
This fix enables:
✅ Reliable re-deployments across regions with different availability zone configurations
✅ Elimination of manual cleanup - no more forced resource deletion after failed deployments
✅ Flexible deployment options - supports all zones, subset of zones, or no zones
✅ Improved user experience - portal UI adapts to actual region capabilities
✅ Full backward compatibility - existing deployments with three zones continue to work unchanged
Related Issues
Addresses the core blocker described in the "Redeploy with Cleanup" feature request by eliminating the validation failures that forced manual resource cleanup and prevented iterative deployments during customer working sessions.
Files Changed: 5 files (23 lines removed, 6 lines added)
workload/bicep/deploy-baseline.bicepworkload/bicep/brownfield/newSessionHosts/deploy.bicepworkload/bicep/modules/avdSessionHosts/deploy.bicepworkload/portal-ui/portal-ui-baseline.jsonworkload/portal-ui/brownfield/portalUiNewSessionHosts.jsonWarning
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:
aka.msbicep build /home/REDACTED/work/avdaccelerator/avdaccelerator/workload/bicep/deploy-baseline.bicep(dns block)bicep build /home/REDACTED/work/avdaccelerator/avdaccelerator/workload/bicep/brownfield/newSessionHosts/deploy.bicep(dns block)bicep build /home/REDACTED/work/avdaccelerator/avdaccelerator/workload/bicep/modules/avdSessionHosts/deploy.bicep(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Fixes #838
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.