Skip to content

Commit 20a5aee

Browse files
authored
[Resources] Bug fixes for deployment and deployment What-If cmdlets (#12780)
* Fix serialization for secure strings in parameters * Show "Ignore" resource changes last * Update change log * Add notes
1 parent 6e070dc commit 20a5aee

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed

src/Resources/ResourceManager/Comparers/ChangeTypeComparer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public class ChangeTypeComparer : IComparer<ChangeType>
2626
[ChangeType.Create] = 1,
2727
[ChangeType.Deploy] = 2,
2828
[ChangeType.Modify] = 3,
29-
[ChangeType.Ignore] = 4,
30-
[ChangeType.NoChange] = 5,
29+
[ChangeType.NoChange] = 4,
30+
[ChangeType.Ignore] = 5,
3131
};
3232

3333
public int Compare(ChangeType first, ChangeType second)

src/Resources/ResourceManager/Formatters/PSResourceManagerErrorFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Formatters
1818
using System;
1919
using System.Collections.Generic;
2020

21-
public class PSResourceManagerErrorFormatter
21+
public static class PSResourceManagerErrorFormatter
2222
{
2323
public static string Format(PSResourceManagerError error)
2424
{

src/Resources/ResourceManager/SdkClient/ResourceManagerSdkClient.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
using Microsoft.Azure.Management.ResourceManager.Models;
3838
using Microsoft.Rest.Azure;
3939
using Microsoft.Rest.Azure.OData;
40+
using Microsoft.WindowsAzure.Commands.Common;
4041
using Microsoft.WindowsAzure.Commands.Utilities.Common;
42+
using Newtonsoft.Json;
4143
using Newtonsoft.Json.Linq;
4244
using ProjectResources = Microsoft.Azure.Commands.ResourceManager.Cmdlets.Properties.Resources;
4345
using ProvisioningState = Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.ProvisioningState;
@@ -451,8 +453,10 @@ private Deployment CreateBasicDeployment(PSDeploymentCmdletParameters parameters
451453
}
452454
else
453455
{
454-
string parametersContent = parameters.TemplateParameterObject != null
455-
? PSJsonSerializer.Serialize(parameters.TemplateParameterObject)
456+
// ToDictionary is needed for extracting value from a secure string. Do not remove it.
457+
Dictionary<string, object> parametersDictionary = parameters.TemplateParameterObject?.ToDictionary(false);
458+
string parametersContent = parametersDictionary != null
459+
? PSJsonSerializer.Serialize(parametersDictionary)
456460
: null;
457461
deployment.Properties.Parameters = !string.IsNullOrEmpty(parametersContent)
458462
? JObject.Parse(parametersContent)

src/Resources/ResourceManager/SdkModels/Deployments/PSDeploymentWhatIfCmdletParameters.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Commands.Common.Authentication.Abstractions;
99
using Management.ResourceManager.Models;
1010
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Json;
11+
using Microsoft.WindowsAzure.Commands.Common;
1112
using Newtonsoft.Json.Linq;
1213

1314
public class PSDeploymentWhatIfCmdletParameters
@@ -105,8 +106,10 @@ public DeploymentWhatIf ToDeploymentWhatIf()
105106
}
106107
else
107108
{
108-
string parametersContent = this.TemplateParametersObject != null
109-
? PSJsonSerializer.Serialize(this.TemplateParametersObject)
109+
// ToDictionary is needed for extracting value from a secure string. Do not remove it.
110+
Dictionary<string, object> parametersDictionary = this.TemplateParametersObject?.ToDictionary(false);
111+
string parametersContent = parametersDictionary != null
112+
? PSJsonSerializer.Serialize(parametersDictionary)
110113
: null;
111114
properties.Parameters = !string.IsNullOrEmpty(parametersContent)
112115
? JObject.Parse(parametersContent)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ public void Format_ResourceIdOnly_SortsAndGroupsByShortResourceId()
273273
- p5/foo
274274
- p6/foo{Color.Reset}{Color.Green}
275275
+ p2/foo{Color.Reset}{Color.Blue}
276-
! p4/foo{Color.Reset}{Color.Gray}
277-
* p1/foo{Color.Reset}{Color.Reset}
278-
= p3/foo
276+
! p4/foo{Color.Reset}{Color.Reset}
277+
= p3/foo{Color.Reset}{Color.Gray}
278+
* p1/foo
279279
{Color.Reset}
280280
"
281281
.Replace("\r\n", Environment.NewLine);

src/Resources/Resources/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
-->
2020
## Upcoming Release
2121
* Added breaking change attribute to `SubscriptionId` parameter of `Get-AzResourceGroupDeploymentOperation`.
22+
* Updated ARM template What-If cmdlets to show "Ignore" resource changes last.
23+
* Fixed an issue where dynamic secure string parameters for deployment cmdlets are not correctly serialized.
2224

2325
## Version 2.5.0
2426
* Updated `Get-AzPolicyAlias` response to include information indicating whether the alias is modifiable by Azure Policy.

0 commit comments

Comments
 (0)