Skip to content

Commit 6696350

Browse files
authored
Enable mg deployments in mg scoped stacks (#23019)
* enable mg deployments in new and set * updated create management group cmdlets to not require a deployment sub * fix help files, mg set cmdlet, and fix small issue in mg tests. * small adjustments to cmdlets * updated help files
1 parent 570ecbd commit 6696350

File tree

10 files changed

+10640
-2983
lines changed

10 files changed

+10640
-2983
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public class NewAzManagementGroupDeploymentStack : DeploymentStacksCreateCmdletB
4646
[ValidateNotNullOrEmpty]
4747
public string ManagementGroupId { get; set; }
4848

49+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
50+
HelpMessage = "The subscription id at which the deployment should be created.")]
51+
public string DeploymentSubscriptionId { get; set; }
52+
4953
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
5054
HelpMessage = "Description for the stack")]
5155
public string Description { get; set; }
@@ -76,10 +80,6 @@ public class NewAzManagementGroupDeploymentStack : DeploymentStacksCreateCmdletB
7680
[Parameter(Mandatory = false, HelpMessage = "Apply to child scopes.")]
7781
public SwitchParameter DenySettingsApplyToChildScopes { get; set; }
7882

79-
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true,
80-
HelpMessage = "The subscription id at which the deployment should be created.")]
81-
public string DeploymentSubscriptionId { get; set; }
82-
8383
[Parameter(Mandatory = false, HelpMessage = "The tags to put on the deployment.")]
8484
public Hashtable Tag { get; set; }
8585

@@ -182,8 +182,11 @@ protected override void OnProcessRecord()
182182
var shouldDeleteResources = (DeleteAll.ToBool() || DeleteResources.ToBool()) ? true : false;
183183
var shouldDeleteResourceGroups = (DeleteAll.ToBool() || DeleteResourceGroups.ToBool()) ? true : false;
184184

185-
// construct deploymentScope if ResourceGroup was provided
186-
var deploymentScope = "/subscriptions/" + DeploymentSubscriptionId;
185+
string deploymentScope = null;
186+
if (DeploymentSubscriptionId != null)
187+
{
188+
deploymentScope = "/subscriptions/" + DeploymentSubscriptionId;
189+
}
187190

188191
var currentStack = DeploymentStacksSdkClient.GetManagementGroupDeploymentStack(ManagementGroupId, Name, throwIfNotExists: false);
189192
if (currentStack != null && Tag == null)

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ public class SetAzManagementGroupDeploymentStack : DeploymentStacksCreateCmdletB
4545
[ValidateNotNullOrEmpty]
4646
public string ManagementGroupId { get; set; }
4747

48-
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true,
48+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
4949
HelpMessage = "The subscription Id at which the deployment should be created.")]
50-
[ValidateNotNullOrEmpty]
5150
public string DeploymentSubscriptionId { get; set; }
5251

5352
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true,
@@ -183,8 +182,11 @@ protected override void OnProcessRecord()
183182
var shouldDeleteResources = (DeleteAll.ToBool() || DeleteResources.ToBool()) ? true : false;
184183
var shouldDeleteResourceGroups = (DeleteAll.ToBool() || DeleteResourceGroups.ToBool()) ? true : false;
185184

186-
// construct deploymentScope if ResourceGroup was provided
187-
var deploymentScope = "/subscriptions/" + DeploymentSubscriptionId;
185+
string deploymentScope = null;
186+
if (DeploymentSubscriptionId != null)
187+
{
188+
deploymentScope = "/subscriptions/" + DeploymentSubscriptionId;
189+
}
188190

189191
var currentStack = DeploymentStacksSdkClient.GetManagementGroupDeploymentStack(ManagementGroupId, Name, throwIfNotExists: false);
190192
if (currentStack != null && Tag == null)

src/Resources/Resources.Test/ScenarioTests/DeploymentStackTests.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,10 +1252,14 @@ function Test-NewManagementGroupDeploymentStack
12521252

12531253
# --- ParameterlessTemplateFileParameterSetName ---
12541254

1255-
# Test - Success
1255+
# Test - Success - blank template
12561256
$deployment = New-AzManagementGroupDeploymentStack -Name $rname -Description "A Stack" -ManagementGroupId $mgid -DeploymentSubscriptionId $subId -TemplateFile blankTemplate.json -Location $location -DenySettingsMode None -Force
12571257
Assert-AreEqual "succeeded" $deployment.ProvisioningState
12581258

1259+
# Test - Success - MG scoped deployment
1260+
$deployment = New-AzManagementGroupDeploymentStack -Name $rname -Description "A Stack" -ManagementGroupId $mgid -TemplateFile StacksMGTemplateMGDeployment.json -Location $location -DenySettingsMode None -Force
1261+
Assert-AreEqual "succeeded" $deployment.ProvisioningState
1262+
12591263
# Test - Failure - template file not found
12601264
$missingFile = "missingFile142.json"
12611265
$exceptionMessage = "The provided file $missingFile doesn't exist"
@@ -1439,6 +1443,10 @@ function Test-SetManagementGroupDeploymentStack
14391443
$deployment = Set-AzManagementGroupDeploymentStack -Name $rname -Description "A Stack" -ManagementGroup $mgid -DeploymentSubscriptionId $subId -TemplateFile StacksMGTemplate.json -TemplateParameterFile StacksMGTemplateParams.json -Location $location -DenySettingsMode None -Force
14401444
Assert-AreEqual "succeeded" $deployment.ProvisioningState
14411445

1446+
# Test - Success - MG scoped deployment
1447+
$deployment = Set-AzManagementGroupDeploymentStack -Name $rname -Description "A Stack" -ManagementGroupId $mgid -TemplateFile StacksMGTemplateMGDeployment.json -Location $location -DenySettingsMode None -Force
1448+
Assert-AreEqual "succeeded" $deployment.ProvisioningState
1449+
14421450
# Test - Failure - template file not found
14431451
$missingFile = "missingFile142.json"
14441452
$exceptionMessage = "The provided file $missingFile doesn't exist"

0 commit comments

Comments
 (0)