Skip to content

Fix Azure roles resources always redeploying - #12901

Merged
Eric Erhardt (eerhardt) merged 2 commits into
microsoft:mainfrom
eerhardt:FixRolesRedeploy
Nov 13, 2025
Merged

Fix Azure roles resources always redeploying#12901
Eric Erhardt (eerhardt) merged 2 commits into
microsoft:mainfrom
eerhardt:FixRolesRedeploy

Conversation

@eerhardt

Copy link
Copy Markdown
Member

Description

Everytime we check if we need to redeploy an Azure "roles" resource in run mode, we are getting a different CheckSum. This is because we are overwriting the "known parameters" like PrincipalId and PrincipalType with 'null' values, because these values aren't available yet.

The fix is to skip setting those known parameters, like we did in previous versions.

Fix #12651

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
  • Did you add public API?
    • No
  • Does the change make any security assumptions or guarantees?
    • No
  • Does the change require an update in our Aspire docs?
    • No

Everytime we check if we need to redeploy an Azure "roles" resource in run mode, we are getting a different CheckSum. This is because we are overwriting the "known parameters" like PrincipalId and PrincipalType with 'null' values, because these values aren't available yet.

The fix is to skip setting those known parameters, like we did in previous versions.

Fix microsoft#12651
@github-actions

github-actions Bot commented Nov 11, 2025

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12901

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12901"

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes an issue where Azure "roles" resources were being redeployed every time an application runs. The problem occurred because known parameters (like PrincipalId and PrincipalType) were being overwritten with null values during checksum calculation, causing the checksum to change unnecessarily.

Key Changes:

  • Added a skipKnownValues parameter to SetParametersAsync to prevent overwriting known parameters with null values
  • Modified GetCurrentChecksumAsync to use skipKnownValues: true when calculating checksums
  • Added a test to verify known parameters are not overwritten during checksum calculation

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Aspire.Hosting.Azure/Provisioning/BicepUtilities.cs Introduces skipKnownValues parameter to SetParametersAsync and uses it in GetCurrentChecksumAsync to prevent overwriting known parameters with null values
tests/Aspire.Hosting.Azure.Tests/BicepUtilitiesTests.cs Adds test to verify known parameters are not overwritten when calculating checksums, ensuring roles resources don't redeploy unnecessarily

Comment on lines +448 to +449
[AzureBicepResource.KnownParameters.PrincipalType] = "User",
[AzureBicepResource.KnownParameters.PrincipalId] = "1234"

Copilot AI Nov 11, 2025

Copy link

Choose a reason for hiding this comment

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

The test creates a parameters JsonObject with direct values, but based on the ARM template parameter format used by SetParametersAsync and expected by GetChecksum, each parameter should be wrapped in a JsonObject with a "value" property.

The parameters should be structured as:

var parameters = new JsonObject
{
    [AzureBicepResource.KnownParameters.PrincipalType] = new JsonObject { ["value"] = "User" },
    [AzureBicepResource.KnownParameters.PrincipalId] = new JsonObject { ["value"] = "1234" }
};

This matches the structure that SetParametersAsync creates (line 45-59 in BicepUtilities.cs) and what GetCurrentChecksumAsync expects when it parses parameters from configuration.

Suggested change
[AzureBicepResource.KnownParameters.PrincipalType] = "User",
[AzureBicepResource.KnownParameters.PrincipalId] = "1234"
[AzureBicepResource.KnownParameters.PrincipalType] = new JsonObject { ["value"] = "User" },
[AzureBicepResource.KnownParameters.PrincipalId] = new JsonObject { ["value"] = "1234" }

Copilot uses AI. Check for mistakes.
/// This is important because if these known parameters are overwritten, it means the "roles"
/// resources will be redeployed every time the app is run.
/// </summary>
/// <returns></returns>

Copilot AI Nov 11, 2025

Copy link

Choose a reason for hiding this comment

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

The return type documentation <returns></returns> is empty and should be removed since this is a Task returning method (equivalent to void). According to the XML documentation guidelines, <returns> tags are only required for methods that return a value (non-void returns).

Copilot generated this review using guidance from repository custom instructions.
Comment thread src/Aspire.Hosting.Azure/Provisioning/BicepUtilities.cs
@davidfowl

Copy link
Copy Markdown
Contributor

Backport to 13.0

@eerhardt

Copy link
Copy Markdown
Member Author

/backport to release/13.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/19275080058

@eerhardt

Copy link
Copy Markdown
Member Author

/backport to release/13.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/19276695129

@eerhardt
Eric Erhardt (eerhardt) enabled auto-merge (squash) November 11, 2025 19:42
@eerhardt
Eric Erhardt (eerhardt) merged commit d3fce4b into microsoft:main Nov 13, 2025
866 of 874 checks passed
@eerhardt
Eric Erhardt (eerhardt) deleted the FixRolesRedeploy branch November 13, 2025 15:44
@dotnet-policy-service dotnet-policy-service Bot added this to the 13.1 milestone Nov 13, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AzureFlexiblePostgresResource always deploys its roles

4 participants