Skip to content

Commit 7e4b330

Browse files
committed
Update policy help markdown
1 parent 2572887 commit 7e4b330

File tree

8 files changed

+197
-24
lines changed

8 files changed

+197
-24
lines changed

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Policy/NewAzurePolicyAssignment.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ object IDynamicParameters.GetDynamicParameters()
240240
{
241241
foreach (var param in parameters.Properties)
242242
{
243-
if (param.Value is PSObject paramValue)
243+
var paramValue = param.Value as PSObject;
244+
if (paramValue != null)
244245
{
245246
var type = paramValue.Properties["type"];
246247
var typeString = type != null ? type.Value.ToString() : string.Empty;

src/ResourceManager/Resources/Commands.Resources.Test/Commands.Resources.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@
289289
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestSaveDeploymentTemplateFile.json">
290290
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
291291
</None>
292+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.PolicyTests\TestPolicyAssignmentIdentity.json">
293+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
294+
</None>
292295
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.SubscriptionLevelDeploymentTests\TestDeploymentAsJob.json">
293296
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
294297
</None>

src/ResourceManager/Resources/Commands.Resources/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Support managed identity on policy assignments.
22+
* Parameters with default values are no longer requred when assigning a policy with `New-AzureRmPolicyAssignment`
2123

2224
## Version 6.4.2
2325
* Fixed issue with creating managed applications from the MarketPlace.

src/ResourceManager/Resources/Commands.Resources/help/Get-AzureRmPolicyAssignment.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,16 @@ PS C:\> Get-AzureRmPolicyAssignment -Name 'PolicyAssignment07' -Scope $ResourceG
6060
```
6161

6262
The first command gets a resource group named ResourceGroup11 by using the Get-AzureRMResourceGroup cmdletand stores it in the $ResourceGroup variable.
63-
The second command get the policy assignment named PolicyAssignment07 for the scope that the **ResourceId** property of $ResourceGroup identifies.
63+
The second command gets the policy assignment named PolicyAssignment07 for the scope that the **ResourceId** property of $ResourceGroup identifies.
64+
65+
### Example 3: Get all policy assignments assigned to a management group
66+
```
67+
PS C:\> $mgId = 'myManagementGroup'
68+
PS C:\> Get-AzureRmPolicyAssignment -Scope '/providers/Microsoft.Management/managementgroups/$mgId'
69+
```
70+
71+
The first command specifies the ID of the management group to query.
72+
The second command gets all of the policy assignments that are assigned to the management group with ID 'myManagementGroup'.
6473

6574
## PARAMETERS
6675

src/ResourceManager/Resources/Commands.Resources/help/New-AzureRmPolicyAssignment.md

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,45 @@ Creates a policy assignment.
1717
```
1818
New-AzureRmPolicyAssignment -Name <String> -Scope <String> [-NotScope <String[]>] [-DisplayName <String>]
1919
[-Description <String>] [-PolicyDefinition <PSObject>] [-PolicySetDefinition <PSObject>] [-Metadata <String>]
20-
[-Sku <Hashtable>] [-ApiVersion <String>] [-Pre] [-DefaultProfile <IAzureContextContainer>]
21-
[-InformationAction <ActionPreference>] [-InformationVariable <String>] [<CommonParameters>]
20+
[-Sku <Hashtable>] [-AssignIdentity] [-Location <String>] [-ApiVersion <String>] [-Pre]
21+
[-DefaultProfile <IAzureContextContainer>] [-InformationAction <ActionPreference>]
22+
[-InformationVariable <String>] [<CommonParameters>]
2223
```
2324

2425
### PolicyParameterObjectParameterSet
2526
```
2627
New-AzureRmPolicyAssignment -Name <String> -Scope <String> [-NotScope <String[]>] [-DisplayName <String>]
2728
[-Description <String>] -PolicyDefinition <PSObject> [-PolicySetDefinition <PSObject>]
28-
-PolicyParameterObject <Hashtable> [-Metadata <String>] [-Sku <Hashtable>] [-ApiVersion <String>] [-Pre]
29-
[-DefaultProfile <IAzureContextContainer>] [-InformationAction <ActionPreference>]
30-
[-InformationVariable <String>] [<CommonParameters>]
29+
-PolicyParameterObject <Hashtable> [-Metadata <String>] [-Sku <Hashtable>] [-AssignIdentity]
30+
[-Location <String>] [-ApiVersion <String>] [-Pre] [-DefaultProfile <IAzureContextContainer>]
31+
[-InformationAction <ActionPreference>] [-InformationVariable <String>] [<CommonParameters>]
3132
```
3233

3334
### PolicyParameterStringParameterSet
3435
```
3536
New-AzureRmPolicyAssignment -Name <String> -Scope <String> [-NotScope <String[]>] [-DisplayName <String>]
3637
[-Description <String>] -PolicyDefinition <PSObject> [-PolicySetDefinition <PSObject>]
37-
-PolicyParameter <String> [-Metadata <String>] [-Sku <Hashtable>] [-ApiVersion <String>] [-Pre]
38-
[-DefaultProfile <IAzureContextContainer>] [-InformationAction <ActionPreference>]
39-
[-InformationVariable <String>] [<CommonParameters>]
38+
-PolicyParameter <String> [-Metadata <String>] [-Sku <Hashtable>] [-AssignIdentity] [-Location <String>]
39+
[-ApiVersion <String>] [-Pre] [-DefaultProfile <IAzureContextContainer>]
40+
[-InformationAction <ActionPreference>] [-InformationVariable <String>] [<CommonParameters>]
4041
```
4142

4243
### PolicySetParameterObjectParameterSet
4344
```
4445
New-AzureRmPolicyAssignment -Name <String> -Scope <String> [-NotScope <String[]>] [-DisplayName <String>]
4546
[-Description <String>] [-PolicyDefinition <PSObject>] -PolicySetDefinition <PSObject>
46-
-PolicyParameterObject <Hashtable> [-Metadata <String>] [-Sku <Hashtable>] [-ApiVersion <String>] [-Pre]
47-
[-DefaultProfile <IAzureContextContainer>] [-InformationAction <ActionPreference>]
48-
[-InformationVariable <String>] [<CommonParameters>]
47+
-PolicyParameterObject <Hashtable> [-Metadata <String>] [-Sku <Hashtable>] [-AssignIdentity]
48+
[-Location <String>] [-ApiVersion <String>] [-Pre] [-DefaultProfile <IAzureContextContainer>]
49+
[-InformationAction <ActionPreference>] [-InformationVariable <String>] [<CommonParameters>]
4950
```
5051

5152
### PolicySetParameterStringParameterSet
5253
```
5354
New-AzureRmPolicyAssignment -Name <String> -Scope <String> [-NotScope <String[]>] [-DisplayName <String>]
5455
[-Description <String>] [-PolicyDefinition <PSObject>] -PolicySetDefinition <PSObject>
55-
-PolicyParameter <String> [-Metadata <String>] [-Sku <Hashtable>] [-ApiVersion <String>] [-Pre]
56-
[-DefaultProfile <IAzureContextContainer>] [-InformationAction <ActionPreference>]
57-
[-InformationVariable <String>] [<CommonParameters>]
56+
-PolicyParameter <String> [-Metadata <String>] [-Sku <Hashtable>] [-AssignIdentity] [-Location <String>]
57+
[-ApiVersion <String>] [-Pre] [-DefaultProfile <IAzureContextContainer>]
58+
[-InformationAction <ActionPreference>] [-InformationVariable <String>] [<CommonParameters>]
5859
```
5960

6061
## DESCRIPTION
@@ -117,6 +118,17 @@ The first command gets a resource group named ResourceGroup11 by using the Get-A
117118
The second command gets the built-in policy definition for allowed locations by using the Get-AzureRmPolicyDefinition cmdlet and stores it in the $Policy variable.
118119
The final command assigns the policy in $Policy at the resource group identified by the **ResourceId** property of $ResourceGroup using the policy parameter file AllowedLocations.json from the local working directory.
119120

121+
### Example 4: Policy assignment with a managed identity
122+
```
123+
PS C:\> $ResourceGroup = Get-AzureRmResourceGroup -Name 'ResourceGroup11'
124+
PS C:\> $Policy = Get-AzureRmPolicyDefinition -Name 'VirtualMachinePolicy'
125+
PS C:\> New-AzureRmPolicyAssignment -Name 'VirtualMachinePolicyAssignment' -PolicyDefinition $Policy -Scope $ResourceGroup.ResourceId -Location 'eastus' -AssignIdentity
126+
```
127+
128+
The first command gets a resource group named ResourceGroup11 by using the Get-AzureRMResourceGroup cmdlet and stores it in the $ResourceGroup variable.
129+
The second command gets the policy definition named VirtualMachinePolicy by using the Get-AzureRmPolicyDefinition cmdlet and stores it in the $Policy variable.
130+
The final command assigns the policy in $Policy to the resource gruop. A managed identity is automatically created and assigned to the policy assignment.
131+
120132
## PARAMETERS
121133

122134
### -ApiVersion
@@ -135,6 +147,21 @@ Accept pipeline input: False
135147
Accept wildcard characters: False
136148
```
137149
150+
### -AssignIdentity
151+
Generate and assign an Azure Active Directory Identity for this policy assignment. The identity will be used when executing deployments for 'deployIfNotExists' policies.
152+
153+
```yaml
154+
Type: System.Management.Automation.SwitchParameter
155+
Parameter Sets: (All)
156+
Aliases:
157+
158+
Required: False
159+
Position: Named
160+
Default value: None
161+
Accept pipeline input: False
162+
Accept wildcard characters: False
163+
```
164+
138165
### -DefaultProfile
139166
The credentials, account, tenant, and subscription used for communication with azure
140167
@@ -217,6 +244,21 @@ Accept pipeline input: False
217244
Accept wildcard characters: False
218245
```
219246
247+
### -Location
248+
The location of the policy assignment. This is only required when the policy assignment has a resource identity.
249+
250+
```yaml
251+
Type: System.String
252+
Parameter Sets: (All)
253+
Aliases:
254+
255+
Required: False
256+
Position: Named
257+
Default value: None
258+
Accept pipeline input: True (ByPropertyName)
259+
Accept wildcard characters: False
260+
```
261+
220262
### -Metadata
221263
The metadata for the new policy assignment. This can either be a path to a file name containing the metadata, or the metadata as a string.
222264

src/ResourceManager/Resources/Commands.Resources/help/New-AzureRmPolicyDefinition.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,43 @@ The **New-AzureRmPolicyDefinition** cmdlet creates a policy definition that incl
4444

4545
### Example 1: Create a policy definition by using a policy file
4646
```
47-
PS C:\> New-AzureRmPolicyDefinition -Name 'VMPolicyDefinition' -Policy C:\VMPolicy.json
47+
{
48+
"if": {
49+
"field": "location",
50+
"notIn": ["eastus", "westus", "centralus"]
51+
},
52+
"then": {
53+
"effect": "audit"
54+
}
55+
}
4856
```
4957

50-
This command creates a policy definition named VMPolicyDefinition that contains the policy rule specified in C:\VMPolicy.json.
58+
```
59+
PS C:\> New-AzureRmPolicyDefinition -Name 'LocationDefinition' -Policy C:\LocationPolicy.json
60+
```
61+
62+
This command creates a policy definition named LocationDefinition that contains the policy rule specified in C:\LocationPolicy.json. Example content for the LocationPolicy.json file is provided above.
63+
64+
### Example 2: Create a parameterized policy definition using inline parameters
65+
```
66+
{
67+
"if": {
68+
"field": "location",
69+
"notIn": "[parameters('listOfAllowedLocations')]"
70+
},
71+
"then": {
72+
"effect": "audit"
73+
}
74+
}
75+
```
76+
77+
```
78+
PS C:\> New-AzureRmPolicyDefinition -Name 'LocationDefinition' -Policy C:\LocationPolicy.json -Parameter '{ "listOfAllowedLocations": { "type": "array" } }'
79+
```
80+
81+
This command creates a policy definition named LocationDefinition that contains the policy rule specified in C:\LocationPolicy.json. The parameter definition for the policy rule is provided inline.
5182

52-
### Example 2: Create a policy definition inline in a management group
83+
### Example 3: Create a policy definition inline in a management group
5384
```
5485
PS C:\> New-AzureRmPolicyDefinition -Name 'VMPolicyDefinition' -ManagementGroupName Dept42 -DisplayName 'Virtual Machine policy definition' -Policy '{"if":{"source":"action","equals":"Microsoft.Compute/virtualMachines/write"},"then":{"effect":"deny"}}'
5586
```

src/ResourceManager/Resources/Commands.Resources/help/New-AzureRmPolicySetDefinition.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,56 @@ The **New-AzureRmPolicySetDefinition** cmdlet creates a policy set definition.
4141
## EXAMPLES
4242

4343
### Example 1: Create a policy set definition by using a policy set file
44+
```
45+
[
46+
{
47+
"policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/2a0e14a6-b0a6-4fab-991a-187a4f81c498",
48+
"parameters": {
49+
"tagName": {
50+
"value": "Business Unit"
51+
},
52+
"tagValue": {
53+
"value": "Finance"
54+
}
55+
}
56+
},
57+
{
58+
"policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/464dbb85-3d5f-4a1d-bb09-95a9b5dd19cf"
59+
}
60+
]
61+
```
62+
4463
```
4564
PS C:\> New-AzureRmPolicySetDefinition -Name 'VMPolicyDefinition' -PolicyDefinition C:\VMPolicySet.json
4665
```
4766

48-
This command creates a policy set definition named VMPolicyDefinition that contains the policy definitions specified in C:\VMPolicy.json.
67+
This command creates a policy set definition named VMPolicyDefinition that contains the policy definitions specified in C:\VMPolicy.json. Example content of the VMPolicy.json is provided above.
68+
69+
### Example 2: Create a parameterized policy set definition
70+
```
71+
[
72+
{
73+
"policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/2a0e14a6-b0a6-4fab-991a-187a4f81c498",
74+
"parameters": {
75+
"tagName": {
76+
"value": "Business Unit"
77+
},
78+
"tagValue": {
79+
"value": "[parameters('buTagValue')]"
80+
}
81+
}
82+
},
83+
{
84+
"policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/464dbb85-3d5f-4a1d-bb09-95a9b5dd19cf"
85+
}
86+
]
87+
```
88+
89+
```
90+
PS C:\> New-AzureRmPolicySetDefinition -Name 'VMPolicyDefinition' -PolicyDefinition C:\VMPolicySet.json -Parameter '{ "buTagValue": { "type": "string" } }'
91+
```
92+
93+
This command creates a parameterized policy set definition named VMPolicyDefinition that contains the policy definitions specified in C:\VMPolicy.json. Example content of the VMPolicy.json is provided above.
4994

5095
## PARAMETERS
5196

src/ResourceManager/Resources/Commands.Resources/help/Set-AzureRmPolicyAssignment.md

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ Modifies a policy assignment.
1616
### NameParameterSet (Default)
1717
```
1818
Set-AzureRmPolicyAssignment -Name <String> -Scope <String> [-NotScope <String[]>] [-DisplayName <String>]
19-
[-Description <String>] [-Metadata <String>] [-Sku <Hashtable>] [-ApiVersion <String>] [-Pre]
20-
[-DefaultProfile <IAzureContextContainer>] [-InformationAction <ActionPreference>]
21-
[-InformationVariable <String>] [<CommonParameters>]
19+
[-Description <String>] [-Metadata <String>] [-Sku <Hashtable>] [-AssignIdentity] [-Location <String>]
20+
[-ApiVersion <String>] [-Pre] [-DefaultProfile <IAzureContextContainer>]
21+
[-InformationAction <ActionPreference>] [-InformationVariable <String>] [<CommonParameters>]
2222
```
2323

2424
### IdParameterSet
2525
```
2626
Set-AzureRmPolicyAssignment [-NotScope <String[]>] -Id <String> [-DisplayName <String>] [-Description <String>]
27-
[-Metadata <String>] [-Sku <Hashtable>] [-ApiVersion <String>] [-Pre]
27+
[-Metadata <String>] [-Sku <Hashtable>] [-AssignIdentity] [-Location <String>] [-ApiVersion <String>] [-Pre]
2828
[-DefaultProfile <IAzureContextContainer>] [-InformationAction <ActionPreference>]
2929
[-InformationVariable <String>] [<CommonParameters>]
3030
```
@@ -48,6 +48,16 @@ The second command gets the policy assignment named PolicyAssignment by using th
4848
The command stores that object in the $PolicyAssignment variable.
4949
The final command updates the display name on the policy assignment on the resource group identified by the **ResourceId** property of $ResourceGroup.
5050

51+
### Example 2: Add a managed identity to the policy assignment
52+
```
53+
PS C:\> $PolicyAssignment = Get-AzureRmPolicyAssignment -Name 'PolicyAssignment'
54+
PS C:\> Set-AzureRmPolicyAssignment -Id $PolicyAssignment.ResourceId -AssignIdentity -Location 'westus'
55+
```
56+
57+
The first command gets the policy assignment named PolicyAssignment from the current subscription by using the Get-AzureRmPolicyAssignment cmdlet.
58+
The command stores that object in the $PolicyAssignment variable.
59+
The final command assigns a managed identity to the policy assignment.
60+
5161
## PARAMETERS
5262

5363
### -ApiVersion
@@ -66,6 +76,21 @@ Accept pipeline input: False
6676
Accept wildcard characters: False
6777
```
6878
79+
### -AssignIdentity
80+
Generate and assign an Azure Active Directory Identity for this policy assignment. The identity will be used when executing deployments for 'deployIfNotExists' policies.
81+
82+
```yaml
83+
Type: System.Management.Automation.SwitchParameter
84+
Parameter Sets: (All)
85+
Aliases:
86+
87+
Required: False
88+
Position: Named
89+
Default value: None
90+
Accept pipeline input: False
91+
Accept wildcard characters: False
92+
```
93+
6994
### -DefaultProfile
7095
The credentials, account, tenant, and subscription used for communication with azure
7196
@@ -163,6 +188,21 @@ Accept pipeline input: False
163188
Accept wildcard characters: False
164189
```
165190
191+
### -Location
192+
The location of the policy assignment. This is only required when the policy assignment has a resource identity.
193+
194+
```yaml
195+
Type: System.String
196+
Parameter Sets: (All)
197+
Aliases:
198+
199+
Required: False
200+
Position: Named
201+
Default value: None
202+
Accept pipeline input: True (ByPropertyName)
203+
Accept wildcard characters: False
204+
```
205+
166206
### -Metadata
167207
The updated metadata for the policy assignment. This can either be a path to a file name containing the metadata, or the metadata as a string.
168208

0 commit comments

Comments
 (0)