Skip to content

Commit 616f7fd

Browse files
committed
adding tags
1 parent c1bd480 commit 616f7fd

File tree

9 files changed

+70
-24
lines changed

9 files changed

+70
-24
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ public class NewAzManagementGroupDeploymentStack : DeploymentStacksCmdletBase
152152
HelpMessage = "The subscription id at which the deployment should be created.")]
153153
public string DeploymentSubscriptionId { get; set; }
154154

155+
[Parameter(Mandatory = false, HelpMessage = "The tags to put on the deployment.")]
156+
[ValidateNotNullOrEmpty]
157+
public Hashtable Tag { get; set; }
158+
155159
[Parameter(Mandatory = false,
156160
HelpMessage = "Do not ask for confirmation when overwriting an existing stack.")]
157161
public SwitchParameter Force { get; set; }
@@ -253,7 +257,8 @@ protected override void OnProcessRecord()
253257
DenySettingsMode.ToString(),
254258
DenySettingsExcludedPrincipals,
255259
DenySettingsExcludedActions,
256-
DenySettingsApplyToChildScopes.IsPresent
260+
DenySettingsApplyToChildScopes.IsPresent,
261+
Tag
257262
);
258263

259264
WriteObject(deploymentStack);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ public class NewAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase
144144
[Parameter(Mandatory = false, HelpMessage = "Apply to child scopes.")]
145145
public SwitchParameter DenySettingsApplyToChildScopes { get; set; }
146146

147+
[Parameter(Mandatory = false, HelpMessage = "The tags to put on the deployment.")]
148+
[ValidateNotNullOrEmpty]
149+
public Hashtable Tag { get; set; }
150+
147151
[Parameter(Mandatory = false,
148152
HelpMessage = "Do not ask for confirmation when overwriting an existing stack.")]
149153
public SwitchParameter Force { get; set; }
@@ -239,7 +243,8 @@ protected override void OnProcessRecord()
239243
DenySettingsMode.ToString(),
240244
DenySettingsExcludedPrincipals,
241245
DenySettingsExcludedActions,
242-
DenySettingsApplyToChildScopes.IsPresent
246+
DenySettingsApplyToChildScopes.IsPresent,
247+
Tag
243248
);
244249

245250
WriteObject(deploymentStack);

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ public class NewAzSubscriptionDeploymentStack : DeploymentStacksCmdletBase
145145
[Parameter(Mandatory = false,
146146
HelpMessage = "The ResourceGroup at which the deployment will be created. If none is specified, it will default to the " +
147147
"subscription level scope of the deployment stack.")]
148-
public string ResourceGroupName { get; set; }
148+
public string DeploymentResourceGroupName { get; set; }
149+
150+
[Parameter(Mandatory = false, HelpMessage = "The tags to put on the deployment.")]
151+
[ValidateNotNullOrEmpty]
152+
public Hashtable Tag { get; set; }
149153

150154
[Parameter(Mandatory = false,
151155
HelpMessage = "Do not ask for confirmation when overwriting an existing stack.")]
@@ -227,8 +231,8 @@ protected override void OnProcessRecord()
227231
var shouldDeleteResourceGroups = (DeleteAll.ToBool() || DeleteResourceGroups.ToBool()) ? true : false;
228232

229233
// construct deploymentScope if ResourceGroup was provided
230-
var deploymentScope = ResourceGroupName != null ? "/subscriptions/" + DeploymentStacksSdkClient.DeploymentStacksClient.SubscriptionId
231-
+ "/resourceGroups/" + ResourceGroupName : null;
234+
var deploymentScope = DeploymentResourceGroupName != null ? "/subscriptions/" + DeploymentStacksSdkClient.DeploymentStacksClient.SubscriptionId
235+
+ "/resourceGroups/" + DeploymentResourceGroupName : null;
232236

