fix: deployment stack name collisions for long deployment names#137
fix: deployment stack name collisions for long deployment names#137RISHABHJAIN27 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses Bug #4062 by making deployment stack name generation collision-resistant when long deployment names must be truncated to meet Azure’s 64-character limit, using a deterministic hash suffix while keeping existing names unchanged when they already fit within the limit.
Changes:
- Updated deployment stack name generation to add a deterministic hash suffix only when the legacy
prefix-basename exceeds 64 characters. - Implemented the same naming logic across local (
scripts-bicep), GitHub Actions, and Azure DevOps deployment flows. - Added a PowerShell validation script and documented how to run it to verify collision avoidance and length safety.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| alz/local/scripts-bicep/bicep-deploy.ps1 | Updates local deployment stack naming to use legacy-or-hash naming logic under the 64-char constraint. |
| alz/github/actions/bicep/templates/actions/bicep-deploy/action.yaml | Updates GitHub Actions deployment stack name generation to add deterministic hash suffix when needed. |
| alz/azuredevops/pipelines/bicep/templates/helpers/bicep-deploy.yaml | Updates Azure DevOps deployment stack name generation to add deterministic hash suffix when needed. |
| .github/tests/scripts/validate-deployment-stack-name-hash.ps1 | Adds a validation script to confirm backward-compatible behavior and collision prevention. |
| .github/tests/README.md | Documents how to run the new validation script from repo root. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $deploymentNameLegacy = "$deploymentPrefix-$deploymentNameOriginalBase" | ||
|
|
||
| if ($deploymentNameLegacy.Length -le 64) { | ||
| # Preserve legacy naming to keep backward compatibility when length already fits. | ||
| $deploymentName = $deploymentNameLegacy |
| } | ||
| $deploymentNameOriginalBase = $deploymentNameOriginalBase.Replace(" ", "-") | ||
| $deploymentNameHashLength = 10 | ||
| $deploymentNameSuffix = [System.BitConverter]::ToString([System.Security.Cryptography.SHA256]::HashData([System.Text.Encoding]::UTF8.GetBytes("$deploymentPrefix|$deploymentNameOriginalBase"))).Replace("-", "").Substring(0, $deploymentNameHashLength).ToLower() |
| $deploymentNameOriginalBase = $deploymentNameOriginalBase.Replace(" ", "-") | ||
|
|
||
| $deploymentNameHashLength = 10 | ||
| $deploymentNameSuffix = [System.BitConverter]::ToString([System.Security.Cryptography.SHA256]::HashData([System.Text.Encoding]::UTF8.GetBytes("$deploymentPrefix|$deploymentNameOriginalBase"))).Replace("-", "").Substring(0, $deploymentNameHashLength).ToLower() |
| $deploymentNameOriginalBase = $deploymentNameOriginalBase.Replace(" ", "-") | ||
|
|
||
| $deploymentNameHashLength = 10 | ||
| $deploymentNameSuffix = [System.BitConverter]::ToString([System.Security.Cryptography.SHA256]::HashData([System.Text.Encoding]::UTF8.GetBytes("$deploymentPrefix|$deploymentNameOriginalBase"))).Replace("-", "").Substring(0, $deploymentNameHashLength).ToLower() |
|
|
||
| $hashLength = 10 | ||
| $hashInput = "$DeploymentPrefix|$normalizedBase" | ||
| $hash = [System.BitConverter]::ToString([System.Security.Cryptography.SHA256]::HashData([System.Text.Encoding]::UTF8.GetBytes($hashInput))).Replace("-", "").Substring(0, $hashLength).ToLower() |
@microsoft-github-policy-service agree company="Microsoft" |
| 1. Legacy names are preserved when `prefix-base` length is within Azure's 64-character limit. | ||
| 2. Different long names (for example `stage-three` and `stage-four`) produce different final stack names. | ||
| 3. Final stack names remain within Azure's 64-character limit. | ||
| 4. Very long prefixes are trimmed safely while preserving the hash suffix when hash mode is required. |
Overview/Summary
Fixes Bug #4062 where deployment stack names can collide when long deployment names are truncated to satisfy Azure's 64-character limit.
The issue occurs when different deployment names share the same prefix and are truncated to an identical deployment stack name.
This PR fixes/adds/changes/removes
Breaking Changes
Testing Evidence
Local validation completed using:
pwsh ..github\tests\scripts\validate-deployment-stack-name-hash.ps1
Results: