Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixed overriding of Bicep parameters in Deployment Stack cmdlets to s…
…upport SecureString parameters.
  • Loading branch information
Dante DG committed Nov 12, 2024
commit 5422455de4be04fe02a27ae74679c31f6607ec08
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
using Newtonsoft.Json;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Json;
using Microsoft.WindowsAzure.Commands.Common;

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

private IDictionary<string, DeploymentParameter> ConvertParameterHashtableToDictionary(Hashtable parameters)
{
var paramDictionary = new Dictionary<string, DeploymentParameter>();

foreach (string key in parameters.Keys)
{
paramDictionary[key] = new DeploymentParameter();
var paramTable = (Hashtable)parameters[key];

if (paramTable["reference"] != null)
{
paramDictionary[key].Reference = JsonConvert.DeserializeObject<KeyVaultParameterReference>(paramTable["reference"].ToString());
}
else
{
paramDictionary[key].Value = paramTable["value"];
}
}

return paramDictionary;
Dictionary<string, object> parametersDictionary = parameters?.ToDictionary(false);
string parametersContent = parametersDictionary != null
? PSJsonSerializer.Serialize(parametersDictionary)
: null;

return !string.IsNullOrEmpty(parametersContent)
? parametersContent.FromJson<Dictionary<string, DeploymentParameter>>()
: null;
}

private DeploymentStack waitStackCompletion(Func<Task<AzureOperationResponse<DeploymentStack>>> getStack, params string[] status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ public void TestGetResourceGroupDeploymentStack()
{
TestRunner.RunTestScript("Test-GetResourceGroupDeploymentStack");
}


[Fact()]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestNewResourceGroupDeploymentStackFromBicepparamFileWithOverrides()
{
TestRunner.RunTestScript("Test-NewResourceGroupDeploymentStackFromBicepparamFileWithOverrides");
}

[Fact()]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestNewResourceGroupDeploymentStack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,57 @@ function Test-GetResourceGroupDeploymentStack
}
}

<#
.SYNOPSIS
Tests deployment via .bicepparam file with inline parameter overrides.
#>
function Test-NewResourceGroupDeploymentStackFromBicepparamFileWithOverrides
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$rglocation = "West US 2"
$expectedAllOutput = @'
{
"array": [
"abc"
],
"string": "hello",
"object": {
"def": "ghi"
},
"int": 42,
"bool": true,
"secureString": "glabble"
}
'@ | ConvertFrom-Json

try
{
# Test
New-AzResourceGroup -Name $rgname -Location $rglocation

$deployment = New-AzResourceGroupDeploymentStack -Name $rname -ResourceGroupName $rgname -ActionOnUnmanage DetachAll -DenySettingsMode None -TemplateParameterFile deployWithParamOverrides.bicepparam `
-myArray @("abc") `
-myObject @{"def" = "ghi";} `
-myString "hello" `
-myInt 42 `
-myBool $true `
-mySecureString (ConvertTo-SecureString -String "glabble" -AsPlainText -Force)

# Assert
Assert-AreEqual Succeeded $deployment.ProvisioningState

$actualAllOutput = $deployment.Outputs["all"].Value.ToString() | ConvertFrom-Json
Assert-AreEqual ($expectedAllOutput | ConvertTo-Json) ($actualAllOutput | ConvertTo-Json)
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests New operation on deployment stacks at the RG scope.
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Resources/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

## Upcoming Release
* Updated Resources SDK to 2024-07-01.
* Fixed overriding of Bicep parameters in Deployment Stack cmdlets to support SecureString parameters.

## Version 7.6.0
* Fixed customer-reported `Remove-AzPolicyAssignment` behavior.
Expand Down