Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
{
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
using Microsoft.Azure.Management.Resources.Models;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
using System;
Expand All @@ -29,6 +30,7 @@ public class RemoveAzManagementGroupDeploymentStack : DeploymentStacksCmdletBase

internal const string RemoveByResourceIdParameterSetName = "RemoveByResourceId";
internal const string RemoveByNameAndManagementGroupIdParameterSetName = "RemoveByNameAndManagementGroupId";
internal const string RemoveByStackObjectParameterSetName = "RemoveByStackObject";

[Alias("StackName")]
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = RemoveByNameAndManagementGroupIdParameterSetName,
Expand All @@ -47,6 +49,11 @@ public class RemoveAzManagementGroupDeploymentStack : DeploymentStacksCmdletBase
[ValidateNotNullOrEmpty]
public string ManagementGroupId { get; set; }

[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true, ParameterSetName = RemoveByStackObjectParameterSetName,
HelpMessage = "The stack PS object")]
[ValidateNotNullOrEmpty]
public PSDeploymentStack InputObjet { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Signal to delete both unmanaged Resources and ResourceGroups after updating stack.")]
public SwitchParameter DeleteAll { get; set; }

Expand All @@ -73,10 +80,16 @@ protected override void OnProcessRecord()
var shouldDeleteResources = (DeleteAll.ToBool() || DeleteResources.ToBool()) ? true : false;
var shouldDeleteResourceGroups = (DeleteAll.ToBool() || DeleteResourceGroups.ToBool()) ? true : false;

if (InputObjet != null)
{
ResourceId = InputObjet.id;
}

// resolve Name and ManagementGroupId if ResourceId was provided
ManagementGroupId = ManagementGroupId ?? ResourceIdUtility.GetManagementGroupId(ResourceId);
Name = Name ?? ResourceIdUtility.GetDeploymentName(ResourceId);


// failed resolving the resource id
if (Name == null || ManagementGroupId == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
{
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.Resources.Models;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
Expand All @@ -30,6 +31,7 @@ public class RemoveAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase

internal const string RemoveByResourceIdParameterSetName = "RemoveByResourceId";
internal const string RemoveByNameAndResourceGroupNameParameterSetName = "RemoveByNameAndResourceGroupName";
internal const string RemoveByStackObjectParameterSetName = "RemoveByStackObject";

[Alias("StackName")]
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = RemoveByNameAndResourceGroupNameParameterSetName,
Expand All @@ -38,7 +40,7 @@ public class RemoveAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase
public string Name { get; set; }

[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = RemoveByNameAndResourceGroupNameParameterSetName,
HelpMessage = "The name of the Resource Group with the stack to delete")]
HelpMessage = "The name of the Resource Group with the stack to delete")]
[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }
Expand All @@ -49,6 +51,11 @@ public class RemoveAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase
[ValidateNotNullOrEmpty]
public string ResourceId { get; set; }

