Skip to content

Commit 1a9e673

Browse files
shenglolisra-fel
andauthored
[Resources] Fix an issue where What-If shows two resource group scopes with different casing (Azure#13299)
* Normalize scope casing when group resource changes * Update change log * Update ChangeLog.md Co-authored-by: Yeming Liu <[email protected]>
1 parent dec1b04 commit 1a9e673

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/Resources/ResourceManager/Formatters/WhatIfOperationResultFormatter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,18 @@ private void FormatResourceChanges(IList<PSWhatIfChange> resourceChanges)
176176
return;
177177
}
178178

179-
int scopeCount = resourceChanges.Select(rc => rc.Scope).Distinct().Count();
179+
int scopeCount = resourceChanges.Select(rc => rc.Scope.ToUpperInvariant()).Distinct().Count();
180180

181181
this.Builder
182182
.AppendLine()
183183
.Append("The deployment will update the following ")
184184
.AppendLine(scopeCount == 1 ? "scope:" : "scopes:");
185185

186186
resourceChanges
187-
.OrderBy(rc => rc.Scope)
188-
.GroupBy(rc => rc.Scope)
187+
.OrderBy(rc => rc.Scope.ToUpperInvariant())
188+
.GroupBy(rc => rc.Scope.ToUpperInvariant())
189189
.ToDictionary(g => g.Key, g => g.ToList())
190-
.ForEach(kvp => FormatResourceChangesInScope(kvp.Key, kvp.Value));
190+
.ForEach(kvp => FormatResourceChangesInScope(kvp.Value[0].Scope, kvp.Value));
191191
}
192192

193193
private void FormatResourceChangesInScope(string scope, IList<PSWhatIfChange> resourceChanges)

src/Resources/Resources.Test/Formatters/WhatIfOperationResultFormatterTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,12 @@ public void Format_NonEmptyResourceChanges_SortsAndGroupsByScopeAndChangeType()
173173
{
174174
new WhatIfChange
175175
{
176-
ResourceId = "/subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/rg1/providers/p1/foo1",
176+
ResourceId = "/Subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/RG1/providers/p1/foo1",
177177
ChangeType = ChangeType.Create
178178
},
179179
new WhatIfChange
180180
{
181-
ResourceId = "/subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/rg1/providers/p2/bar",
181+
ResourceId = "/Subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/rg1/providers/p2/bar",
182182
ChangeType = ChangeType.Create
183183
},
184184
new WhatIfChange
@@ -188,7 +188,7 @@ public void Format_NonEmptyResourceChanges_SortsAndGroupsByScopeAndChangeType()
188188
},
189189
new WhatIfChange
190190
{
191-
ResourceId = "/subscriptions/00000000-0000-0000-0000-000000000002/providers/p3/foobar1",
191+
ResourceId = "/SUBSCRIPTIONS/00000000-0000-0000-0000-000000000002/providers/p3/foobar1",
192192
ChangeType = ChangeType.Ignore
193193
},
194194
new WhatIfChange
@@ -204,7 +204,7 @@ public void Format_NonEmptyResourceChanges_SortsAndGroupsByScopeAndChangeType()
204204
};
205205

206206
string changesInfo = $@"
207-
Scope: /subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/rg1
207+
Scope: /subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/RG1
208208
{Color.Green}
209209
+ p1/foo1
210210
+ p2/bar

src/Resources/Resources/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed an issue where What-If shows two resource group scopes with different casing
2122
* Updated `Export-AzResourceGroup` to use the SDK.
2223

2324
## Version 3.0.0

0 commit comments

Comments
 (0)