-
Notifications
You must be signed in to change notification settings - Fork 4k
Add Rollback option to resource group level resources #7134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
using ProjectResources = Microsoft.Azure.Commands.ResourceManager.Cmdlets.Properties.Resources; | ||
using System.Management.Automation; | ||
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; | ||
using System; | ||
|
||
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation | ||
{ | ||
|
@@ -45,6 +46,12 @@ public class NewAzureResourceGroupDeploymentCmdlet : ResourceWithParameterCmdlet | |
[ValidateSet("RequestContent", "ResponseContent", "All", "None", IgnoreCase = true)] | ||
public string DeploymentDebugLogLevel { get; set; } | ||
|
||
[Parameter(Mandatory = false, HelpMessage = "Rollback to the last successful deployment in the resource group, should not be present if -RollBackDeploymentName is used.")] | ||
public SwitchParameter RollbackToLastDeployment { get; set; } | ||
|
||
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Rollback to the successful deployment with the given name in the resource group, should not be used if -RollbackToLastDeployment is used.")] | ||
public string RollBackDeploymentName { get; set; } | ||
|
||
[Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation.")] | ||
public SwitchParameter Force { get; set; } | ||
|
||
|
@@ -66,6 +73,11 @@ public override void ExecuteCmdlet() | |
ResourceGroupName, | ||
() => | ||
{ | ||
if (RollbackToLastDeployment && !string.IsNullOrEmpty(RollBackDeploymentName)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead, we shoudl do this with parameter sets, |
||
{ | ||
WriteExceptionError(new ArgumentException(ProjectResources.InvalidRollbackParameters)); | ||
} | ||
|
||
var parameters = new PSDeploymentCmdletParameters() | ||
{ | ||
ResourceGroupName = ResourceGroupName, | ||
|
@@ -74,7 +86,14 @@ public override void ExecuteCmdlet() | |
TemplateFile = TemplateUri ?? this.TryResolvePath(TemplateFile), | ||
TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject), | ||
ParameterUri = TemplateParameterUri, | ||
DeploymentDebugLogLevel = GetDeploymentDebugLogLevel(DeploymentDebugLogLevel) | ||
DeploymentDebugLogLevel = GetDeploymentDebugLogLevel(DeploymentDebugLogLevel), | ||
OnErrorDeployment = RollbackToLastDeployment || !string.IsNullOrEmpty(RollBackDeploymentName) | ||
? new OnErrorDeployment | ||
{ | ||
Type = RollbackToLastDeployment ? OnErrorDeploymentType.LastSuccessful : OnErrorDeploymentType.SpecificDeployment, | ||
DeploymentName = RollbackToLastDeployment ? null : RollBackDeploymentName | ||
} | ||
: null | ||
}; | ||
|
||
if (!string.IsNullOrEmpty(parameters.DeploymentDebugLogLevel)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; | ||
using Microsoft.Azure.Management.ResourceManager.Models; | ||
using Microsoft.WindowsAzure.Commands.Utilities.Common; | ||
using ProjectResources = Microsoft.Azure.Commands.ResourceManager.Cmdlets.Properties.Resources; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
|
||
|
@@ -35,19 +37,37 @@ public class TestAzureResourceGroupDeploymentCmdlet : ResourceWithParameterCmdle | |
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The deployment mode.")] | ||
public DeploymentMode Mode { get; set; } | ||
|
||
[Parameter(Mandatory = false, HelpMessage = "Rollback to the last successful deployment in the resource group, should not be present if -RollBackDeploymentName is used.")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment |
||
public SwitchParameter RollbackToLastDeployment { get; set; } | ||
|
||
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Rollback to the successful deployment with the given name in the resource group, should not be used if -RollbackToLastDeployment is used.")] | ||
public string RollBackDeploymentName { get; set; } | ||
|
||
public TestAzureResourceGroupDeploymentCmdlet() | ||
{ | ||
this.Mode = DeploymentMode.Incremental; | ||
} | ||
|
||
public override void ExecuteCmdlet() | ||
{ | ||
if (RollbackToLastDeployment && !string.IsNullOrEmpty(RollBackDeploymentName)) | ||
{ | ||
WriteExceptionError(new ArgumentException(ProjectResources.InvalidRollbackParameters)); | ||
} | ||
|
||
PSDeploymentCmdletParameters parameters = new PSDeploymentCmdletParameters() | ||
{ | ||
ResourceGroupName = ResourceGroupName, | ||
TemplateFile = TemplateUri ?? this.TryResolvePath(TemplateFile), | ||
TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject), | ||
ParameterUri = TemplateParameterUri | ||
ParameterUri = TemplateParameterUri, | ||
OnErrorDeployment = RollbackToLastDeployment || !string.IsNullOrEmpty(RollBackDeploymentName) | ||
? new OnErrorDeployment | ||
{ | ||
Type = RollbackToLastDeployment ? OnErrorDeploymentType.LastSuccessful : OnErrorDeploymentType.SpecificDeployment, | ||
DeploymentName = RollbackToLastDeployment ? null : RollBackDeploymentName | ||
} | ||
: null | ||
}; | ||
|
||
WriteObject(ResourceManagerSdkClient.ValidateDeployment(parameters, Mode)); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these need to be in separate parameter sets - any parameter that is not in any parameter set is in all parameter sets. I can put a PR into your branch to show how this is done.