Skip to content

Commit 953c4ab

Browse files
committed
Merge pull request Azure#697 from vivsriaus/dev
Add Complete to DeploymentMode when creating new deployment
2 parents fca68c8 + 1e5efcb commit 953c4ab

File tree

9 files changed

+949
-386
lines changed

9 files changed

+949
-386
lines changed

src/ResourceManager/Resources/Commands.Resources.Test/Models.ResourceGroups/ResourceClientTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ public void TestTemplateShowsErrorMessage()
10161016
}))
10171017
.Callback((string rg, string dn, Deployment d, CancellationToken c) => { deploymentFromValidate = d; });
10181018

1019-
IEnumerable<PSResourceManagerError> error = resourcesClient.ValidatePSResourceGroupDeployment(parameters);
1019+
IEnumerable<PSResourceManagerError> error = resourcesClient.ValidatePSResourceGroupDeployment(parameters, DeploymentMode.Incremental);
10201020
Assert.Equal(2, error.Count());
10211021
}
10221022

@@ -1054,7 +1054,7 @@ public void TestTemplateShowsSuccessMessage()
10541054
}))
10551055
.Callback((string rg, string dn, Deployment d, CancellationToken c) => { deploymentFromValidate = d; });
10561056

1057-
IEnumerable<PSResourceManagerError> error = resourcesClient.ValidatePSResourceGroupDeployment(parameters);
1057+
IEnumerable<PSResourceManagerError> error = resourcesClient.ValidatePSResourceGroupDeployment(parameters, DeploymentMode.Incremental);
10581058
Assert.Equal(0, error.Count());
10591059
progressLoggerMock.Verify(f => f("Template is valid."), Times.Once());
10601060
}

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ResourceGroupTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void TestNewDeploymentAndProviderRegistration()
7474
ResourcesController.NewInstance.RunPsTest("Test-NewDeploymentAndProviderRegistration");
7575
}
7676

77-
[Fact(Skip = "Known test failure")]
77+
[Fact]
7878
public void TestNewResourceGroupWithTemplate()
7979
{
8080
ResourcesController.NewInstance.RunPsTest("Test-NewResourceGroupWithTemplateThenGetWithAndWithoutDetails");

src/ResourceManager/Resources/Commands.Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceGroupTests/TestNewResourceGroupWithTemplate.json

Lines changed: 894 additions & 372 deletions
Large diffs are not rendered by default.

src/ResourceManager/Resources/Commands.Resources.Test/Templates/TestAzureResourceGroupTemplateCommandTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Management.Automation;
1717
using Microsoft.Azure.Commands.Resources.Models;
1818
using Microsoft.Azure.Commands.Resources.ResourceGroupDeployments;
19+
using Microsoft.Azure.Management.Resources.Models;
1920
using Moq;
2021
using Xunit;
2122

@@ -75,9 +76,9 @@ public void ValidatesPSResourceGroupDeploymentWithUserTemplate()
7576
}
7677
};
7778
resourcesClientMock.Setup(f => f.ValidatePSResourceGroupDeployment(
78-
It.IsAny<ValidatePSResourceGroupDeploymentParameters>()))
79+
It.IsAny<ValidatePSResourceGroupDeploymentParameters>(), DeploymentMode.Incremental))
7980
.Returns(expected)
80-
.Callback((ValidatePSResourceGroupDeploymentParameters p) => { actualParameters = p; });
81+
.Callback((ValidatePSResourceGroupDeploymentParameters p, DeploymentMode m) => { actualParameters = p; m = DeploymentMode.Incremental; });
8182

8283
cmdlet.ResourceGroupName = resourceGroupName;
8384
cmdlet.TemplateFile = expectedParameters.TemplateFile;
@@ -123,9 +124,9 @@ public void ValidatesPSResourceGroupDeploymentWithGalleryTemplate()
123124
}
124125
};
125126
resourcesClientMock.Setup(f => f.ValidatePSResourceGroupDeployment(
126-
It.IsAny<ValidatePSResourceGroupDeploymentParameters>()))
127+
It.IsAny<ValidatePSResourceGroupDeploymentParameters>(), DeploymentMode.Incremental))
127128
.Returns(expected)
128-
.Callback((ValidatePSResourceGroupDeploymentParameters p) => { actualParameters = p; });
129+
.Callback((ValidatePSResourceGroupDeploymentParameters p, DeploymentMode m) => { actualParameters = p; m = DeploymentMode.Incremental; });
129130

130131
cmdlet.ResourceGroupName = resourceGroupName;
131132
cmdlet.GalleryTemplateIdentity = expectedParameters.GalleryTemplateIdentity;

src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/CreatePSDeploymentParameters.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Management.Resources.Models;
1516

1617
namespace Microsoft.Azure.Commands.Resources.Models
1718
{
1819
public class CreatePSResourceGroupDeploymentParameters : ValidatePSResourceGroupDeploymentParameters
1920
{
2021
public string DeploymentName { get; set; }
22+
23+
public DeploymentMode DeploymentMode { get; set; }
2124
}
2225
}

