Skip to content

Commit 3e51378

Browse files
committed
Added stack existence checks for New- and Set-
1 parent d3743a2 commit 3e51378

File tree

5 files changed

+218
-44
lines changed

5 files changed

+218
-44
lines changed

src/Resources/ResourceManager/Implementation/DeploymentStacks/NewAzResourceGroupDeploymentStack.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
44
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
5+
using Microsoft.Azure.Management.ResourceManager.Models;
56
using Microsoft.WindowsAzure.Commands.Utilities.Common;
67
using System;
78
using System.Collections;
@@ -104,6 +105,7 @@ public override void ExecuteCmdlet()
104105
throw new PSInvalidOperationException(
105106
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
106107
}
108+
TemplateUri = TemplateFile;
107109
break;
108110
case ParameterFileTemplateSpecParameterSetName:
109111
case ParameterFileTemplateUriParameterSetName:
@@ -117,17 +119,25 @@ public override void ExecuteCmdlet()
117119
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
118120
}
119121
parameters = this.GetParameterObject(ParameterFile);
122+
TemplateUri = TemplateFile;
120123
break;
121124
}
122125

126+
if (DeploymentStacksSdkClient.GetResourceGroupDeploymentStack(
127+
ResourceGroupName,
128+
Name,
129+
throwIfNotExists: false) != null)
130+
throw new DeploymentStacksErrorException($"The stack '{Name}' in Resource Group '{ResourceGroupName}' you're trying to create already exists. Please Use Set-AzResourceGroupDeploymentStack to make changes to it");
131+
123132
var deploymentStack = DeploymentStacksSdkClient.ResourceGroupCreateOrUpdateDeploymentStack(
124133
Name,
125134
ResourceGroupName,
126135
TemplateUri,
127136
TemplateSpec,
128137
ParameterUri,
129138
parameters,
130-
Description
139+
Description,
140+
"Detach"
131141
);
132142
WriteObject(deploymentStack);
133143

src/Resources/ResourceManager/Implementation/DeploymentStacks/NewAzSubscriptionDeploymentStack.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
44
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
5+
using Microsoft.Azure.Management.ResourceManager.Models;
56
using Microsoft.WindowsAzure.Commands.Utilities.Common;
67
using System;
78
using System.Collections;
@@ -114,6 +115,11 @@ public override void ExecuteCmdlet()
114115
break;
115116
}
116117

118+
if (DeploymentStacksSdkClient.GetSubscriptionDeploymentStack(
119+
Name,
120+
throwIfNotExists: false) != null)
121+
throw new DeploymentStacksErrorException($"The stack '{Name}' you're trying to create already exists in the current subscription. Please Use Set-AzResourceGroupDeploymentStack to make changes to it");
122+
117123
var deploymentStack = DeploymentStacksSdkClient.SubscriptionCreateOrUpdateDeploymentStack(
118124
Name,
119125
TemplateUri,

src/Resources/ResourceManager/Implementation/DeploymentStacks/SetAzResourceGroupDeploymentStack.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
44
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
5+
using Microsoft.Azure.Management.ResourceManager.Models;
56
using Microsoft.WindowsAzure.Commands.Utilities.Common;
67
using System;
78
using System.Collections;
@@ -85,6 +86,10 @@ public class SetAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase
8586
HelpMessage = "Description for the stack")]
8687
public string Description { get; set; }
8788

89+
[Parameter(Mandatory = true, ValueFromPipeline = true,
90+
HelpMessage = "Update behavior for the stack. Value can be \"Detach\" or \"Purge\".")]
91+
public String UpdateBehavior { get; set; }
92+
8893
#endregion
8994

9095
#region Cmdlet Overrides
@@ -120,15 +125,21 @@ public override void ExecuteCmdlet()
120125
break;
121126
}
122127

128+
if (DeploymentStacksSdkClient.GetSubscriptionDeploymentStack(
129+
Name,
130+
throwIfNotExists: false) == null)
131+
throw new DeploymentStacksErrorException($"The stack '{Name}' you're trying to modify does not exist in '{ResourceGroupName}'. Please Use New-AzResourceGroupDeploymentStack to create it");
132+
123133
var deploymentStack = DeploymentStacksSdkClient.ResourceGroupCreateOrUpdateDeploymentStack(
124134
Name,
125135
ResourceGroupName,
126136
TemplateUri,
127137
TemplateSpec,
128138
ParameterUri,
129139
parameters,
130-
Description
131-
);
140+
Description,
141+
UpdateBehavior
142+
) ;
132143
WriteObject(deploymentStack);
133144

134145
}

src/Resources/ResourceManager/Implementation/DeploymentStacks/SetAzSubscriptionDeploymentStack.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
44
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
5+
using Microsoft.Azure.Management.ResourceManager.Models;
56
using Microsoft.WindowsAzure.Commands.Utilities.Common;
67
using System;
78
using System.Collections;
@@ -114,6 +115,12 @@ public override void ExecuteCmdlet()
114115
break;
115116
}
116117

118+
119+
if (DeploymentStacksSdkClient.GetSubscriptionDeploymentStack(
120+
Name,
121+
throwIfNotExists: false) == null)
122+
throw new DeploymentStacksErrorException($"The stack '{Name}' you're trying to modify does not exist in the current subscription. Please Use New-AzResourceGroupDeploymentStack to create it");
123+
117124
var deploymentStack = DeploymentStacksSdkClient.SubscriptionCreateOrUpdateDeploymentStack(
118125
Name,
119126
TemplateUri,

0 commit comments

Comments
 (0)