233237
Action createOrUpdateAction = () =>
234238
{
@@ -247,7 +251,8 @@ protected override void OnProcessRecord()
247251
DenySettingsMode.ToString(),
248252
DenySettingsExcludedPrincipals,
249253
DenySettingsExcludedActions,
250-
DenySettingsApplyToChildScopes.IsPresent
254+
DenySettingsApplyToChildScopes.IsPresent,
255+
Tag
251256
);
252257

253258
WriteObject(deploymentStack);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ public class SetAzManagementGroupDeploymentStack : DeploymentStacksCmdletBase
154154
[Parameter(Mandatory = false, HelpMessage = "Apply to child scopes.")]
155155
public SwitchParameter DenySettingsApplyToChildScopes { get; set; }
156156

157+
[Parameter(Mandatory = false, HelpMessage = "The tags to put on the deployment.")]
158+
[ValidateNotNullOrEmpty]
159+
public Hashtable Tag { get; set; }
160+
157161
[Parameter(Mandatory = false,
158162
HelpMessage = "Do not ask for confirmation when overwriting an existing stack.")]
159163
public SwitchParameter Force { get; set; }
@@ -254,7 +258,8 @@ protected override void OnProcessRecord()
254258
DenySettingsMode.ToString(),
255259
DenySettingsExcludedPrincipals,
256260
DenySettingsExcludedActions,
257-
DenySettingsApplyToChildScopes.IsPresent
261+
DenySettingsApplyToChildScopes.IsPresent,
262+
Tag
258263
);
259264

260265
WriteObject(deploymentStack);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ public class SetAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase
146146
[Parameter(Mandatory = false, HelpMessage = "Apply to child scopes.")]
147147
public SwitchParameter DenySettingsApplyToChildScopes { get; set; }
148148

149+
[Parameter(Mandatory = false, HelpMessage = "The tags to put on the deployment.")]
150+
[ValidateNotNullOrEmpty]
151+
public Hashtable Tag { get; set; }
152+
149153
[Parameter(Mandatory = false,
150154
HelpMessage = "Do not ask for confirmation when overwriting an existing stack.")]
151155
public SwitchParameter Force { get; set; }
@@ -241,7 +245,8 @@ protected override void OnProcessRecord()
241245
DenySettingsMode.ToString(),
242246
DenySettingsExcludedPrincipals,
243247
DenySettingsExcludedActions,
244-
DenySettingsApplyToChildScopes.IsPresent
248+
DenySettingsApplyToChildScopes.IsPresent,
249+
Tag
245250
);
246251

247252
WriteObject(deploymentStack);

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public class SetAzSubscriptionDeploymentStack : DeploymentStacksCmdletBase
121121
[Parameter(Mandatory = false,
122122
HelpMessage = "The ResourceGroup at which the deployment will be created. If none is specified, it will default to the " +
123123
"subscription level scope of the deployment stack.")]
124-
public string ResourceGroupName { get; set; }
124+
public string DeploymentResourceGroupName { get; set; }
125125

126126
[Parameter(Mandatory = false, HelpMessage = "Signal to delete both unmanaged Resources and ResourceGroups after deleting stack.")]
127127
public SwitchParameter DeleteAll { get; set; }
@@ -149,6 +149,10 @@ public class SetAzSubscriptionDeploymentStack : DeploymentStacksCmdletBase
149149
[Parameter(Mandatory = false, HelpMessage = "Apply to child scopes.")]
150150
public SwitchParameter DenySettingsApplyToChildScopes { get; set; }
151151

