Skip to content

Commit 691d74a

Browse files
authored
Fixed overriding of Bicep parameters in Deployment Stack cmdlets to support SecureString parameters. (#26670)
* Fixed overriding of Bicep parameters in Deployment Stack cmdlets to support SecureString parameters. * Added session record. --------- Co-authored-by: Dante DG <test>
1 parent 2cb03f7 commit 691d74a

File tree

5 files changed

+1091
-19
lines changed

5 files changed

+1091
-19
lines changed

src/Resources/ResourceManager/SdkClient/DeploymentStacksSdkClient.cs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
3434
using Newtonsoft.Json;
3535
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks;
36+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Json;
37+
using Microsoft.WindowsAzure.Commands.Common;
3638

3739
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient
3840
{
@@ -905,24 +907,14 @@ private void HandleErrors(DeploymentStack deploymentStack)
905907

906908
private IDictionary<string, DeploymentParameter> ConvertParameterHashtableToDictionary(Hashtable parameters)
907909
{
908-
var paramDictionary = new Dictionary<string, DeploymentParameter>();
909-
910-
foreach (string key in parameters.Keys)
911-
{
912-
paramDictionary[key] = new DeploymentParameter();
913-
var paramTable = (Hashtable)parameters[key];
914-
915-
if (paramTable["reference"] != null)
916-
{
917-
paramDictionary[key].Reference = JsonConvert.DeserializeObject<KeyVaultParameterReference>(paramTable["reference"].ToString());
918-
}
919-
else
920-
{
921-
paramDictionary[key].Value = paramTable["value"];
922-
}
923-
}
924-
925-
return paramDictionary;
910+
Dictionary<string, object> parametersDictionary = parameters?.ToDictionary(false);
911+
string parametersContent = parametersDictionary != null
912+
? PSJsonSerializer.Serialize(parametersDictionary)
913+
: null;
914+
915+
return !string.IsNullOrEmpty(parametersContent)
916+
? parametersContent.FromJson<Dictionary<string, DeploymentParameter>>()
917+
: null;
926918
}
927919

928920
private DeploymentStack waitStackCompletion(Func<Task<AzureOperationResponse<DeploymentStack>>> getStack, params string[] status)

src/Resources/Resources.Test/ScenarioTests/DeploymentStackTests.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ public void TestGetResourceGroupDeploymentStack()
3030
{
3131
TestRunner.RunTestScript("Test-GetResourceGroupDeploymentStack");
3232
}
33-
33+
34+
[Fact()]
35+
[Trait(Category.AcceptanceType, Category.CheckIn)]
36+
public void TestNewResourceGroupDeploymentStackFromBicepparamFileWithOverrides()
37+
{
38+
TestRunner.RunTestScript("Test-NewResourceGroupDeploymentStackFromBicepparamFileWithOverrides");
39+
}
40+
3441
[Fact()]
3542
[Trait(Category.AcceptanceType, Category.CheckIn)]
3643
public void TestNewResourceGroupDeploymentStack()

src/Resources/Resources.Test/ScenarioTests/DeploymentStackTests.ps1

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,57 @@ function Test-GetResourceGroupDeploymentStack
6969
}
7070
}
7171

72+
<#
73+
.SYNOPSIS
74+
Tests deployment via .bicepparam file with inline parameter overrides.
75+
#>
76+
function Test-NewResourceGroupDeploymentStackFromBicepparamFileWithOverrides
77+
{
78+
# Setup
79+
$rgname = Get-ResourceGroupName
80+
$rname = Get-ResourceName
81+
$rglocation = "West US 2"
82+
$expectedAllOutput = @'
83+
{
84+
"array": [
85+
"abc"
86+
],
87+
"string": "hello",
88+
"object": {
89+
"def": "ghi"
90+
},
91+
"int": 42,
92+
"bool": true,
93+
"secureString": "glabble"
94+
}
95+
'@ | ConvertFrom-Json
96+
97+
try
98+
{
99+
# Test
100+
New-AzResourceGroup -Name $rgname -Location $rglocation
101+
102+
$deployment = New-AzResourceGroupDeploymentStack -Name $rname -ResourceGroupName $rgname -ActionOnUnmanage DetachAll -DenySettingsMode None -TemplateParameterFile deployWithParamOverrides.bicepparam `
103+
-myArray @("abc") `
104+
-myObject @{"def" = "ghi";} `
105+
-myString "hello" `
106+
-myInt 42 `
107+
-myBool $true `
108+
-mySecureString (ConvertTo-SecureString -String "glabble" -AsPlainText -Force)
109+
110+
# Assert
111+
Assert-AreEqual Succeeded $deployment.ProvisioningState
112+
113+
$actualAllOutput = $deployment.Outputs["all"].Value.ToString() | ConvertFrom-Json
114+
Assert-AreEqual ($expectedAllOutput | ConvertTo-Json) ($actualAllOutput | ConvertTo-Json)
115+
}
116+
finally
117+
{
118+
# Cleanup
119+
Clean-ResourceGroup $rgname
120+
}
121+
}
122+
72123
<#
73124
.SYNOPSIS
74125
Tests New operation on deployment stacks at the RG scope.

0 commit comments

Comments
 (0)