Skip to content

Conversation

@eerhardt
Copy link
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 dotnet#12651
@eerhardt eerhardt requested a review from davidfowl November 11, 2025 18:10
Copilot AI review requested due to automatic review settings November 11, 2025 18:10
@github-actions
Copy link
Contributor

github-actions bot commented Nov 11, 2025

🚀 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 finished reviewing on behalf of eerhardt November 11, 2025 18:13
Copy link
Contributor

Copilot AI left a comment

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"
Copy link

Copilot AI Nov 11, 2025

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>
Copy link

Copilot AI Nov 11, 2025

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.
@davidfowl
Copy link
Member

Backport to 13.0

@eerhardt
Copy link
Member Author

/backport to release/13.0

@github-actions
Copy link
Contributor

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

@eerhardt
Copy link
Member Author

/backport to release/13.0

@github-actions
Copy link
Contributor

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

@eerhardt eerhardt enabled auto-merge (squash) November 11, 2025 19:42
@eerhardt eerhardt merged commit d3fce4b into dotnet:main Nov 13, 2025
866 of 874 checks passed
@eerhardt 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
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.

AzureFlexiblePostgresResource always deploys its roles

3 participants