Skip to content

fix: deployment stack name collisions for long deployment names#137

Open
RISHABHJAIN27 wants to merge 2 commits into
mainfrom
fix/4062-deployment-stack-name-collision
Open

fix: deployment stack name collisions for long deployment names#137
RISHABHJAIN27 wants to merge 2 commits into
mainfrom
fix/4062-deployment-stack-name-collision

Conversation

@RISHABHJAIN27

Copy link
Copy Markdown

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

  1. Adds deterministic hash-suffix generation for deployment stack names when the generated name exceeds Azure limits.
  2. Preserves existing deployment stack names when the generated name is already within the 64-character limit.
  3. Adds validation script and documentation to verify collision prevention and backward-compatible behavior.

Breaking Changes

  1. None.
  2. Existing deployment stack names that are already within Azure limits remain unchanged.

Testing Evidence

Local validation completed using:

pwsh ..github\tests\scripts\validate-deployment-stack-name-hash.ps1

Results:

  • Existing deployment stack names within Azure limits remain unchanged.
  • Stage Three and Stage Four collision scenario now generate different deployment stack names.
  • Generated deployment stack names remain within Azure's 64-character limit.
  • Validation passed successfully.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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-base name 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.

Comment on lines +43 to +47
$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()
@RISHABHJAIN27

Copy link
Copy Markdown
Author

@RISHABHJAIN27 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree company="Microsoft"

@RISHABHJAIN27 RISHABHJAIN27 changed the title Fix deployment stack name collisions for long deployment names fix: deployment stack name collisions for long deployment names Jul 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread .github/tests/README.md
Comment on lines +45 to +48
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants