Skip to content

Commit d1d1ac8

Browse files
Implementing Test cmdlets for Deployment Stacks Validation. (#25363)
* Implementing Test cmdlets for Deployment Stacks Validation. Standalone Test cmdlets so validation can be run on deployment stacks without having to actually deploy. * update a session record. * added help files * Updated help files. * Update help. * Update SignatureIssues.csv --------- Co-authored-by: Dante DG <test> Co-authored-by: Yabo Hu <[email protected]>
1 parent f2c1ce8 commit d1d1ac8

19 files changed

+6005
-524
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1919
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks;
2020
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
2121
using Microsoft.Azure.Management.Resources.Models;
22-
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
2322
using System;
2423
using System.Collections;
2524
using System.Management.Automation;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1919
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks;
2020
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
2121
using Microsoft.Azure.Management.Resources.Models;
22-
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
2322
using System;
2423
using System.Collections;
2524
using System.Management.Automation;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
16+
{
17+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks;
18+
using Microsoft.Azure.Management.Resources.Models;
19+
using System;
20+
using System.Management.Automation;
21+
22+
[Cmdlet("Test", Common.AzureRMConstants.AzureRMPrefix + "ManagementGroupDeploymentStack",
23+
SupportsShouldProcess = true, DefaultParameterSetName = ParameterlessTemplateFileParameterSetName), OutputType(typeof(bool))]
24+
public class TestAzManagementGroupDeploymentStack : NewAzManagementGroupDeploymentStack
25+
{
26+
27+
[Parameter(Mandatory = false, HelpMessage = "If set, a boolean will be returned with value dependent on cmdlet success.")]
28+
public SwitchParameter PassThru { get; set; }
29+
30+
protected override void OnProcessRecord()
31+
{
32+
try
33+
{
34+
var shouldDeleteResources = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll || ActionOnUnmanage is PSActionOnUnmanage.DeleteResources) ? true : false;
35+
var shouldDeleteResourceGroups = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll) ? true : false;
36+
var shouldDeleteManagementGroups = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll) ? true : false;
37+
38+
string deploymentScope = null;
39+
if (DeploymentSubscriptionId != null)
40+
{
41+
deploymentScope = "/subscriptions/" + DeploymentSubscriptionId;
42+
}
43+
44+
DeploymentStacksSdkClient.ManagementGroupValidateDeploymentStack(
45+
deploymentStackName: Name,
46+
managementGroupId: ManagementGroupId,
47+
location: Location,
48+
templateFile: TemplateFile,
49+
templateUri: !string.IsNullOrEmpty(protectedTemplateUri) ? protectedTemplateUri : TemplateUri,
50+
templateSpec: TemplateSpecId,
51+
templateObject: TemplateObject,
52+
parameterUri: TemplateParameterUri,
53+
parameters: GetTemplateParameterObject(),
54+
description: Description,
55+
resourcesCleanupAction: shouldDeleteResources ? "delete" : "detach",
56+
resourceGroupsCleanupAction: shouldDeleteResourceGroups ? "delete" : "detach",
57+
managementGroupsCleanupAction: shouldDeleteManagementGroups ? "delete" : "detach",
58+
deploymentScope: deploymentScope,
59+
denySettingsMode: DenySettingsMode.ToString(),
60+
denySettingsExcludedPrincipals: DenySettingsExcludedPrincipal,
61+
denySettingsExcludedActions: DenySettingsExcludedAction,
62+
denySettingsApplyToChildScopes: DenySettingsApplyToChildScopes.IsPresent,
63+
tags: Tag,
64+
bypassStackOutOfSyncError: BypassStackOutOfSyncError.IsPresent
65+
);
66+
67+
if (PassThru.IsPresent)
68+
{
69+
WriteObject(true);
70+
}
71+
}
72+
catch (Exception ex)
73+
{
74+
if (ex is DeploymentStacksErrorException dex)
75+
throw new PSArgumentException(dex.Message + " : " + dex.Body.Error.Code + " : " + dex.Body.Error.Message);
76+
else
77+
WriteExceptionError(ex);
78+
}
79+
}
80+
}
81+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
16+
{
17+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient;
18+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks;
19+
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
20+
using Microsoft.Azure.Management.Resources.Models;
21+
using System;
22+
using System.Management.Automation;
23+
24+
[Cmdlet("Test", Common.AzureRMConstants.AzureRMPrefix + "ResourceGroupDeploymentStack",
25+
SupportsShouldProcess = true, DefaultParameterSetName = ParameterlessTemplateFileParameterSetName), OutputType(typeof(bool))]
26+
public class TestAzResourceGroupDeploymentStack : NewAzResourceGroupDeploymentStack
27+
{
28+
[Parameter(Mandatory = false, HelpMessage = "If set, a boolean will be returned with value dependent on cmdlet success.")]
29+
public SwitchParameter PassThru { get; set; }
30+
31+
protected override void OnProcessRecord()
32+
{
33+
try
34+
{
35+
var shouldDeleteResources = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll || ActionOnUnmanage is PSActionOnUnmanage.DeleteResources) ? true : false;
36+
var shouldDeleteResourceGroups = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll) ? true : false;
37+
var shouldDeleteManagementGroups = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll) ? true : false;
38+
39+
var currentStack = DeploymentStacksSdkClient.GetResourceGroupDeploymentStack(ResourceGroupName, Name, throwIfNotExists: false);
40+
if (currentStack != null && Tag == null)
41+
{
42+
Tag = TagsConversionHelper.CreateTagHashtable(currentStack.tags);
43+
}
44+
45+
DeploymentStacksSdkClient.ResourceGroupValidateDeploymentStack(
46+
deploymentStackName: Name,
47+
resourceGroupName: ResourceGroupName,
48+
templateFile: TemplateFile,
49+
templateUri: !string.IsNullOrEmpty(protectedTemplateUri) ? protectedTemplateUri : TemplateUri,
50+
templateSpec: TemplateSpecId,
51+
templateObject: TemplateObject,
52+
parameterUri: TemplateParameterUri,
53+
parameters: GetTemplateParameterObject(),
54+
description: Description,
55+
resourcesCleanupAction: shouldDeleteResources ? "delete" : "detach",
56+
resourceGroupsCleanupAction: shouldDeleteResourceGroups ? "delete" : "detach",
57+
managementGroupsCleanupAction: shouldDeleteManagementGroups ? "delete" : "detach",
58+
denySettingsMode: DenySettingsMode.ToString(),
59+
denySettingsExcludedPrincipals: DenySettingsExcludedPrincipal,
60+
denySettingsExcludedActions: DenySettingsExcludedAction,
61+
denySettingsApplyToChildScopes: DenySettingsApplyToChildScopes.IsPresent,
62+
tags: Tag,
63+
bypassStackOutOfSyncError: BypassStackOutOfSyncError.IsPresent
64+
);
65+
66+
if (PassThru.IsPresent)
67+
{
68+
WriteObject(true);
69+
}
70+
}
71+
catch (Exception ex)
72+
{
73+
if (ex is DeploymentStacksErrorException dex)
74+
throw new PSArgumentException(dex.Message + " : " + dex.Body.Error.Code + " : " + dex.Body.Error.Message);
75+
else
76+
WriteExceptionError(ex);
77+
}
78+
}
79+
}
80+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
16+
{
17+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient;
18+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks;
19+
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
20+
using Microsoft.Azure.Management.Resources.Models;
21+
using System;
22+
using System.Management.Automation;
23+
24+
[Cmdlet("Test", Common.AzureRMConstants.AzureRMPrefix + "SubscriptionDeploymentStack",
25+
SupportsShouldProcess = true, DefaultParameterSetName = ParameterlessTemplateFileParameterSetName), OutputType(typeof(bool))]
26+
public class TestAzSubscriptionDeploymentStack : NewAzSubscriptionDeploymentStack
27+
{
28+
29+
[Parameter(Mandatory = false, HelpMessage = "If set, a boolean will be returned with value dependent on cmdlet success.")]
30+
public SwitchParameter PassThru { get; set; }
31+
32+
protected override void OnProcessRecord()
33+
{
34+
try
35+
{
36+
var shouldDeleteResources = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll || ActionOnUnmanage is PSActionOnUnmanage.DeleteResources) ? true : false;
37+
var shouldDeleteResourceGroups = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll) ? true : false;
38+
var shouldDeleteManagementGroups = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll) ? true : false;
39+
40+
// construct deploymentScope if ResourceGroup was provided
41+
var deploymentScope = DeploymentResourceGroupName != null ? "/subscriptions/" + DeploymentStacksSdkClient.DeploymentStacksClient.SubscriptionId
42+
+ "/resourceGroups/" + DeploymentResourceGroupName : null;
43+
44+
var currentStack = DeploymentStacksSdkClient.GetSubscriptionDeploymentStack(Name, throwIfNotExists: false);
45+
if (currentStack != null && Tag == null)
46+
{
47+
Tag = TagsConversionHelper.CreateTagHashtable(currentStack.tags);
48+
}
49+
50+
DeploymentStacksSdkClient.SubscriptionValidateDeploymentStack(
51+
deploymentStackName: Name,
52+
location: Location,
53+
templateFile: TemplateFile,
54+
templateUri: !string.IsNullOrEmpty(protectedTemplateUri) ? protectedTemplateUri : TemplateUri,
55+
templateSpec: TemplateSpecId,
56+
templateObject: TemplateObject,
57+
parameterUri: TemplateParameterUri,
58+
parameters: GetTemplateParameterObject(),
59+
description: Description,
60+
resourcesCleanupAction: shouldDeleteResources ? "delete" : "detach",
61+
resourceGroupsCleanupAction: shouldDeleteResourceGroups ? "delete" : "detach",
62+
managementGroupsCleanupAction: shouldDeleteManagementGroups ? "delete" : "detach",
63+
deploymentScope: deploymentScope,
64+
denySettingsMode: DenySettingsMode.ToString(),
65+
denySettingsExcludedPrincipals: DenySettingsExcludedPrincipal,
66+
denySettingsExcludedActions: DenySettingsExcludedAction,
67+
denySettingsApplyToChildScopes: DenySettingsApplyToChildScopes.IsPresent,
68+
tags: Tag,
69+
bypassStackOutOfSyncError: BypassStackOutOfSyncError.IsPresent
70+
);
71+
72+
if (PassThru.IsPresent)
73+
{
74+
WriteObject(true);
75+
}
76+
}
77+
catch (Exception ex)
78+
{
79+
if (ex is DeploymentStacksErrorException dex)
80+
throw new PSArgumentException(dex.Message + " : " + dex.Body.Error.Code + " : " + dex.Body.Error.Message);
81+
else
82+
WriteExceptionError(ex);
83+
}
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)