src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.ResourceManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public virtual List<GenericResourceExtended> FilterResources(FilterResourcesOpti
302302
public virtual PSResourceGroupDeployment ExecuteDeployment(CreatePSResourceGroupDeploymentParameters parameters)
303303
{
304304
parameters.DeploymentName = GenerateDeploymentName(parameters);
305-
Deployment deployment = CreateBasicDeployment(parameters);
305+
Deployment deployment = CreateBasicDeployment(parameters, parameters.DeploymentMode);
306306
TemplateValidationInfo validationInfo = CheckBasicDeploymentErrors(parameters.ResourceGroupName, parameters.DeploymentName, deployment);
307307

308308
if (validationInfo.Errors.Count != 0)
@@ -563,9 +563,9 @@ public virtual void CancelDeployment(string resourceGroup, string deploymentName
563563
/// </summary>
564564
/// <param name="parameters">The deployment create options</param>
565565
/// <returns>True if valid, false otherwise.</returns>
566-
public virtual List<PSResourceManagerError> ValidatePSResourceGroupDeployment(ValidatePSResourceGroupDeploymentParameters parameters)
566+
public virtual List<PSResourceManagerError> ValidatePSResourceGroupDeployment(ValidatePSResourceGroupDeploymentParameters parameters, DeploymentMode deploymentMode)
567567
{
568-
Deployment deployment = CreateBasicDeployment(parameters);
568+
Deployment deployment = CreateBasicDeployment(parameters, deploymentMode);
569569
TemplateValidationInfo validationInfo = CheckBasicDeploymentErrors(parameters.ResourceGroupName, Guid.NewGuid().ToString(), deployment);
570570

571571
if (validationInfo.Errors.Count == 0)

src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,12 @@ private List<DeploymentOperation> GetNewOperations(List<DeploymentOperation> old
324324
return newOperations;
325325
}
326326

327-
private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParameters parameters)
327+
private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParameters parameters, DeploymentMode deploymentMode)
328328
{
329329
Deployment deployment = new Deployment
330330
{
331331
Properties = new DeploymentProperties {
332-
Mode = DeploymentMode.Incremental,
332+
Mode = deploymentMode,
333333
Template = GetTemplate(parameters.TemplateFile, parameters.GalleryTemplateIdentity),
334334
Parameters = GetDeploymentParameters(parameters.TemplateParameterObject)
335335
}

src/ResourceManager/Resources/Commands.Resources/ResourceGroupDeployments/NewAzureResourceGroupDeploymentCommand.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using System.Management.Automation;
1616
using Microsoft.Azure.Commands.Resources.Models;
17+
using Microsoft.Azure.Management.Resources.Models;
1718
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1819

1920
namespace Microsoft.Azure.Commands.Resources
@@ -34,20 +35,47 @@ public class NewAzureResourceGroupDeploymentCommand : ResourceWithParameterBaseC
3435
[ValidateNotNullOrEmpty]
3536
public string ResourceGroupName { get; set; }
3637

38+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The deployment mode.")]
39+
public DeploymentMode Mode { get; set; }
40+
41+
[Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation.")]
42+
public SwitchParameter Force { get; set; }
43+
44+
public NewAzureResourceGroupDeploymentCommand()
45+
{
46+
this.Mode = DeploymentMode.Incremental;
47+
}
48+
3749
public override void ExecuteCmdlet()
3850
{
3951
CreatePSResourceGroupDeploymentParameters parameters = new CreatePSResourceGroupDeploymentParameters()
4052
{
4153
ResourceGroupName = ResourceGroupName,
4254
DeploymentName = Name,
55+
DeploymentMode = Mode,
4356
GalleryTemplateIdentity = GalleryTemplateIdentity,
4457
TemplateFile = TemplateUri ?? this.TryResolvePath(TemplateFile),
4558
TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject),
4659
TemplateVersion = TemplateVersion,
4760
StorageAccountName = StorageAccountName
4861
};
4962

50-
WriteObject(ResourcesClient.ExecuteDeployment(parameters));
63+
if(this.Mode == DeploymentMode.Complete)
64+
{
65+
this.ConfirmAction(
66+
this.Force,
67+
"Are you sure you want to use the complete deployment mode? Resources in the resource group '" + ResourceGroupName + "' which are not included in the template will be deleted.",
68+
"Creating a deployment with Complete mode",
69+
ResourceGroupName,
70+
() =>
71+
{
72+
WriteObject(ResourcesClient.ExecuteDeployment(parameters));
73+
});
74+
}
75+
else
76+
{
77+
WriteObject(ResourcesClient.ExecuteDeployment(parameters));
78+
}
5179
}
5280
}
5381
}

src/ResourceManager/Resources/Commands.Resources/Templates/TestAzureResourceGroupTemplateCommand.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Collections.Generic;
1616
using System.Management.Automation;
1717
using Microsoft.Azure.Commands.Resources.Models;
18+
using Microsoft.Azure.Management.Resources.Models;
1819
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1920

2021
namespace Microsoft.Azure.Commands.Resources.ResourceGroupDeployments
@@ -29,6 +30,14 @@ public class TestAzureResourceGroupTemplateCommand : ResourceWithParameterBaseCm
2930
[ValidateNotNullOrEmpty]
3031
public string ResourceGroupName { get; set; }
3132

33+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The deployment mode.")]
34+
public DeploymentMode Mode { get; set; }
35+
36+
public TestAzureResourceGroupTemplateCommand()
37+
{
38+
this.Mode = DeploymentMode.Incremental;
39+
}
40+
3241
public override void ExecuteCmdlet()
3342
{
3443
ValidatePSResourceGroupDeploymentParameters parameters = new ValidatePSResourceGroupDeploymentParameters()
@@ -41,7 +50,7 @@ public override void ExecuteCmdlet()
4150
StorageAccountName = StorageAccountName
4251
};
4352

44-
WriteObject(ResourcesClient.ValidatePSResourceGroupDeployment(parameters));
53+
WriteObject(ResourcesClient.ValidatePSResourceGroupDeployment(parameters, Mode));
4554
}
4655
}
4756
}

0 commit comments

Comments
 (0)