152+
[Parameter(Mandatory = false, HelpMessage = "The tags to put on the deployment.")]
153+
[ValidateNotNullOrEmpty]
154+
public Hashtable Tag { get; set; }
155+
152156
[Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation when overwriting an existing stack.")]
153157
public SwitchParameter Force { get; set; }
154158

@@ -228,8 +232,8 @@ protected override void OnProcessRecord()
228232
var shouldDeleteResourceGroups = (DeleteAll.ToBool() || DeleteResourceGroups.ToBool()) ? true : false;
229233

230234
// construct deploymentScope if ResourceGroup was provided
231-
var deploymentScope = ResourceGroupName != null ? "/subscriptions/" + DeploymentStacksSdkClient.DeploymentStacksClient.SubscriptionId
232-
+ "/resourceGroups/" + ResourceGroupName : null;
235+
var deploymentScope = DeploymentResourceGroupName != null ? "/subscriptions/" + DeploymentStacksSdkClient.DeploymentStacksClient.SubscriptionId
236+
+ "/resourceGroups/" + DeploymentResourceGroupName : null;
233237

234238
Action createOrUpdateAction = () =>
235239
{
@@ -248,7 +252,8 @@ protected override void OnProcessRecord()
248252
DenySettingsMode.ToString(),
249253
DenySettingsExcludedPrincipals,
250254
DenySettingsExcludedActions,
251-
DenySettingsApplyToChildScopes.IsPresent
255+
DenySettingsApplyToChildScopes.IsPresent,
256+
Tag
252257
);
253258

254259
WriteObject(deploymentStack);

src/Resources/ResourceManager/SdkClient/DeploymentStacksSdkClient.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ public PSDeploymentStack ResourceGroupCreateOrUpdateDeploymentStack(
364364
string denySettingsMode,
365365
string[] denySettingsExcludedPrincipales,
366366
string[] denySettingsExcludedActions,
367-
bool denySettingsApplyToChildScopes
367+
bool denySettingsApplyToChildScopes,
368+
Hashtable tags
368369
)
369370
{
370371
var actionOnUnmanage = new DeploymentStackPropertiesSharedActionOnUnmanage
@@ -386,7 +387,8 @@ bool denySettingsApplyToChildScopes
386387
{
387388
Description = description,
388389
ActionOnUnmanage = actionOnUnmanage,
389-
DenySettings = denySettings
390+
DenySettings = denySettings,
391+
Tags = TagsHelper.ConvertToTagsDictionary(tags)
390392
};
391393

392394
DeploymentStacksTemplateLink templateLink = new DeploymentStacksTemplateLink();
@@ -485,7 +487,8 @@ public PSDeploymentStack SubscriptionCreateOrUpdateDeploymentStack(
485487
string denySettingsMode,
486488
string[] denySettingsExcludedPrincipales,
487489
string[] denySettingsExcludedActions,
488-
bool denySettingsApplyToChildScopes
490+
bool denySettingsApplyToChildScopes,
491+
Hashtable tags
489492
)
490493
{
491494
var actionOnUnmanage = new DeploymentStackPropertiesSharedActionOnUnmanage
@@ -509,7 +512,8 @@ bool denySettingsApplyToChildScopes
509512
Location = location,
510513
ActionOnUnmanage = actionOnUnmanage,
511514
DeploymentScope = deploymentScope,
512-
DenySettings = denySettings
515+
DenySettings = denySettings,
516+
Tags = TagsHelper.ConvertToTagsDictionary(tags)
513517
};
514518

515519
DeploymentStacksTemplateLink templateLink = new DeploymentStacksTemplateLink();
@@ -594,7 +598,8 @@ public PSDeploymentStack ManagementGroupCreateOrUpdateDeploymentStack(
594598
string denySettingsMode,
595599
string[] denySettingsExcludedPrincipales,
596600
string[] denySettingsExcludedActions,
597-
bool denySettingsApplyToChildScopes
601+
bool denySettingsApplyToChildScopes,
602+
Hashtable tags
598603
)
599604
{
600605
var actionOnUnmanage = new DeploymentStackPropertiesSharedActionOnUnmanage
@@ -617,7 +622,8 @@ bool denySettingsApplyToChildScopes
617622
Location = location,
618623
ActionOnUnmanage = actionOnUnmanage,
619624
DeploymentScope = deploymentScope,
620-
DenySettings = denySettings
625+
DenySettings = denySettings,
626+
Tags = TagsHelper.ConvertToTagsDictionary(tags)
621627
};
622628

623629
DeploymentStacksTemplateLink templateLink = new DeploymentStacksTemplateLink();

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ function Test-NewResourceGroupDeploymentStack
8888

8989
# --- ParameterlessTemplateFileParameterSetName ---
9090

91-
# Test - Success
92-
$deployment = New-AzResourceGroupDeploymentStack -Name $rname -Description "A Stack" -ResourceGroup $rgname -TemplateFile blankTemplate.json -Force
91+
# Test - Success (with tags)
92+
$deployment = New-AzResourceGroupDeploymentStack -Name $rname -Description "A Stack" -ResourceGroup $rgname -TemplateFile blankTemplate.json -Tag @{"key1" = "value1"; "key2" = "value2"} -Force
9393
Assert-AreEqual "succeeded" $deployment.ProvisioningState
94+
Assert-AreEqual 2 $deployment.Tags.Count
9495

9596
# Test - Failure - template file not found
9697
$missingFile = "missingFile142.json"
@@ -618,9 +619,10 @@ function Test-NewSubscriptionDeploymentStack
618619

619620
# --- ParameterlessTemplateFileParameterSetName ---
620621

621-
# Test - Success
622-
$deployment = New-AzSubscriptionDeploymentStack -Name $rname -Description "A Stack" -TemplateFile blankTemplate.json -Location $location -Force
622+
# Test - Success (with tags)
623+
$deployment = New-AzSubscriptionDeploymentStack -Name $rname -Description "A Stack" -TemplateFile blankTemplate.json -Location $location -Tag @{"key1" = "value1"; "key2" = "value2"} -Force
623624
Assert-AreEqual "succeeded" $deployment.ProvisioningState
625+
Assert-AreEqual 2 $deployment.Tags.Count
624626

625627
# Test - Failure - template file not found
626628
$missingFile = "missingFile142.json"
@@ -1108,9 +1110,10 @@ function Test-NewManagementGroupDeploymentStack
11081110

11091111
# --- ParameterlessTemplateFileParameterSetName ---
11101112

1111-
# Test - Success
1112-
$deployment = New-AzManagementGroupDeploymentStack -Name $rname -Description "A Stack" -ManagementGroupId $mgId -TemplateFile blankTemplate.json -DeploymentScopeId $subId -Force
1113+
# Test - Success (with tags)
1114+
$deployment = New-AzManagementGroupDeploymentStack -Name $rname -Description "A Stack" -ManagementGroupId $mgId -TemplateFile blankTemplate.json -DeploymentScopeId $subId -Tag @{"key1" = "value1"; "key2" = "value2"} -Force
11131115
Assert-AreEqual "succeeded" $deployment.ProvisioningState
1116+
Assert-AreEqual 2 $deployment.Tags.Count
11141117

11151118
# Test - Failure - template file not found
11161119
$missingFile = "missingFile142.json"

src/Resources/Resources/Resources.format.ps1xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,13 @@
520520
<ScriptBlock>$_.Parameters -ne $null -And $_.Parameters.Keys.Count -ne 0</ScriptBlock>
521521
</ItemSelectionCondition>
522522
<ScriptBlock>$s = ""; foreach($v in $_.Parameters.Keys) { $n = ""; if ($s -ne "") { $n = "`n"; } $s = $s + $n + "{" + "Name: " + $v + ", Type: " + $_.Parameters[$v].Type + ", " + "Value: " + $_.Parameters[$v].Value + "}"} $s;</ScriptBlock>
523+
</ListItem>
524+
<ListItem>
525+
<Label>Tags</Label>
526+
<ItemSelectionCondition>
527+
<ScriptBlock>$_.Tags -ne $null -And $_.Tags.Keys.Count -ne 0</ScriptBlock>
528+
</ItemSelectionCondition>
529+
<ScriptBlock>$s = ""; foreach($v in $_.Tags.Keys) { $n = ""; if ($s -ne "") { $n = "`n"; } $s = $s + $n + "{" + "Key: " + $v + ", Value: " + $_.Tags[$v] + "}"} $s;</ScriptBlock>
523530
</ListItem>
524531
<ListItem>
525532
<Label>ResourcesCleanupAction</Label>

0 commit comments

Comments
 (0)