[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true, ParameterSetName = RemoveByStackObjectParameterSetName,
HelpMessage = "The stack PS object.")]
[ValidateNotNullOrEmpty]
public PSDeploymentStack InputObjet { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Signal to delete both unmanaged Resources and ResourceGroups after updating stack.")]
public SwitchParameter DeleteAll { get; set; }

Expand All @@ -75,6 +82,11 @@ protected override void OnProcessRecord()
var shouldDeleteResources = (DeleteAll.ToBool() || DeleteResources.ToBool()) ? true : false;
var shouldDeleteResourceGroups = (DeleteAll.ToBool() || DeleteResourceGroups.ToBool()) ? true : false;

if (InputObjet != null)
{
ResourceId = InputObjet.id;
}

// resolve Name and ResourceGroupName if ResourceId was provided
ResourceGroupName = ResourceGroupName ?? ResourceIdUtility.GetResourceGroupName(ResourceId);
Name = Name ?? ResourceIdUtility.GetDeploymentName(ResourceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
{
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
using Microsoft.Azure.Management.Resources.Models;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
using System;
Expand All @@ -29,6 +30,7 @@ public class RemoveAzSubscriptionDeploymentStack : DeploymentStacksCmdletBase

internal const string RemoveByResourceIdParameterSetName = "RemoveByResourceId";
internal const string RemoveByNameParameterSetName = "RemoveByName";
internal const string RemoveByStackObjectParameterSetName = "RemoveByStackObject";

[Alias("StackName")]
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = RemoveByNameParameterSetName,
Expand All @@ -42,6 +44,11 @@ public class RemoveAzSubscriptionDeploymentStack : DeploymentStacksCmdletBase
[ValidateNotNullOrEmpty]
public string ResourceId { get; set; }

[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true, ParameterSetName = RemoveByStackObjectParameterSetName,
HelpMessage = "The stack PS object")]
[ValidateNotNullOrEmpty]
public PSDeploymentStack InputObjet { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Signal to delete both unmanaged Resources and ResourceGroups after updating stack.")]
public SwitchParameter DeleteAll { get; set; }

Expand All @@ -68,6 +75,11 @@ protected override void OnProcessRecord()
var shouldDeleteResources = (DeleteAll.ToBool() || DeleteResources.ToBool()) ? true : false;
var shouldDeleteResourceGroups = (DeleteAll.ToBool() || DeleteResourceGroups.ToBool()) ? true : false;

if (InputObjet != null)
{
ResourceId = InputObjet.id;
}

// resolve Name if ResourceId was provided
Name = Name ?? ResourceIdUtility.GetDeploymentName(ResourceId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class SaveAzManagementGroupDeploymentStackTemplate : DeploymentStacksCmdl

internal const string SaveByResourceIdParameterSetName = "SaveByResourceId";
internal const string SaveByNameAndManagementGroupIdParameterSetName = "SaveByNameAndManagmentGroupId";
internal const string SaveByStackObjectParameterSetName = "SaveByStackObject";

[Alias("Id")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = SaveByResourceIdParameterSetName,
Expand All @@ -47,6 +48,11 @@ public class SaveAzManagementGroupDeploymentStackTemplate : DeploymentStacksCmdl
[ValidateNotNullOrEmpty]
public string ManagementGroupId { get; set; }

[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true, ParameterSetName = SaveByStackObjectParameterSetName,
HelpMessage = "The stack PS object")]
[ValidateNotNullOrEmpty]
public PSDeploymentStack InputObjet { get; set; }

#endregion

#region Cmdlet Overrides
Expand All @@ -56,7 +62,11 @@ protected override void OnProcessRecord()
{
switch (ParameterSetName)
{
case SaveByResourceIdParameterSetName:
case SaveByResourceIdParameterSetName: case SaveByStackObjectParameterSetName:
if (InputObjet != null)
{
ResourceId = InputObjet.id;
}
ManagementGroupId = ResourceIdUtility.GetManagementGroupId(ResourceId);
StackName = ResourceIdUtility.GetDeploymentName(ResourceId);
if (ManagementGroupId == null || StackName == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class SaveAzResourceGroupDeploymentStackTemplate : DeploymentStacksCmdlet

internal const string SaveByResourceIdParameterSetName = "SaveByResourceId";
internal const string SaveByNameAndResourceGroupNameParameterSetName = "SaveByNameAndResourceGroupName";
internal const string SaveByStackObjectParameterSetName = "SaveByStackObject";

[Alias("Id")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = SaveByResourceIdParameterSetName,
Expand All @@ -48,6 +49,11 @@ public class SaveAzResourceGroupDeploymentStackTemplate : DeploymentStacksCmdlet
[ValidateNotNullOrEmpty]
public string StackName { get; set; }

[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true, ParameterSetName = SaveByStackObjectParameterSetName,
HelpMessage = "The stack PS object")]
[ValidateNotNullOrEmpty]
public PSDeploymentStack InputObjet { get; set; }

#endregion

#region Cmdlet Overrides
Expand All @@ -58,7 +64,11 @@ protected override void OnProcessRecord()
{
switch (ParameterSetName)
{
case SaveByResourceIdParameterSetName:
case SaveByResourceIdParameterSetName: case SaveByStackObjectParameterSetName:
if (InputObjet != null)
{
ResourceId = InputObjet.id;
}
ResourceGroupName = ResourceIdUtility.GetResourceGroupName(ResourceId);
StackName = ResourceIdUtility.GetDeploymentName(ResourceId);
if (ResourceGroupName == null || StackName == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class SaveAzSubscriptionDeploymentStackTemplate : DeploymentStacksCmdletB

internal const string SaveByResourceIdParameterSetName = "SaveByResourceId";
internal const string SaveByNameParameterSetName = "SaveByName";
internal const string SaveByStackObjectParameterSetName = "SaveByStackObject";

[Alias("Id")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = SaveByResourceIdParameterSetName,
Expand All @@ -42,6 +43,11 @@ public class SaveAzSubscriptionDeploymentStackTemplate : DeploymentStacksCmdletB
[ValidateNotNullOrEmpty]
public string StackName { get; set; }

[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true, ParameterSetName = SaveByStackObjectParameterSetName,
HelpMessage = "The stack PS object")]
[ValidateNotNullOrEmpty]
public PSDeploymentStack InputObjet { get; set; }

#endregion

#region Cmdlet Overrides
Expand All @@ -51,7 +57,11 @@ protected override void OnProcessRecord()
{
switch (ParameterSetName)
{
case SaveByResourceIdParameterSetName:
case SaveByResourceIdParameterSetName: case SaveByStackObjectParameterSetName:
if (InputObjet != null)
{
ResourceId = InputObjet.id;
}
StackName = ResourceIdUtility.GetDeploymentName(ResourceId);
if (StackName == null)
{
Expand Down
21 changes: 21 additions & 0 deletions src/Resources/Resources.Test/ScenarioTests/DeploymentStackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ public void TestNewAndSetResourceGroupDeploymentStackWithTags()
TestRunner.RunTestScript("Test-NewAndSetResourceGroupDeploymentStackWithTags");
}

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

[Fact()]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetSubscriptionDeploymentStack()
Expand Down Expand Up @@ -178,6 +185,13 @@ public void TestNewAndSetSubscriptionDeploymentStackWithTags()
TestRunner.RunTestScript("Test-NewAndSetSubscriptionDeploymentStackWithTags");
}

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

[Fact()]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetManagementGroupDeploymentStack()
Expand Down Expand Up @@ -254,5 +268,12 @@ public void TestNewAndSetManagementGroupDeploymentStackWithTags()
{
TestRunner.RunTestScript("Test-NewAndSetManagementGroupDeploymentStackWithTags");
}

[Fact()]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSaveAndRemoveManagementGroupDeploymentStackWithPipeOperator()
{
TestRunner.RunTestScript("Test-SaveAndRemoveManagementGroupDeploymentStackWithPipeOperator");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,40 @@ function Test-SaveResourceGroupDeploymentStackTemplate
}
}

<#
.SYNOPSIS
Tests SAVE and REMOVE operation using pipe operator on deploymentStacks at RG scope.
#>
function Test-SaveAndRemoveResourceGroupDeploymentStackWithPipeOperator
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$rglocation = "West US 2"

try
{
# Prepare
New-AzResourceGroup -Name $rgname -Location $rglocation
$deployment = New-AzResourceGroupDeploymentStack -Name $rname -ResourceGroupName $rgname -TemplateFile StacksRGTemplate.json -TemplateParameterFile StacksRGTemplateParams.json -DenySettingsMode None -Force
Assert-AreEqual "succeeded" $deployment.ProvisioningState

# --- SaveByStackObjectSetName ---
$template = Get-AzResourceGroupDeploymentStack -Name $rname -ResourceGroupName $rgname | Save-AzResourceGroupDeploymentStackTemplate
Assert-NotNull $template

# --- RemoveByStackObjectSetName ---
$deployment = Get-AzResourceGroupDeploymentStack -Name $rname -ResourceGroupName $rgname | Remove-AzResourceGroupDeploymentStack -Force
Assert-Null $deployment
}

finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

#### Subscription Scoped Stacks #####

<#
Expand Down Expand Up @@ -1161,6 +1195,37 @@ function Test-GetManagementGroupDeploymentStack
}
}

<#
.SYNOPSIS
Tests SAVE and REMOVE operation using pipe operator on deploymentStacks at Sub scope.
#>
function Test-SaveAndRemoveSubscriptionDeploymentStackWithPipeOperator
{
# Setup
$rname = Get-ResourceName
$location = "West US 2"

try
{
# Prepare
$deployment = New-AzSubscriptionDeploymentStack -Name $rname -Location $location -TemplateFile StacksSubTemplate.json -TemplateParameterFile StacksSubTemplateParams.json -DenySettingsMode None -Force
Assert-AreEqual "succeeded" $deployment.ProvisioningState

# --- SaveByStackObjectSetName ---
$template = Get-AzSubscriptionDeploymentStack -Name $rname | Save-AzSubscriptionDeploymentStackTemplate
Assert-NotNull $template

# --- RemoveByStackObjectSetName ---
$deployment = Get-AzSubscriptionDeploymentStack -Name $rname | Remove-AzSubscriptionDeploymentStack -Force
Assert-Null $deployment
}

finally
{
# No need to cleanup as we already deleted stack.
}
}

<#
.SYNOPSIS
Tests New operation on deployment stacks at the RG scope.
Expand Down Expand Up @@ -1638,4 +1703,37 @@ function Test-SaveManagementGroupDeploymentStackTemplate
# Cleanup
Remove-AzManagementGroupDeploymentStack $mgid $rname -DeleteAll -Force
}
}

<#
.SYNOPSIS
Tests SAVE and REMOVE operation using pipe operator on deploymentStacks at MG scope.
#>
function Test-SaveAndRemoveManagementGroupDeploymentStackWithPipeOperator
{
# Setup
$mgid = "AzBlueprintAssignTest"
$rname = Get-ResourceName
$location = "West US 2"
$subId = (Get-AzContext).Subscription.SubscriptionId

try
{
# Prepare
$deployment = New-AzManagementGroupDeploymentStack -Name $rname -ManagementGroupId $mgid -DeploymentSubscriptionId $subId -TemplateFile StacksMGTemplate.json -TemplateParameterFile StacksMGTemplateParams.json -Location $location -DenySettingsMode None -Force
Assert-AreEqual "succeeded" $deployment.ProvisioningState

# --- SaveByStackObjectSetName ---
$template = Get-AzManagementGroupDeploymentStack -Name $rname -ManagementGroupId $mgid | Save-AzManagementGroupDeploymentStackTemplate
Assert-NotNull $template

# --- RemoveByStackObjectSetName ---
$deployment = Get-AzManagementGroupDeploymentStack -Name $rname -ManagementGroupId $mgid | Remove-AzManagementGroupDeploymentStack -Force
Assert-Null $deployment
}

finally
{
# No cleanup needed, as the stack was deleted.
}
}
Loading