Skip to content

Commit b70362c

Browse files
Fix bug with custom types and deployments whatif (#24140)
* Fix bug with custom types and whatif * Update changelog
1 parent b1d2eed commit b70362c

File tree

6 files changed

+933
-1
lines changed

6 files changed

+933
-1
lines changed

src/Resources/ResourceManager/Json/PSJsonSerializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private static object ProcessValue(object value, int currentDepth, SerializeCont
9494

9595
if (value is JObject jObject)
9696
{
97-
return jObject.ToObject<Dictionary<object, object>>();
97+
return jObject.Properties().ToDictionary(x => x.Name, x => x.Value);
9898
}
9999

100100
Type type = value.GetType();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type managementGroupNameType = string
2+
3+
@description('The ID (not the display name) of the Management Group. Used only when it is management group deployment.')
4+
param managementGroupName managementGroupNameType = ''

src/Resources/Resources.Test/ScenarioTests/DeploymentWhatIfTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public void RGLevelWhatIf_SetExcludeChangeType_HidesResourceChanges()
6666
TestRunner.RunTestScript("Test-WhatIfExcludeChangeTypesAtResourceGroupScope");
6767
}
6868

69+
[Fact]
70+
[Trait(Category.AcceptanceType, Category.CheckIn)]
71+
public void Test_WhatIfWithUserDefinedTypes()
72+
=> TestRunner.RunTestScript("Test-WhatIfWithUserDefinedTypes");
73+
6974
[Fact]
7075
[Trait(Category.AcceptanceType, Category.CheckIn)]
7176
public void SubLevelWhatIf_BlankTemplate_ReturnsNoChange()

src/Resources/Resources.Test/ScenarioTests/DeploymentWhatIfTests.ps1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,39 @@ function Test-WhatIfExcludeChangeTypesAtResourceGroupScope
274274
}
275275
}
276276

277+
278+
279+
<#
280+
.SYNOPSIS
281+
Tests what-if with user-defined types (https://github.com/Azure/bicep/issues/13245).
282+
#>
283+
function Test-WhatIfWithUserDefinedTypes
284+
{
285+
try
286+
{
287+
# Arrange.
288+
$deploymentName = Get-ResourceName
289+
$location = "westus"
290+
$resourceGroupName = Get-ResourceGroupName
291+
292+
New-AzResourceGroup -Name $resourceGroupName -Location $location
293+
294+
# Act.
295+
$result = Get-AzResourceGroupDeploymentWhatIfResult `
296+
-ResourceGroupName $resourceGroupName `
297+
-Name $deploymentName `
298+
-TemplateFile "Resources/DeploymentWhatIfTests/WhatIfWithUserDefinedTypes/main.bicep"
299+
300+
# Assert.
301+
Assert-AreEqual "Succeeded" $result.Status
302+
}
303+
finally
304+
{
305+
# Cleanup.
306+
Clean-ResourceGroup $resourceGroupName
307+
}
308+
}
309+
277310
<#
278311
.SYNOPSIS
279312
Tests subscription level deployment what-if with empty template.

src/Resources/Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentWhatIfTests/Test_WhatIfWithUserDefinedTypes.json

Lines changed: 889 additions & 0 deletions
Large diffs are not rendered by default.

src/Resources/Resources/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
## Upcoming Release
2222
* Added `AuxTenant` parameter in `New-AzResourceGroupDeployment`to support cross-tenant deployment.
23+
* Fixed bug with custom types and deployments whatif. [#13245]
2324

2425
## Version 6.15.1
2526
* Fixed deadlock in Bicep CLI execution. [#24133]

0 commit comments

Comments
 (0)