diff --git a/docs/wiki/Settings.md b/docs/wiki/Settings.md index 7dc79b54..6f5700e6 100644 --- a/docs/wiki/Settings.md +++ b/docs/wiki/Settings.md @@ -17,8 +17,9 @@ The following configuration values can be modified within the `settings.json` fi | 16 | SkipPolicy | Generate template files for Policy types | | 17 | SkipResource | Generate template files for Resources within Resource Groups | | 18 | SkipResourceGroup | Generate folder hierachy for all Resource Groups | -| 19 | SkipRole | Generate template files for Role types | -| 20 | State | Default top level folder name within the repository | -| 21 | SubscriptionsToIncludeResourceGroups | Generate folder hierachy for specific Resource Groups | +| 19 | SkipResourceType | Skip specific [Resource Types](https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/resource-providers-and-types) (only targets Resource Group scoped resources)| +| 20 | SkipRole | Generate template files for Role types | +| 21 | State | Default top level folder name within the repository | +| 22 | SubscriptionsToIncludeResourceGroups | Generate folder hierachy for specific Resource Groups | | 23 | TemplateParameterFileSuffix | Default template file suffix | | 24 | ThrottleLimit | | diff --git a/src/internal/configurations/Core.ps1 b/src/internal/configurations/Core.ps1 index 83cbe6af..e53cf5a2 100644 --- a/src/internal/configurations/Core.ps1 +++ b/src/internal/configurations/Core.ps1 @@ -15,6 +15,7 @@ Set-PSFConfig -Module AzOps -Name Core.PartialMgDiscoveryRoot -Value @() -Initia Set-PSFConfig -Module AzOps -Name Core.SkipPolicy -Value $false -Initialize -Validation bool -Description '-' Set-PSFConfig -Module AzOps -Name Core.SkipResource -Value $true -Initialize -Validation bool -Description 'Global flag to indicate whether resource should be discovered or not. Requires SkipResourceGroup to be false.' Set-PSFConfig -Module AzOps -Name Core.SkipResourceGroup -Value $false -Initialize -Validation bool -Description 'Global flag to indicate whether resource group should be discovered or not' +Set-PSFConfig -Module AzOps -Name Core.SkipResourceType -Value @('Microsoft.VSOnline/plans','Microsoft.PowerPlatform/accounts','Microsoft.PowerPlatform/enterprisePolicies') -Initialize -Validation stringarray -Description 'Global flag to skip discovery of specific Resource types.' Set-PSFConfig -Module AzOps -Name Core.SkipRole -Value $false -Initialize -Validation bool -Description '-' Set-PSFConfig -Module AzOps -Name Core.State -Value (Join-Path $pwd -ChildPath "root") -Initialize -Validation string -Description 'Folder to store AzOpsState artefact' Set-PSFConfig -Module AzOps -Name Core.SubscriptionsToIncludeResourceGroups -Value @('*') -Initialize -Validation stringarray -Description 'Requires SkipResourceGroup to be false. Subscription ID or Display Name that matches the filter. Powershell filter that matches with like operator is supported.' diff --git a/src/internal/functions/Get-AzOpsResourceDefinition.ps1 b/src/internal/functions/Get-AzOpsResourceDefinition.ps1 index a4b74a5d..8050dc28 100644 --- a/src/internal/functions/Get-AzOpsResourceDefinition.ps1 +++ b/src/internal/functions/Get-AzOpsResourceDefinition.ps1 @@ -15,6 +15,8 @@ Skip discovery of resource groups. .PARAMETER SkipResource Skip discovery of resources inside resource groups. + .PARAMETER SkipResourceType + Skip discovery of specific resource types. .PARAMETER ExportRawTemplate Export generic templates without embedding them in the parameter block. .PARAMETER StatePath @@ -54,6 +56,9 @@ [switch] $SkipResource = (Get-PSFConfigValue -FullName 'AzOps.Core.SkipResource'), + [string[]] + $SkipResourceType = (Get-PSFConfigValue -FullName 'AzOps.Core.SkipResourceType'), + [switch] $ExportRawTemplate = (Get-PSFConfigValue -FullName 'AzOps.Core.ExportRawTemplate'), @@ -105,6 +110,9 @@ [switch] $SkipResource, + [string[]] + $SkipResourceType, + [string] $StatePath, @@ -145,7 +153,7 @@ ODataQuery = $OdataFilter ExpandProperties = $true } - Get-AzResource @paramGetAzResource | ForEach-Object { + Get-AzResource @paramGetAzResource | Where-Object {$_.Type -notin $SkipResourceType} | ForEach-Object { New-AzOpsScope -Scope $_.ResourceId } | ConvertFrom-TypeResource -StatePath $StatePath -ExportRawTemplate:$ExportRawTemplate } @@ -172,6 +180,9 @@ [switch] $SkipResource, + [string[]] + $SkipResourceType, + [string] $ODataFilter ) begin { @@ -220,6 +231,7 @@ ScopeObject = $ScopeObject ODataFilter = $ODataFilter SkipResource = $SkipResource + SkipResourceType = $SkipResourceType MaxRetryCount = $maxRetryCount BackoffMultiplier = $backoffMultiplier ExportRawTemplate = $ExportRawTemplate @@ -284,7 +296,7 @@ } # Loop through resources and convert them to AzOpsState - foreach ($resource in $resources) { + foreach ($resource in ($resources | Where-Object {$_.Type -notin $runspaceData.SkipResourceType})) { # Convert resources to AzOpsState Write-PSFMessage @msgCommon -String 'Get-AzOpsResourceDefinition.SubScription.Processing.Resource' -StringValues $resource.Name, $resourceGroup.ResourceGroupName -Target $resource & $azOps { ConvertTo-AzOpsState -Resource $resource -ExportRawTemplate:$runspaceData.ExportRawTemplate -StatePath $runspaceData.Statepath } @@ -392,8 +404,8 @@ switch ($scopeObject.Type) { resource { ConvertFrom-TypeResource -ScopeObject $scopeObject -StatePath $StatePath -ExportRawTemplate:$ExportRawTemplate } - resourcegroups { ConvertFrom-TypeResourceGroup -ScopeObject $scopeObject -StatePath $StatePath -ExportRawTemplate:$ExportRawTemplate -Context $context -SkipResource:$SkipResource -OdataFilter $odataFilter } - subscriptions { ConvertFrom-TypeSubscription -ScopeObject $scopeObject -StatePath $StatePath -ExportRawTemplate:$ExportRawTemplate -Context $context -SkipResourceGroup:$SkipResourceGroup -SkipResource:$SkipResource -ODataFilter $odataFilter } + resourcegroups { ConvertFrom-TypeResourceGroup -ScopeObject $scopeObject -StatePath $StatePath -ExportRawTemplate:$ExportRawTemplate -Context $context -SkipResource:$SkipResource -SkipResourceType:$SkipResourceType -OdataFilter $odataFilter } + subscriptions { ConvertFrom-TypeSubscription -ScopeObject $scopeObject -StatePath $StatePath -ExportRawTemplate:$ExportRawTemplate -Context $context -SkipResourceGroup:$SkipResourceGroup -SkipResource:$SkipResource -SkipResourceType:$SkipResourceType -ODataFilter $odataFilter } managementGroups { ConvertFrom-TypeManagementGroup -ScopeObject $scopeObject -StatePath $StatePath -ExportRawTemplate:$ExportRawTemplate -SkipPolicy:$SkipPolicy -SkipRole:$SkipRole -SkipResourceGroup:$SkipResourceGroup -SkipResource:$SkipResource } }