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

Retiring legacy setting Core.AllInOneTemplate #517

Merged
merged 2 commits into from
Jan 3, 2022
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions docs/wiki/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@ The following configuration values can be modified within the `settings.json` fi

| Id | Name | Description |
|----|--------------------------------------|--------------------------------------------------------------|
| 01 | AllInOneTemplate | |
| 02 | AutoGeneratedTemplateFolderPath | Generate sub folder for composite resources (/.Az) |
| 03 | AutoInitialize | |
| 04 | DefaultDeploymentRegion | Set the default region to be used for deployments |
| 05 | EnrollmentAccountPrincipalName | Default enrollment account for Subscription creation |
| 06 | ExcludedSubOffer | Exclude speicific Subscription offer types from creation |
| 07 | ExcludedSubState | Exclude specific Subscription states from creation |
| 08 | ExportRawTemplate | |
| 10 | IgnoreContextCheck | Skip Azure PowerShell context validation |
| 11 | InvalidateCache | |
| 14 | OfferType | Default offer type for Subscriptions creation |
| 15 | PartialMgDiscoveryRoot | Generate folder hierachy for specific Management Groups |
| 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 | 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 | |
| 25 | WhatifExcludedChangeTypes | Exclude specific change types from WhatIf operations |
| 01 | AutoGeneratedTemplateFolderPath | Generate sub folder for composite resources (/.Az) |
| 02 | AutoInitialize | |
| 03 | DefaultDeploymentRegion | Set the default region to be used for deployments |
| 04 | EnrollmentAccountPrincipalName | Default enrollment account for Subscription creation |
| 05 | ExcludedSubOffer | Exclude speicific Subscription offer types from creation |
| 06 | ExcludedSubState | Exclude specific Subscription states from creation |
| 07 | ExportRawTemplate | |
| 08 | IgnoreContextCheck | Skip Azure PowerShell context validation |
| 09 | InvalidateCache | |
| 10 | OfferType | Default offer type for Subscriptions creation |
| 11 | PartialMgDiscoveryRoot | Generate folder hierachy for specific Management Groups |
| 12 | SkipPolicy | Generate template files for Policy types |
| 13 | SkipResource | Generate template files for Resources within Resource Groups |
| 14 | SkipResourceGroup | Generate folder hierachy for all Resource Groups |
| 15 | 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)|
| 16 | SkipRole | Generate template files for Role types |
| 17 | State | Default top level folder name within the repository |
| 18 | SubscriptionsToIncludeResourceGroups | Generate folder hierachy for specific Resource Groups |
| 19 | TemplateParameterFileSuffix | Default template file suffix |
| 20 | ThrottleLimit | |
| 21 | WhatifExcludedChangeTypes | Exclude specific change types from WhatIf operations |
2 changes: 1 addition & 1 deletion src/internal/classes/AzOpsScope.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
{ $_.resources -and
$_.resources[0].type -eq 'Microsoft.Resources/resourceGroups' } {
Write-PSFMessage -Level Verbose -String 'AzOpsScope.InitializeMemberVariablesFromFile.resourceGroups' -StringValues ($_.resources[0].name) -FunctionName InitializeMemberVariablesFromFile -ModuleName AzOps

if ($(Get-PSFConfigValue -FullName 'AzOps.Core.AutoGeneratedTemplateFolderPath') -match $Path.Directory.Name) {
$currentScope = New-AzOpsScope -Path ($Path.Directory.Parent)
}
Expand Down
3 changes: 1 addition & 2 deletions src/internal/configurations/Core.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Set-PSFConfig -Module AzOps -Name Core.AllInOneTemplate -Value $false -Initialize -Validation bool -Description '-'
Set-PSFConfig -Module AzOps -Name Core.AutoGeneratedTemplateFolderPath -Value "." -Initialize -Validation string -Description 'Auto-Genereated Template Folder Path i.e. ./Az'
Set-PSFConfig -Module AzOps -Name Core.AutoGeneratedTemplateFolderPath -Value "." -Initialize -Validation string -Description 'Auto-Generated Template Folder Path i.e. ./Az'
Set-PSFConfig -Module AzOps -Name Core.AutoInitialize -Value $false -Initialize -Validation bool -Description '-'
Set-PSFConfig -Module AzOps -Name Core.DefaultDeploymentRegion -Value northeurope -Initialize -Validation string -Description 'Default deployment region for state deployments (ARM region, not region where a resource is deployed)'
Set-PSFConfig -Module AzOps -Name Core.EnrollmentAccountPrincipalName -Value '' -Initialize -Validation stringorempty -Description '-'
Expand Down
36 changes: 1 addition & 35 deletions src/internal/functions/Get-AzOpsResourceDefinition.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -414,37 +414,27 @@
return
}

$serializedPolicyDefinitionsInAzure = @()
$serializedPolicySetDefinitionsInAzure = @()
$serializedPolicyAssignmentsInAzure = @()
$serializedRoleDefinitionsInAzure = @()
$serializedRoleAssignmentInAzure = @()

