Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Resources from generation to main #26129

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion src/Resources/Authorization.Autorest/Az.Authorization.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
GUID = '75928d90-d5c7-49aa-b368-3856a02003be'
GUID = '87ef2602-2a5d-4f33-8ec1-e58f24d6d474'
RootModule = './Az.Authorization.psm1'
ModuleVersion = '0.1.0'
CompatiblePSEditions = 'Core', 'Desktop'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
Module Name: Az.Authorization
Module Guid: 75928d90-d5c7-49aa-b368-3856a02003be
Module Guid: 87ef2602-2a5d-4f33-8ec1-e58f24d6d474
Download Help Link: https://learn.microsoft.com/powershell/module/az.authorization
Help Version: 1.0.0.0
Locale: en-US
Expand Down
4 changes: 1 addition & 3 deletions src/Resources/Policy.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,10 @@ directive:
- DisplayName

# Hide parameters that aren't supported.
# For some reason these can't be hidden by hiding them in
# the custom folder so we have to do it here.
- where:
verb: New|Update
subject: PolicyAssignment|PolicyExemption
parameter-name: PolicyDefinitionId|ResourceSelector|Override
parameter-name: PolicyDefinitionId
hide: true
- where:
verb: New
Expand Down
14 changes: 14 additions & 0 deletions src/Resources/Policy.Autorest/custom/New-AzPolicyAssignment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ param(
# To construct, see NOTES section for NONCOMPLIANCEMESSAGE properties and create a hash table.
${NonComplianceMessage},

[Parameter()]
[AllowEmptyCollection()]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Body')]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Models.IOverride[]]
# The policy property value override.
${Override},

[Parameter()]
[AllowEmptyCollection()]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Body')]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Models.IResourceSelector[]]
# The resource selector list to filter policies by resource properties.
${ResourceSelector},

[Parameter()]
[Obsolete('This parameter is a temporary bridge to new types and formats and will be removed in a future release.')]
[System.Management.Automation.SwitchParameter]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ param(
# Metadata is an open ended object and is typically a collection of key value pairs.
${Metadata},

[Parameter()]
[AllowEmptyCollection()]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Body')]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Models.IResourceSelector[]]
# The resource selector list to filter policies by resource properties.
${ResourceSelector},

[Parameter()]
[Obsolete('This parameter is a temporary bridge to new types and formats and will be removed in a future release.')]
[System.Management.Automation.SwitchParameter]
Expand Down
18 changes: 16 additions & 2 deletions src/Resources/Policy.Autorest/custom/Update-AzPolicyAssignment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ param(
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Models.IPolicyAssignment]
${InputObject},

[Parameter()]
[AllowEmptyCollection()]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Body')]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Models.IOverride[]]
# The policy property value override.
${Override},

[Parameter()]
[AllowEmptyCollection()]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Body')]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Models.IResourceSelector[]]
# The resource selector list to filter policies by resource properties.
${ResourceSelector},

[Parameter()]
[Obsolete('This parameter is a temporary bridge to new types and formats and will be removed in a future release.')]
[System.Management.Automation.SwitchParameter]
Expand Down Expand Up @@ -279,7 +293,7 @@ process {
if ($InputObject) {
foreach ($parameterName in $InputObject.Keys) {
$value = $InputObject.($parameterName)
if ($value -or ($value -is [array])) {
if ($value -or ($value -is [array]) -or ($value -is [switch])) {
$calledParameters.($parameterName) = $value
}
}
Expand All @@ -288,7 +302,7 @@ process {
# skip $null and empty values to avoid validation failures on pipeline input
foreach ($parameterName in $PSBoundParameters.Keys) {
$value = $PSBoundParameters.($parameterName)
if ($value -or ($value -is [array])) {
if ($value -or ($value -is [array]) -or ($value -is [switch])) {
$calledParameters.($parameterName) = $value
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ process {
if ($InputObject) {
foreach ($parameterName in $InputObject.Keys) {
$value = $InputObject.($parameterName)
if ($value -or ($value -is [array])) {
if ($value -or ($value -is [array]) -or ($value -is [switch])) {
$calledParameters.($parameterName) = $value
}
}
Expand All @@ -229,7 +229,7 @@ process {
# skip $null and empty values to avoid validation failures on pipeline input
foreach ($parameterName in $PSBoundParameters.Keys) {
$value = $PSBoundParameters.($parameterName)
if ($value -or ($value -is [array])) {
if ($value -or ($value -is [array]) -or ($value -is [switch])) {
$calledParameters.($parameterName) = $value
}
}
Expand Down
19 changes: 13 additions & 6 deletions src/Resources/Policy.Autorest/custom/Update-AzPolicyExemption.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ param(
${InputObject},

[Parameter()]
[Obsolete('This parameter is a temporary bridge to new types and formats and will be removed in a future release.')]
[System.Management.Automation.SwitchParameter]
# Causes cmdlet to return artifacts using legacy format placing policy-specific properties in a property bag object.
${BackwardCompatible} = $false,
[AllowEmptyCollection()]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Body')]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Models.IResourceSelector[]]
# The resource selector list to filter policies by resource properties.
${ResourceSelector},

[Parameter()]
[ValidateSet('Default', 'DoNotValidate')]
Expand All @@ -122,6 +123,12 @@ param(
# The option whether validate the exemption is at or under the assignment scope.
${AssignmentScopeValidation},

[Parameter()]
[Obsolete('This parameter is a temporary bridge to new types and formats and will be removed in a future release.')]
[System.Management.Automation.SwitchParameter]
# Causes cmdlet to return artifacts using legacy format placing policy-specific properties in a property bag object.
${BackwardCompatible} = $false,

[Parameter()]
[Alias('AzureRMContext', 'AzureCredential')]
[ValidateNotNull()]
Expand Down Expand Up @@ -221,7 +228,7 @@ process {
if ($InputObject) {
foreach ($parameterName in $InputObject.Keys) {
$value = $InputObject.($parameterName)
if ($value -or ($value -is [array])) {
if ($value -or ($value -is [array]) -or ($value -is [switch])) {
$calledParameters.($parameterName) = $value
}
}
Expand All @@ -230,7 +237,7 @@ process {
# skip $null and empty values to avoid validation failures on pipeline input
foreach ($parameterName in $PSBoundParameters.Keys) {
$value = $PSBoundParameters.($parameterName)
if ($value -or ($value -is [array])) {
if ($value -or ($value -is [array]) -or ($value -is [switch])) {
$calledParameters.($parameterName) = $value
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ process {
if ($InputObject) {
foreach ($parameterName in $InputObject.Keys) {
$value = $InputObject.($parameterName)
if ($value -or ($value -is [array])) {
if ($value -or ($value -is [array]) -or ($value -is [switch])) {
$calledParameters.($parameterName) = $value
}
}
Expand All @@ -230,7 +230,7 @@ process {
# skip $null and empty values to avoid validation failures on pipeline input
foreach ($parameterName in $PSBoundParameters.Keys) {
$value = $PSBoundParameters.($parameterName)
if ($value -or ($value -is [array])) {
if ($value -or ($value -is [array]) -or ($value -is [switch])) {
$calledParameters.($parameterName) = $value
}
}
Expand Down
50 changes: 36 additions & 14 deletions src/Resources/Policy.Autorest/examples/New-AzPolicyAssignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,25 @@ The final command assigns the policy in $Policy at the level of a resource group
The **ResourceId** property of $ResourceGroup identifies the resource group.

### Example 4: Policy assignment at resource group level with policy parameter file
Create a file called _AllowedLocations.json_ in the local working directory with the following content.

```powershell
{
'{
"listOfAllowedLocations": {
"value": [
"westus",
"westeurope",
"japanwest"
]
}
}
}' > .\AllowedLocations.json

$ResourceGroup = Get-AzResourceGroup -Name 'ResourceGroup11'
$Policy = Get-AzPolicyDefinition -BuiltIn | Where-Object {$_.DisplayName -eq 'Allowed locations'}
New-AzPolicyAssignment -Name 'RestrictLocationPolicyAssignment' -PolicyDefinition $Policy -Scope $ResourceGroup.ResourceId -PolicyParameter .\AllowedLocations.json
```

The first command gets a resource group named ResourceGroup11 by using the Get-AzResourceGroup cmdlet and stores it in the $ResourceGroup variable.
The second command gets the built-in policy definition for allowed locations by using the Get-AzPolicyDefinition cmdlet and stores it in the $Policy variable.
The first command creates a parameter file called _AllowedLocations.json_ in the local working directory.
The second command gets a resource group named ResourceGroup11 by using the Get-AzResourceGroup cmdlet and stores it in the $ResourceGroup variable.
The third command gets the built-in policy definition for allowed locations by using the Get-AzPolicyDefinition cmdlet and stores it in the $Policy variable.
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.

### Example 5: Policy assignment with a system assigned managed identity
Expand Down Expand Up @@ -108,7 +107,31 @@ The first command gets the policy set definition named VirtualMachinePolicySet b
The second command creates an array of non-compliance messages. One general purpose message for the entire assignment and one message specific to a SKU restriction policy within the assigned policy set definition.
The final command assigns the policy set definition in $PolicySet to the subscription with two non-compliance messages that will be shown if a resource is denied by policy.

### Example 9: [Backcompat] Policy assignment at resource group level with policy parameter object
### Example 9: Policy assignment with resource selector
```powershell
$Policy = Get-AzPolicyDefinition -Name 'VirtualMachinePolicy'
$ResourceSelector = @{Name = "MyLocationSelector"; Selector = @(@{Kind = "resourceLocation"; In = @("eastus", "eastus2")})}
New-AzPolicyAssignment -Name 'VirtualMachinePolicyAssignment' -PolicyDefinition $Policy -ResourceSelector $ResourceSelector
```

The first command gets the policy definition named VirtualMachinePolicy by using the Get-AzPolicyDefinition cmdlet and stores it in the $Policy variable.
The second command creates a resource selector object that will be used to specify the assignment should only apply to resources located in East US or East US 2 and stores it in the $ResourceSelector variable.
The final command assigns the policy definition in $Policy to the subscription with the resource selector specified by $ResourceSelector.

### Example 10: Policy assignment with override
```powershell
$Policy = Get-AzPolicyDefinition -Name 'VirtualMachinePolicy'
$Selector = @{Kind = "resourceLocation"; In = @("eastus", "eastus2")}
$Override = @(@{Kind = "policyEffect"; Value = 'Disabled'; Selector = @($Selector)})
New-AzPolicyAssignment -Name 'VirtualMachinePolicyAssignment' -PolicyDefinition $Policy -Override $Override
```

The first command gets the policy definition named VirtualMachinePolicy by using the Get-AzPolicyDefinition cmdlet and stores it in the $Policy variable.
The second command creates a location selector specifying East US or East US 2 locations and stores it in the $Selector variable.
The third command creates an override object that will be used to specify that the assigned definition should have a Disabled effect in the locations identified by the $Selector object and stores it in the $Override variable.
The final command assigns the policy definition in $Policy to the subscription with the override specified by $Override.

### Example 11: [Backcompat] Policy assignment at resource group level with policy parameter object
```powershell
$ResourceGroup = Get-AzResourceGroup -Name 'ResourceGroup11'
$Policy = Get-AzPolicyDefinition -BuiltIn | Where-Object {$_.Properties.DisplayName -eq 'Allowed locations'}
Expand All @@ -126,25 +149,24 @@ The commands store that object in the $AllowedLocations variable.
The final command assigns the policy in $Policy at the level of a resource group using the policy parameter object in $AllowedLocations.
The **ResourceId** property of $ResourceGroup identifies the resource group.

### Example 10: [Backcompat] Policy assignment at resource group level with policy parameter file
Create a file called _AllowedLocations.json_ in the local working directory with the following content.

### Example 12: [Backcompat] Policy assignment at resource group level with policy parameter file
```powershell
{
'{
"listOfAllowedLocations": {
"value": [
"westus",
"westeurope",
"japanwest"
]
}
}
}' > .\AllowedLocations.json

$ResourceGroup = Get-AzResourceGroup -Name 'ResourceGroup11'
$Policy = Get-AzPolicyDefinition -BuiltIn | Where-Object {$_.Properties.DisplayName -eq 'Allowed locations'}
New-AzPolicyAssignment -Name 'RestrictLocationPolicyAssignment' -PolicyDefinition $Policy -Scope $ResourceGroup.ResourceId -PolicyParameter .\AllowedLocations.json
```

The first command gets a resource group named ResourceGroup11 by using the Get-AzResourceGroup cmdlet and stores it in the $ResourceGroup variable.
The second command gets the built-in policy definition for allowed locations by using the Get-AzPolicyDefinition cmdlet and stores it in the $Policy variable.
The first command creates a parameter file called _AllowedLocations.json_ in the local working directory.
The second command gets a resource group named ResourceGroup11 by using the Get-AzResourceGroup cmdlet and stores it in the $ResourceGroup variable.
The third command gets the built-in policy definition for allowed locations by using the Get-AzPolicyDefinition cmdlet and stores it in the $Policy variable.
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.
12 changes: 12 additions & 0 deletions src/Resources/Policy.Autorest/examples/New-AzPolicyExemption.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,15 @@ New-AzPolicyExemption -Name 'VirtualMachinePolicyAssignment' -PolicyAssignment $
The first command gets a VM named SpecialVM by using the Get-AzVM cmdlet and stores it in the $VM variable.
The second command gets the policy assignment named VirtualMachinePolicyAssignment by using the Get-AzPolicyAssignment cmdlet and stores it in the $Assignment variable.
The final command exempts the resource identified by the **Id** property of $VM from the policy assignment in $Assignment.

### Example 5: Policy exemption with resource selector
```powershell
$Assignment = Get-AzPolicyAssignment -Name 'VirtualMachineAssignment'
$ResourceSelector = @{Name = "MyLocationSelector"; Selector = @(@{Kind = "resourceLocation"; In = @("eastus", "eastus2")})}
New-AzPolicyExemption -Name 'VirtualMachinePolicyExemption' -PolicyAssignment $Assignment -ResourceSelector $ResourceSelector
```

The first command gets the policy assignment named VirtualMachineAssignment by using the Get-AzPolicyAssignment cmdlet and stores it in the $Assignment variable.
The second command creates a resource selector object that will be used to specify the exemption should only apply to resources located in East US or East US 2 and stores it in the $ResourceSelector variable.
The final command creates a policy exemption for the assignment $Assignment with the resource selector specified by $ResourceSelector.

Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,27 @@ Update-AzPolicyAssignment -Id $PolicyAssignment.ResourceId -NonComplianceMessage
The first command gets the policy assignment named VirtualMachinePolicy by using the Get-AzPolicyAssignment cmdlet and stores it in the $PolicyAssignment variable.
The final command updates the non-compliance messages on the policy assignment with a new message that will be displayed if a resource is denied by the policy.

### Example 8: [Backcompat] Update an enforcementMode
### Example 8: Update resource selector
```powershell
$ResourceSelector = @{Name = "MyLocationSelector"; Selector = @(@{Kind = "resourceLocation"; NotIn = @("eastus", "eastus2")})}
Update-AzPolicyAssignment -Name 'VirtualMachinePolicyAssignment' -ResourceSelector $ResourceSelector
```

The first command creates a resource selector object that will be used to specify the assignment should only apply to resources not located in East US or East US 2 and stores it in the $ResourceSelector variable.
The final command updates the policy assignment named VirtualMachinePolicyAssignment with the resource selector specified by $ResourceSelector.

### Example 9: Update override
```powershell
$Selector = @{Kind = "resourceLocation"; NotIn = @("eastus", "eastus2")}
$Override = @(@{Kind = "policyEffect"; Value = 'Disabled'; Selector = @($Selector)})
Update-AzPolicyAssignment -Name 'VirtualMachinePolicyAssignment' -Override $Override
```

The first command creates a location selector specifying locations other than East US or East US 2 and stores in in the $Selector variable.
The second command creates an override object that will be used to specify that the assigned definition should have a Disabled effect in the locations identified by $Selector.
The final command updates the policy assignment named VirtualMachinePolicyAssignment with the override specified by $Override.

### Example 10: [Backcompat] Update an enforcementMode
```powershell
$ResourceGroup = Get-AzResourceGroup -Name 'ResourceGroup11'
$PolicyAssignment = Get-AzPolicyAssignment -Name 'PolicyAssignment' -Scope $ResourceGroup.ResourceId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,16 @@ The second command gets the policy exemption named PolicyExemption07 by using th
The command stores that object in the $PolicyExemption variable.
The final command updates the expiration date time for the policy exemption on the default subscription.

### Example 5: [Backcompat] Clear the expiration date time
### Example 5: Update resource selector
```powershell
$ResourceSelector = @{Name = "MyLocationSelector"; Selector = @(@{Kind = "resourceLocation"; NotIn = @("eastus", "eastus2")})}
Update-AzPolicyExemption -Name 'VirtualMachineExemption' -ResourceSelector $ResourceSelector
```

The first command creates a resource selector object that will be used to specify the exemption should only apply to resources in locations other than East US or East US 2 and stores it in the $ResourceSelector variable.
The final command updates the policy exemption named VirtualMachineExemption with the resource selector specified by $ResourceSelector.

### Example 6: [Backcompat] Clear the expiration date time
```powershell
$PolicyExemption = Get-AzPolicyExemption -Name 'PolicyExemption07'
Set-AzPolicyExemption -Id $PolicyExemption.ResourceId -ClearExpiration
Expand Down
Loading