forked from Azure/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing Test cmdlets for Deployment Stacks Validation. (Azure#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]>
- Loading branch information
1 parent
f2c1ce8
commit d1d1ac8
Showing
19 changed files
with
6,005 additions
and
524 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...s/ResourceManager/Implementation/DeploymentStacks/TestAzManagementGroupDeploymentStack.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation | ||
{ | ||
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks; | ||
using Microsoft.Azure.Management.Resources.Models; | ||
using System; | ||
using System.Management.Automation; | ||
|
||
[Cmdlet("Test", Common.AzureRMConstants.AzureRMPrefix + "ManagementGroupDeploymentStack", | ||
SupportsShouldProcess = true, DefaultParameterSetName = ParameterlessTemplateFileParameterSetName), OutputType(typeof(bool))] | ||
public class TestAzManagementGroupDeploymentStack : NewAzManagementGroupDeploymentStack | ||
{ | ||
|
||
[Parameter(Mandatory = false, HelpMessage = "If set, a boolean will be returned with value dependent on cmdlet success.")] | ||
public SwitchParameter PassThru { get; set; } | ||
|
||
protected override void OnProcessRecord() | ||
{ | ||
try | ||
{ | ||
var shouldDeleteResources = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll || ActionOnUnmanage is PSActionOnUnmanage.DeleteResources) ? true : false; | ||
var shouldDeleteResourceGroups = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll) ? true : false; | ||
var shouldDeleteManagementGroups = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll) ? true : false; | ||
|
||
string deploymentScope = null; | ||
if (DeploymentSubscriptionId != null) | ||
{ | ||
deploymentScope = "/subscriptions/" + DeploymentSubscriptionId; | ||
} | ||
|
||
DeploymentStacksSdkClient.ManagementGroupValidateDeploymentStack( | ||
deploymentStackName: Name, | ||
managementGroupId: ManagementGroupId, | ||
location: Location, | ||
templateFile: TemplateFile, | ||
templateUri: !string.IsNullOrEmpty(protectedTemplateUri) ? protectedTemplateUri : TemplateUri, | ||
templateSpec: TemplateSpecId, | ||
templateObject: TemplateObject, | ||
parameterUri: TemplateParameterUri, | ||
parameters: GetTemplateParameterObject(), | ||
description: Description, | ||
resourcesCleanupAction: shouldDeleteResources ? "delete" : "detach", | ||
resourceGroupsCleanupAction: shouldDeleteResourceGroups ? "delete" : "detach", | ||
managementGroupsCleanupAction: shouldDeleteManagementGroups ? "delete" : "detach", | ||
deploymentScope: deploymentScope, | ||
denySettingsMode: DenySettingsMode.ToString(), | ||
denySettingsExcludedPrincipals: DenySettingsExcludedPrincipal, | ||
denySettingsExcludedActions: DenySettingsExcludedAction, | ||
denySettingsApplyToChildScopes: DenySettingsApplyToChildScopes.IsPresent, | ||
tags: Tag, | ||
bypassStackOutOfSyncError: BypassStackOutOfSyncError.IsPresent | ||
); | ||
|
||
if (PassThru.IsPresent) | ||
{ | ||
WriteObject(true); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
if (ex is DeploymentStacksErrorException dex) | ||
throw new PSArgumentException(dex.Message + " : " + dex.Body.Error.Code + " : " + dex.Body.Error.Message); | ||
else | ||
WriteExceptionError(ex); | ||
} | ||
} | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...ces/ResourceManager/Implementation/DeploymentStacks/TestAzResourceGroupDeploymentStack.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation | ||
{ | ||
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient; | ||
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks; | ||
using Microsoft.Azure.Commands.ResourceManager.Common.Tags; | ||
using Microsoft.Azure.Management.Resources.Models; | ||
using System; | ||
using System.Management.Automation; | ||
|
||
[Cmdlet("Test", Common.AzureRMConstants.AzureRMPrefix + "ResourceGroupDeploymentStack", | ||
SupportsShouldProcess = true, DefaultParameterSetName = ParameterlessTemplateFileParameterSetName), OutputType(typeof(bool))] | ||
public class TestAzResourceGroupDeploymentStack : NewAzResourceGroupDeploymentStack | ||
{ | ||
[Parameter(Mandatory = false, HelpMessage = "If set, a boolean will be returned with value dependent on cmdlet success.")] | ||
public SwitchParameter PassThru { get; set; } | ||
|
||
protected override void OnProcessRecord() | ||
{ | ||
try | ||
{ | ||
var shouldDeleteResources = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll || ActionOnUnmanage is PSActionOnUnmanage.DeleteResources) ? true : false; | ||
var shouldDeleteResourceGroups = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll) ? true : false; | ||
var shouldDeleteManagementGroups = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll) ? true : false; | ||
|
||
var currentStack = DeploymentStacksSdkClient.GetResourceGroupDeploymentStack(ResourceGroupName, Name, throwIfNotExists: false); | ||
if (currentStack != null && Tag == null) | ||
{ | ||
Tag = TagsConversionHelper.CreateTagHashtable(currentStack.tags); | ||
} | ||
|
||
DeploymentStacksSdkClient.ResourceGroupValidateDeploymentStack( | ||
deploymentStackName: Name, | ||
resourceGroupName: ResourceGroupName, | ||
templateFile: TemplateFile, | ||
templateUri: !string.IsNullOrEmpty(protectedTemplateUri) ? protectedTemplateUri : TemplateUri, | ||
templateSpec: TemplateSpecId, | ||
templateObject: TemplateObject, | ||
parameterUri: TemplateParameterUri, | ||
parameters: GetTemplateParameterObject(), | ||
description: Description, | ||
resourcesCleanupAction: shouldDeleteResources ? "delete" : "detach", | ||
resourceGroupsCleanupAction: shouldDeleteResourceGroups ? "delete" : "detach", | ||
managementGroupsCleanupAction: shouldDeleteManagementGroups ? "delete" : "detach", | ||
denySettingsMode: DenySettingsMode.ToString(), | ||
denySettingsExcludedPrincipals: DenySettingsExcludedPrincipal, | ||
denySettingsExcludedActions: DenySettingsExcludedAction, | ||
denySettingsApplyToChildScopes: DenySettingsApplyToChildScopes.IsPresent, | ||
tags: Tag, | ||
bypassStackOutOfSyncError: BypassStackOutOfSyncError.IsPresent | ||
); | ||
|
||
if (PassThru.IsPresent) | ||
{ | ||
WriteObject(true); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
if (ex is DeploymentStacksErrorException dex) | ||
throw new PSArgumentException(dex.Message + " : " + dex.Body.Error.Code + " : " + dex.Body.Error.Message); | ||
else | ||
WriteExceptionError(ex); | ||
} | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...rces/ResourceManager/Implementation/DeploymentStacks/TestAzSubscriptionDeploymentStack.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation | ||
{ | ||
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient; | ||
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks; | ||
using Microsoft.Azure.Commands.ResourceManager.Common.Tags; | ||
using Microsoft.Azure.Management.Resources.Models; | ||
using System; | ||
using System.Management.Automation; | ||
|
||
[Cmdlet("Test", Common.AzureRMConstants.AzureRMPrefix + "SubscriptionDeploymentStack", | ||
SupportsShouldProcess = true, DefaultParameterSetName = ParameterlessTemplateFileParameterSetName), OutputType(typeof(bool))] | ||
public class TestAzSubscriptionDeploymentStack : NewAzSubscriptionDeploymentStack | ||
{ | ||
|
||
[Parameter(Mandatory = false, HelpMessage = "If set, a boolean will be returned with value dependent on cmdlet success.")] | ||
public SwitchParameter PassThru { get; set; } | ||
|
||
protected override void OnProcessRecord() | ||
{ | ||
try | ||
{ | ||
var shouldDeleteResources = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll || ActionOnUnmanage is PSActionOnUnmanage.DeleteResources) ? true : false; | ||
var shouldDeleteResourceGroups = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll) ? true : false; | ||
var shouldDeleteManagementGroups = (ActionOnUnmanage is PSActionOnUnmanage.DeleteAll) ? true : false; | ||
|
||
// construct deploymentScope if ResourceGroup was provided | ||
var deploymentScope = DeploymentResourceGroupName != null ? "/subscriptions/" + DeploymentStacksSdkClient.DeploymentStacksClient.SubscriptionId | ||
+ "/resourceGroups/" + DeploymentResourceGroupName : null; | ||
|
||
var currentStack = DeploymentStacksSdkClient.GetSubscriptionDeploymentStack(Name, throwIfNotExists: false); | ||
if (currentStack != null && Tag == null) | ||
{ | ||
Tag = TagsConversionHelper.CreateTagHashtable(currentStack.tags); | ||
} | ||
|
||
DeploymentStacksSdkClient.SubscriptionValidateDeploymentStack( | ||
deploymentStackName: Name, | ||
location: Location, | ||
templateFile: TemplateFile, | ||
templateUri: !string.IsNullOrEmpty(protectedTemplateUri) ? protectedTemplateUri : TemplateUri, | ||
templateSpec: TemplateSpecId, | ||
templateObject: TemplateObject, | ||
parameterUri: TemplateParameterUri, | ||
parameters: GetTemplateParameterObject(), | ||
description: Description, | ||
resourcesCleanupAction: shouldDeleteResources ? "delete" : "detach", | ||
resourceGroupsCleanupAction: shouldDeleteResourceGroups ? "delete" : "detach", | ||
managementGroupsCleanupAction: shouldDeleteManagementGroups ? "delete" : "detach", | ||
deploymentScope: deploymentScope, | ||
denySettingsMode: DenySettingsMode.ToString(), | ||
denySettingsExcludedPrincipals: DenySettingsExcludedPrincipal, | ||
denySettingsExcludedActions: DenySettingsExcludedAction, | ||
denySettingsApplyToChildScopes: DenySettingsApplyToChildScopes.IsPresent, | ||
tags: Tag, | ||
bypassStackOutOfSyncError: BypassStackOutOfSyncError.IsPresent | ||
); | ||
|
||
if (PassThru.IsPresent) | ||
{ | ||
WriteObject(true); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
if (ex is DeploymentStacksErrorException dex) | ||
throw new PSArgumentException(dex.Message + " : " + dex.Body.Error.Code + " : " + dex.Body.Error.Message); | ||
else | ||
WriteExceptionError(ex); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.