#region Process Policies
if (-not $SkipPolicy) {
# Process policy definitions
Write-PSFMessage -Level Verbose -String 'Get-AzOpsResourceDefinition.Processing.Detail' -StringValues 'Policy Definitions', $scopeObject.Scope
$policyDefinitions = Get-AzOpsPolicyDefinition -ScopeObject $scopeObject
$policyDefinitions | ConvertTo-AzOpsState -ExportRawTemplate:$ExportRawTemplate -StatePath $StatePath
$serializedPolicyDefinitionsInAzure = $policyDefinitions | ConvertTo-AzOpsState -ExportRawTemplate -StatePath $StatePath -ReturnObject

# Process policyset definitions (initiatives))
Write-PSFMessage -Level Verbose -String 'Get-AzOpsResourceDefinition.Processing.Detail' -StringValues 'PolicySet Definitions', $scopeObject.Scope
$policySetDefinitions = Get-AzOpsPolicySetDefinition -ScopeObject $scopeObject
$policySetDefinitions | ConvertTo-AzOpsState -ExportRawTemplate:$ExportRawTemplate -StatePath $StatePath
$serializedPolicySetDefinitionsInAzure = $policySetDefinitions | ConvertTo-AzOpsState -ExportRawTemplate -StatePath $StatePath -ReturnObject

# Process policy assignments
Write-PSFMessage -Level Verbose -String 'Get-AzOpsResourceDefinition.Processing.Detail' -StringValues 'Policy Assignments', $scopeObject.Scope
$policyAssignments = Get-AzOpsPolicyAssignment -ScopeObject $scopeObject
$policyAssignments | ConvertTo-AzOpsState -ExportRawTemplate:$ExportRawTemplate -StatePath $StatePath
$serializedPolicyAssignmentsInAzure = $policyAssignments | ConvertTo-AzOpsState -ExportRawTemplate -StatePath $StatePath -ReturnObject

# Process policy exemptions
Write-PSFMessage -Level Verbose -String 'Get-AzOpsResourceDefinition.Processing.Detail' -StringValues 'Policy Exemptions', $scopeObject.Scope
$policyExemptions = Get-AzOpsPolicyExemption -ScopeObject $scopeObject
$policyExemptions | ConvertTo-AzOpsState -ExportRawTemplate:$ExportRawTemplate -StatePath $StatePath
$serializedpolicyExemptionsInAzure = $policyExemptions | ConvertTo-AzOpsState -ExportRawTemplate -StatePath $StatePath -ReturnObject
}
#endregion Process Policies

Expand All @@ -454,42 +444,18 @@
Write-PSFMessage -Level Verbose -String 'Get-AzOpsResourceDefinition.Processing.Detail' -StringValues 'Role Definitions', $scopeObject.Scope
$roleDefinitions = Get-AzOpsRoleDefinition -ScopeObject $scopeObject
$roleDefinitions | ConvertTo-AzOpsState -ExportRawTemplate:$ExportRawTemplate -StatePath $StatePath
$serializedRoleDefinitionsInAzure = $roleDefinitions | ConvertTo-AzOpsState -ExportRawTemplate -StatePath $StatePath -ReturnObject

# Process role assignments
Write-PSFMessage -Level Verbose -String 'Get-AzOpsResourceDefinition.Processing.Detail' -StringValues 'Role Assignments', $scopeObject.Scope
$roleAssignments = Get-AzOpsRoleAssignment -ScopeObject $scopeObject
$roleAssignments | ConvertTo-AzOpsState -ExportRawTemplate:$ExportRawTemplate -StatePath $StatePath
$serializedRoleAssignmentInAzure = $roleAssignments | ConvertTo-AzOpsState -ExportRawTemplate -StatePath $StatePath -ReturnObject
}
#endregion Process Roles

if ($scopeObject.Type -notin 'subscriptions', 'managementGroups') {
Write-PSFMessage -Level Verbose -String 'Get-AzOpsResourceDefinition.Finished' -StringValues $scopeObject.Scope
return
}

if (Get-PSFConfigValue -FullName 'AzOps.Core.AllInOneTemplate') {
#region Add accumulated policy and role data
# Get statefile from scope
$parametersJson = Get-Content -Path $scopeObject.StatePath | ConvertFrom-Json -Depth 100
# Create property bag and add resources at scope
$propertyBag = [ordered]@{
'policyDefinitions' = @($serializedPolicyDefinitionsInAzure)
'policySetDefinitions' = @($serializedPolicySetDefinitionsInAzure)
'policyAssignments' = @($serializedPolicyAssignmentsInAzure)
'policyExemptions' = @($serializedpolicyExemptionsInAzure)
'roleDefinitions' = @($serializedRoleDefinitionsInAzure)
'roleAssignments' = @($serializedRoleAssignmentInAzure)
}
# Add property bag to parameters json
$parametersJson.parameters.input.value | Add-Member -Name 'properties' -MemberType NoteProperty -Value $propertyBag -force
# Export state file with properties at scope
ConvertTo-AzOpsState -Resource $parametersJson -ExportPath $scopeObject.StatePath -ExportRawTemplate -StatePath $StatePath
#endregion Add accumulated policy and role data
}

Write-PSFMessage -Level Verbose -String 'Get-AzOpsResourceDefinition.Finished' -StringValues $scopeObject.Scope
}

}
}