diff --git a/.azuredevops/pipelineTemplates/module.jobs.deploy.yml b/.azuredevops/pipelineTemplates/module.jobs.deploy.yml index 76cf45a495..df626e90fc 100644 --- a/.azuredevops/pipelineTemplates/module.jobs.deploy.yml +++ b/.azuredevops/pipelineTemplates/module.jobs.deploy.yml @@ -291,10 +291,10 @@ jobs: if (-not [String]::IsNullOrEmpty('$(deploymentName)')) { $functionInput = @{ - deploymentName = '$(deploymentName)' - templateFilePath = $templateFilePath - resourceGroupName = '${{ parameters.resourceGroupName }}' - verbose = $true + DeploymentName = '$(deploymentName)' + TemplateFilePath = $templateFilePath + ResourceGroupName = '${{ parameters.resourceGroupName }}' + Verbose = $true } Write-Verbose 'Invoke task with' -Verbose diff --git a/.github/actions/templates/validateModuleDeployment/action.yml b/.github/actions/templates/validateModuleDeployment/action.yml index 60bfbf9f52..6711eb84c8 100644 --- a/.github/actions/templates/validateModuleDeployment/action.yml +++ b/.github/actions/templates/validateModuleDeployment/action.yml @@ -150,10 +150,10 @@ runs: if (-not [String]::IsNullOrEmpty('${{ steps.deploy_step.outputs.deploymentName }}')) { $functionInput = @{ - deploymentName = '${{ steps.deploy_step.outputs.deploymentName }}' - templateFilePath = Join-Path $env:GITHUB_WORKSPACE '${{ inputs.templateFilePath }}' - resourceGroupName = '${{ inputs.resourceGroupName }}' - verbose = $true + DeploymentName = '${{ steps.deploy_step.outputs.deploymentName }}' + TemplateFilePath = Join-Path $env:GITHUB_WORKSPACE '${{ inputs.templateFilePath }}' + ResourceGroupName = '${{ inputs.resourceGroupName }}' + Verbose = $true } Write-Verbose 'Invoke task with' -Verbose diff --git a/.github/workflows/ms.insights.diagnosticsettings.yml b/.github/workflows/ms.insights.diagnosticsettings.yml index 477321678a..f82cf56669 100644 --- a/.github/workflows/ms.insights.diagnosticsettings.yml +++ b/.github/workflows/ms.insights.diagnosticsettings.yml @@ -7,7 +7,7 @@ on: type: boolean description: 'Remove deployed module' required: false - default: 'false' # Needs custom removals script + default: 'true' versioningOption: type: choice description: 'The mode to handle the version increments [major|minor|patch]' diff --git a/.github/workflows/ms.network.networkwatchers.yml b/.github/workflows/ms.network.networkwatchers.yml index 58513b4913..ff9b9a66ea 100644 --- a/.github/workflows/ms.network.networkwatchers.yml +++ b/.github/workflows/ms.network.networkwatchers.yml @@ -7,7 +7,7 @@ on: type: boolean description: 'Remove deployed module' required: false - default: 'false' # Required as a dependency + Only one Network Watcher can exist in the same location. If removed, a default would be created in a dedicated RG + default: 'false' # Only one Network Watcher can exist in the same location. If removed, a default would be created in a dedicated RG versioningOption: type: choice description: 'The mode to handle the version increments [major|minor|patch]' diff --git a/utilities/pipelines/resourceRemoval/Initialize-DeploymentRemoval.ps1 b/utilities/pipelines/resourceRemoval/Initialize-DeploymentRemoval.ps1 index 731f866053..54f8ad6d05 100644 --- a/utilities/pipelines/resourceRemoval/Initialize-DeploymentRemoval.ps1 +++ b/utilities/pipelines/resourceRemoval/Initialize-DeploymentRemoval.ps1 @@ -5,17 +5,17 @@ Remove deployed resources based on their deploymentName(s) .DESCRIPTION Remove deployed resources based on their deploymentName(s) -.PARAMETER deploymentName(s) +.PARAMETER DeploymentName(s) Mandatory. The name(s) of the deployment(s) -.PARAMETER templateFilePath +.PARAMETER TemplateFilePath Mandatory. The path to the template used for the deployment. Used to determine the level/scope (e.g. subscription) .PARAMETER ResourceGroupName Optional. The name of the resource group the deployment was happening in. Relevant for resource-group level deployments. .EXAMPLE -Initialize-DeploymentRemoval -deploymentName 'virtualWans-20211204T1812029146Z' -templateFilePath "$home/ResourceModules/arm/Microsoft.Network/virtualWans/deploy.bicep" -resourceGroupName 'test-virtualWan-parameters.json-rg' +Initialize-DeploymentRemoval -DeploymentName 'virtualWans-20211204T1812029146Z' -TemplateFilePath "$home/ResourceModules/arm/Microsoft.Network/virtualWans/deploy.bicep" -resourceGroupName 'test-virtualWan-parameters.json-rg' Remove the deployment 'virtualWans-20211204T1812029146Z' from resource group 'test-virtualWan-parameters.json-rg' that was executed using template in path "$home/ResourceModules/arm/Microsoft.Network/virtualWans/deploy.bicep" #> @@ -24,11 +24,11 @@ function Initialize-DeploymentRemoval { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] - [Alias('deploymentName')] - [string[]] $deploymentNames, + [Alias('DeploymentName')] + [string[]] $DeploymentNames, [Parameter(Mandatory = $true)] - [string] $templateFilePath, + [string] $TemplateFilePath, [Parameter(Mandatory = $false)] [string] $ResourceGroupName = 'validation-rg' @@ -74,10 +74,10 @@ function Initialize-DeploymentRemoval { # Invoke removal $inputObject = @{ - deploymentName = $deploymentName - ResourceGroupName = $ResourceGroupName - templateFilePath = $templateFilePath - removalSequence = $removalSequence + DeploymentName = $deploymentName + ResourceGroupName = $resourceGroupName + TemplateFilePath = $templateFilePath + RemovalSequence = $removalSequence } Remove-Deployment @inputObject -Verbose } diff --git a/utilities/pipelines/resourceRemoval/helper/Get-DependencyResourceNameList.ps1 b/utilities/pipelines/resourceRemoval/helper/Get-DependencyResourceNameList.ps1 index 9cb9210564..c3748e2dad 100644 --- a/utilities/pipelines/resourceRemoval/helper/Get-DependencyResourceNameList.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Get-DependencyResourceNameList.ps1 @@ -6,7 +6,7 @@ Get a list of all dependency resources specified in the dependencies parameter f Get a list of all dependency resources specified in the dependencies parameter files Note: It only considers resources that use the 'name' parameter -.PARAMETER dependencyParameterPath +.PARAMETER DependencyParameterPath Optional. The path the the dependency parameters parent folder. Defaults to 'utilities/pipelines/dependencies' .EXAMPLE @@ -19,7 +19,7 @@ function Get-DependencyResourceNameList { [CmdletBinding()] param ( [Parameter(Mandatory = $false)] - [string] $dependencyParameterPath = (Join-Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) 'dependencies') + [string] $DependencyParameterPath = (Join-Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) 'dependencies') ) $parameterFolders = Get-ChildItem -Path $dependencyParameterPath -Recurse -Filter 'parameters' -Directory diff --git a/utilities/pipelines/resourceRemoval/helper/Get-OrderedResourcesList.ps1 b/utilities/pipelines/resourceRemoval/helper/Get-OrderedResourcesList.ps1 index 5eb47e4f55..0c94365267 100644 --- a/utilities/pipelines/resourceRemoval/helper/Get-OrderedResourcesList.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Get-OrderedResourcesList.ps1 @@ -6,7 +6,7 @@ Order the given resources as per the provided ordered resource type list Order the given resources as per the provided ordered resource type list. Any resources not in that list will be appended after. -.PARAMETER resourcesToOrder +.PARAMETER ResourcesToOrder Mandatory. The resources to order. Items are stacked as per their order in the list (i.e. the first items is put on top, then the next, etc.) Each item should be in format: @{ @@ -15,11 +15,11 @@ Each item should be in format: type = '...' } -.PARAMETER order -Optional. The order of resource types to apply. If order is provided, the list is returned as is +.PARAMETER Order +Optional. The order of resource types to apply for deletion. If order is provided, the list is returned as is .EXAMPLE -Get-OrderedResourcesList -resourcesToOrder @(@{ name = 'myAccount'; resourceId '(..)/Microsoft.Automation/automationAccounts/myAccount'; type = 'Microsoft.Automation/automationAccounts'}) -order @('Microsoft.Insights/diagnosticSettings','Microsoft.Automation/automationAccounts') +Get-OrderedResourcesList -ResourcesToOrder @(@{ name = 'myAccount'; resourceId '(..)/Microsoft.Automation/automationAccounts/myAccount'; type = 'Microsoft.Automation/automationAccounts'}) -Order @('Microsoft.Insights/diagnosticSettings','Microsoft.Automation/automationAccounts') Order the given list of resources which would put the diagnostic settings to the front of the list, then the automation account, then the rest. As only one item exists, the list is returned as is. #> @@ -28,10 +28,10 @@ function Get-OrderedResourcesList { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] - [hashtable[]] $resourcesToOrder, + [hashtable[]] $ResourcesToOrder, [Parameter(Mandatory = $false)] - [string[]] $order = @() + [string[]] $Order = @() ) # Going from back to front of the list to stack in the correct order diff --git a/utilities/pipelines/resourceRemoval/helper/Get-ResourceIdsAsFormattedObjectList.ps1 b/utilities/pipelines/resourceRemoval/helper/Get-ResourceIdsAsFormattedObjectList.ps1 index 417914276d..7f971aad54 100644 --- a/utilities/pipelines/resourceRemoval/helper/Get-ResourceIdsAsFormattedObjectList.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Get-ResourceIdsAsFormattedObjectList.ps1 @@ -5,11 +5,11 @@ Format the provide resource IDs into objects of resourceID, name & type .DESCRIPTION Format the provide resource IDs into objects of resourceID, name & type -.PARAMETER resourceIds +.PARAMETER ResourceIds Optional. The resource IDs to process .EXAMPLE -Get-ResourceIdsAsFormattedObjectList -resourceIds @('/subscriptions//resourceGroups/test-analysisServices-parameters.json-rg/providers/Microsoft.Storage/storageAccounts/adpsxxazsaaspar01') +Get-ResourceIdsAsFormattedObjectList -ResourceIds @('/subscriptions//resourceGroups/test-analysisServices-parameters.json-rg/providers/Microsoft.Storage/storageAccounts/adpsxxazsaaspar01') Returns an object @{ resourceId = '/subscriptions//resourceGroups/test-analysisServices-parameters.json-rg/providers/Microsoft.Storage/storageAccounts/adpsxxazsaaspar01' @@ -22,7 +22,7 @@ function Get-ResourceIdsAsFormattedObjectList { [CmdletBinding()] param ( [Parameter(Mandatory = $false)] - [string[]] $resourceIds = @() + [string[]] $ResourceIds = @() ) $formattedResources = [System.Collections.ArrayList]@() diff --git a/utilities/pipelines/resourceRemoval/helper/Get-ResourceIdsOfDeployment.ps1 b/utilities/pipelines/resourceRemoval/helper/Get-ResourceIdsOfDeployment.ps1 index b996947423..076aa7ad06 100644 --- a/utilities/pipelines/resourceRemoval/helper/Get-ResourceIdsOfDeployment.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Get-ResourceIdsOfDeployment.ps1 @@ -10,15 +10,15 @@ Get all deployments that match a given deployment name in a given scope. Works r Mandatory. The deployment name to search for .PARAMETER ResourceGroupName -Optional. The name of the resource group for scope 'resourceGroup' +Optional. The name of the resource group for scope 'resourcegroup' .PARAMETER Scope Mandatory. The scope to search in .EXAMPLE -Get-ResourceIdsOfDeploymentInner -Name 'keyvault-12356' -Scope 'resourceGroup' +Get-ResourceIdsOfDeploymentInner -Name 'keyvault-12356' -Scope 'resourcegroup' -Get all deployments that match name 'keyvault-12356' in scope 'resourceGroup' +Get all deployments that match name 'keyvault-12356' in scope 'resourcegroup' .NOTES Works after the principal: @@ -38,9 +38,9 @@ function Get-ResourceIdsOfDeploymentInner { [Parameter(Mandatory)] [ValidateSet( - 'resourceGroup', + 'resourcegroup', 'subscription', - 'managementGroup', + 'managementgroup', 'tenant' )] [string] $Scope @@ -57,7 +57,7 @@ function Get-ResourceIdsOfDeploymentInner { foreach ($deployment in ($deploymentTargets | Where-Object { $_ -match '/deployments/' } )) { $name = Split-Path $deployment -Leaf $resourceGroupName = $deployment.split('/resourceGroups/')[1].Split('/')[0] - [array]$resultSet += Get-ResourceIdsOfDeploymentInner -Name $name -ResourceGroupName $ResourceGroupName -Scope 'resourceGroup' + [array]$resultSet += Get-ResourceIdsOfDeploymentInner -Name $name -ResourceGroupName $ResourceGroupName -Scope 'resourcegroup' } } else { # In case the resource group itself was already deleted, there is no need to try and fetch deployments from it @@ -76,7 +76,7 @@ function Get-ResourceIdsOfDeploymentInner { # Resource Group Level Child Deployments $name = Split-Path $deployment -Leaf $resourceGroupName = $deployment.split('/resourceGroups/')[1].Split('/')[0] - [array]$resultSet += Get-ResourceIdsOfDeploymentInner -Name $name -ResourceGroupName $ResourceGroupName -Scope 'resourceGroup' + [array]$resultSet += Get-ResourceIdsOfDeploymentInner -Name $name -ResourceGroupName $ResourceGroupName -Scope 'resourcegroup' } else { # Subscription Level Deployments [array]$resultSet += Get-ResourceIdsOfDeploymentInner -name (Split-Path $deployment -Leaf) -Scope 'subscription' @@ -95,7 +95,7 @@ function Get-ResourceIdsOfDeploymentInner { [array]$resultSet += Get-ResourceIdsOfDeploymentInner -Name (Split-Path $deployment -Leaf) -Scope 'subscription' } else { # Management Group Level Deployments - [array]$resultSet += Get-ResourceIdsOfDeploymentInner -name (Split-Path $deployment -Leaf) -scope 'managementGroup' + [array]$resultSet += Get-ResourceIdsOfDeploymentInner -name (Split-Path $deployment -Leaf) -scope 'managementgroup' } } } @@ -108,7 +108,7 @@ function Get-ResourceIdsOfDeploymentInner { [array]$resultSet = $resultSet | Where-Object { $_ -ne $deployment } if ($deployment -match '/tenant/') { # Management Group Level Child Deployments - [array]$resultSet += Get-ResourceIdsOfDeploymentInner -Name (Split-Path $deployment -Leaf) -scope 'managementGroup' + [array]$resultSet += Get-ResourceIdsOfDeploymentInner -Name (Split-Path $deployment -Leaf) -scope 'managementgroup' } else { # Tenant Level Deployments [array]$resultSet += Get-ResourceIdsOfDeploymentInner -name (Split-Path $deployment -Leaf) @@ -133,7 +133,7 @@ Mandatory. The resource group of the resource to remove .PARAMETER Name Optional. The deployment name to use for the removal -.PARAMETER scope +.PARAMETER Scope Mandatory. The scope to search in .PARAMETER SearchRetryLimit @@ -143,9 +143,9 @@ Optional. The maximum times to retry the search for resources via their removal Optional. The time to wait in between the search for resources via their remove tags .EXAMPLE -Get-ResourceIdsOfDeployment -name 'KeyVault' -ResourceGroupName 'validation-rg' -scope 'resourceGroup' +Get-ResourceIdsOfDeployment -name 'KeyVault' -ResourceGroupName 'validation-rg' -scope 'resourcegroup' -Get all deployments that match name 'KeyVault' in scope 'resourceGroup' of resource group 'validation-rg' +Get all deployments that match name 'KeyVault' in scope 'resourcegroup' of resource group 'validation-rg' #> function Get-ResourceIdsOfDeployment { @@ -155,10 +155,16 @@ function Get-ResourceIdsOfDeployment { [string] $ResourceGroupName, [Parameter(Mandatory = $true)] - [string] $name, + [string] $Name, [Parameter(Mandatory = $true)] - [string] $scope, + [ValidateSet( + 'resourcegroup', + 'subscription', + 'managementgroup', + 'tenant' + )] + [string] $Scope, [Parameter(Mandatory = $false)] [int] $SearchRetryLimit = 40, @@ -169,7 +175,7 @@ function Get-ResourceIdsOfDeployment { $searchRetryCount = 1 do { - [array]$deployments = Get-ResourceIdsOfDeploymentInner -name $name -scope $scope -resourceGroupName $resourceGroupName -ErrorAction 'SilentlyContinue' + [array]$deployments = Get-ResourceIdsOfDeploymentInner -Name $name -Scope $scope -ResourceGroupName $resourceGroupName -ErrorAction 'SilentlyContinue' if ($deployments) { break } diff --git a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 index c8e0e329ef..6d93fefe36 100644 --- a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 @@ -5,17 +5,17 @@ Remove any artifacts that remain of the given resource .DESCRIPTION Remove any artifacts that remain of the given resource. For example, some resources such as key vaults usually go into a soft-delete state from which we want to purge them from. -.PARAMETER resourceId +.PARAMETER ResourceId Mandatory. The resourceID of the resource to remove -.PARAMETER name +.PARAMETER Name Mandatory. The name of the resource to remove -.PARAMETER type +.PARAMETER Type Mandatory. The type of the resource to remove .EXAMPLE -Invoke-ResourcePostRemoval -name 'myVault' -type 'Microsoft.KeyVault/vaults' -resourceId '/subscriptions/.../resourceGroups/validation-rg/providers/Microsoft.KeyVault/vaults/myVault' +Invoke-ResourcePostRemoval -Name 'myVault' -Type 'Microsoft.KeyVault/vaults' -ResourceId '/subscriptions/.../resourceGroups/validation-rg/providers/Microsoft.KeyVault/vaults/myVault' Purge the resource 'myVault' of type 'Microsoft.KeyVault/vaults' with ID '/subscriptions/.../resourceGroups/validation-rg/providers/Microsoft.KeyVault/vaults/myVault' if no purge protection is enabled #> @@ -24,13 +24,13 @@ function Invoke-ResourcePostRemoval { [CmdletBinding(SupportsShouldProcess)] param ( [Parameter(Mandatory = $true)] - [string] $resourceId, + [string] $ResourceId, [Parameter(Mandatory = $true)] - [string] $name, + [string] $Name, [Parameter(Mandatory = $true)] - [string] $type + [string] $Type ) switch ($type) { @@ -58,28 +58,22 @@ function Invoke-ResourcePostRemoval { $subscriptionId = $resourceId.Split('/')[2] # Fetch service in soft-delete - $getUri = 'https://management.azure.com/subscriptions/{0}/providers/Microsoft.ApiManagement/deletedservices?api-version=2021-08-01' -f $subscriptionId - $requestInputObject = @{ - Method = 'GET' - Uri = $getUri - Headers = @{ - Authorization = 'Bearer {0}' -f (Get-AzAccessToken).Token - } + $getPath = '/subscriptions/{0}/providers/Microsoft.ApiManagement/deletedservices?api-version=2021-08-01' -f $subscriptionId + $getRequestInputObject = @{ + Method = 'GET' + Path = $getPath } - $softDeletedService = (Invoke-RestMethod @requestInputObject).value | Where-Object { $_.properties.serviceId -eq $resourceId } + $softDeletedService = ((Invoke-AzRestMethod @getRequestInputObject).Content | ConvertFrom-Json).value | Where-Object { $_.properties.serviceId -eq $resourceId } if ($softDeletedService) { # Purge service - $purgeUri = 'https://management.azure.com/subscriptions/{0}/providers/Microsoft.ApiManagement/locations/{1}/deletedservices/{2}?api-version=2020-06-01-preview' -f $subscriptionId, $softDeletedService.location, $name - $requestInputObject = @{ - Method = 'DELETE' - Uri = $purgeUri - Headers = @{ - Authorization = 'Bearer {0}' -f (Get-AzAccessToken).Token - } + $purgePath = '/subscriptions/{0}/providers/Microsoft.ApiManagement/locations/{1}/deletedservices/{2}?api-version=2020-06-01-preview' -f $subscriptionId, $softDeletedService.location, $name + $purgeRequestInputObject = @{ + Method = 'DELETE' + Path = $purgePath } if ($PSCmdlet.ShouldProcess(('API management service with ID [{0}]' -f $softDeletedService.properties.serviceId), 'Purge')) { - $null = Invoke-RestMethod @requestInputObject + $null = Invoke-AzRestMethod @purgeRequestInputObject } } } diff --git a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 index 017ae3c26a..350a52195e 100644 --- a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 @@ -5,17 +5,17 @@ Remove a specific resource .DESCRIPTION Remove a specific resource. Tries to handle different resource types accordingly -.PARAMETER resourceId +.PARAMETER ResourceId Mandatory. The resourceID of the resource to remove -.PARAMETER name +.PARAMETER Name Mandatory. The name of the resource to remove -.PARAMETER type +.PARAMETER Type Mandatory. The type of the resource to remove .EXAMPLE -Invoke-ResourceRemoval -name 'sxx-vm-linux-001-nic-01-diagnosticSettings' -type 'Microsoft.Insights/diagnosticSettings' -resourceId '/subscriptions/.../resourceGroups/validation-rg/providers/Microsoft.Network/networkInterfaces/sxx-vm-linux-001-nic-01/providers/Microsoft.Insights/diagnosticSettings/sxx-vm-linux-001-nic-01-diagnosticSettings' +Invoke-ResourceRemoval -Name 'sxx-vm-linux-001-nic-01-diagnosticSettings' -Type 'Microsoft.Insights/diagnosticSettings' -ResourceId '/subscriptions/.../resourceGroups/validation-rg/providers/Microsoft.Network/networkInterfaces/sxx-vm-linux-001-nic-01/providers/Microsoft.Insights/diagnosticSettings/sxx-vm-linux-001-nic-01-diagnosticSettings' Remove the resource 'sxx-vm-linux-001-nic-01-diagnosticSettings' of type 'Microsoft.Insights/diagnosticSettings' from resource '/subscriptions/.../resourceGroups/validation-rg/providers/Microsoft.Network/networkInterfaces/sxx-vm-linux-001-nic-01' #> @@ -24,13 +24,13 @@ function Invoke-ResourceRemoval { [CmdletBinding(SupportsShouldProcess)] param ( [Parameter(Mandatory = $true)] - [string] $resourceId, + [string] $ResourceId, [Parameter(Mandatory = $true)] - [string] $name, + [string] $Name, [Parameter(Mandatory = $true)] - [string] $type + [string] $Type ) switch ($type) { diff --git a/utilities/pipelines/resourceRemoval/helper/Remove-Deployment.ps1 b/utilities/pipelines/resourceRemoval/helper/Remove-Deployment.ps1 index d1bd0aaae5..a680938a6d 100644 --- a/utilities/pipelines/resourceRemoval/helper/Remove-Deployment.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Remove-Deployment.ps1 @@ -24,6 +24,9 @@ Optional. The deployment name to use for the removal .PARAMETER TemplateFilePath Optional. The path to the deployment file +.PARAMETER RemovalSequence +Optional. The order of resource types to apply for deletion + .EXAMPLE Remove-Deployment -DeploymentName 'KeyVault' -ResourceGroupName 'validation-rg' -TemplateFilePath 'C:/deploy.json' @@ -78,9 +81,9 @@ function Remove-Deployment { # Fetch deployments # ================= $deploymentsInputObject = @{ - name = $deploymentName - scope = $deploymentScope - resourceGroupName = $resourceGroupName + Name = $deploymentName + Scope = $deploymentScope + ResourceGroupName = $resourceGroupName } $deploymentResourceIds = Get-ResourceIdsOfDeployment @deploymentsInputObject -Verbose @@ -90,7 +93,7 @@ function Remove-Deployment { # Format items # ============ - $resourcesToRemove = Get-ResourceIdsAsFormattedObjectList -resourceIds $rawResourceIdsToRemove + $resourcesToRemove = Get-ResourceIdsAsFormattedObjectList -ResourceIds $rawResourceIdsToRemove # Filter all dependency resources # =============================== @@ -99,13 +102,13 @@ function Remove-Deployment { # Order resources # =============== - $resourcesToRemove = Get-OrderedResourcesList -resourcesToOrder $resourcesToRemove -order $RemovalSequence + $resourcesToRemove = Get-OrderedResourcesList -ResourcesToOrder $resourcesToRemove -Order $RemovalSequence # Remove resources # ================ if ($resourcesToRemove.Count -gt 0) { if ($PSCmdlet.ShouldProcess(('[{0}] resources' -f (($resourcesToRemove -is [array]) ? $resourcesToRemove.Count : 1)), 'Remove')) { - Remove-ResourceList -resourcesToRemove $resourcesToRemove -Verbose + Remove-ResourceList -ResourcesToRemove $resourcesToRemove -Verbose } } else { Write-Verbose 'Found [0] resources to remove' diff --git a/utilities/pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 b/utilities/pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 index 12aee3bab8..fa02b523d4 100644 --- a/utilities/pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 @@ -6,18 +6,18 @@ Remove the given resource(s) .DESCRIPTION Remove the given resource(s). Resources that the script fails to removed are returned in an array. -.PARAMETER resourcesToRemove +.PARAMETER ResourcesToRemove Mandatory. The resource(s) to remove. Each resource must have a name (optional), type (optional) & resourceId property. .EXAMPLE -Remove-ResourceListInner -resourcesToRemove @( @{ 'Name' = 'resourceName'; Type = 'Microsoft.Storage/storageAccounts'; ResourceId = 'subscriptions/.../storageAccounts/resourceName' } ) +Remove-ResourceListInner -ResourcesToRemove @( @{ 'Name' = 'resourceName'; Type = 'Microsoft.Storage/storageAccounts'; ResourceId = 'subscriptions/.../storageAccounts/resourceName' } ) #> function Remove-ResourceListInner { [CmdletBinding(SupportsShouldProcess)] param( [Parameter(Mandatory = $false)] - [Hashtable[]] $resourcesToRemove = @() + [Hashtable[]] $ResourcesToRemove = @() ) begin { @@ -47,7 +47,7 @@ function Remove-ResourceListInner { Write-Verbose ('Removing resource [{0}] of type [{1}]' -f $resource.name, $resource.type) -Verbose try { if ($PSCmdlet.ShouldProcess(('Resource [{0}]' -f $resource.resourceId), 'Remove')) { - Invoke-ResourceRemoval -ResourceId $resource.resourceId -name $resource.name -type $resource.type + Invoke-ResourceRemoval -Name $resource.name -Type $resource.type -ResourceId $resource.resourceId } # If we removed a parent remove its children @@ -59,9 +59,9 @@ function Remove-ResourceListInner { } } - # We want to purge resources even if they were not explictely removed because they were 'alreadyProcessed' + # We want to purge resources even if they were not explicitly removed because they were 'alreadyProcessed' if ($PSCmdlet.ShouldProcess(('Post-resource-removal for [{0}]' -f $resource.resourceId), 'Execute')) { - Invoke-ResourcePostRemoval -name $resource.name -type $resource.type -resourceId $resource.resourceId + Invoke-ResourcePostRemoval -Name $resource.name -Type $resource.type -ResourceId $resource.resourceId } } Write-Verbose '----------------------------------' -Verbose @@ -80,7 +80,7 @@ Remove all resources in the provided array from Azure .DESCRIPTION Remove all resources in the provided array from Azure. Resources are removed with a retry mechanism. -.PARAMETER resourcesToRemove +.PARAMETER ResourcesToRemove Optional. The array of resources to remove. Has to contain objects with at least a 'resourceId' property .EXAMPLE @@ -107,9 +107,9 @@ function Remove-ResourceList { do { if ($PSCmdlet.ShouldProcess(("[{0}] Resource(s) with a maximum of [$removalRetryLimit] attempts." -f (($resourcesToRetry -is [array]) ? $resourcesToRetry.Count : 1)), 'Remove')) { - $resourcesToRetry = Remove-ResourceListInner -resourcesToRemove $resourcesToRetry -Verbose + $resourcesToRetry = Remove-ResourceListInner -ResourcesToRemove $resourcesToRetry -Verbose } else { - Remove-ResourceListInner -resourcesToRemove $resourcesToRemove -WhatIf + Remove-ResourceListInner -ResourcesToRemove $resourcesToRemove -WhatIf } if (-not $resourcesToRetry) { diff --git a/utilities/pipelines/sharedScripts/Get-ScopeOfTemplateFile.ps1 b/utilities/pipelines/sharedScripts/Get-ScopeOfTemplateFile.ps1 index 1c1f5cbec5..d2b13414cb 100644 --- a/utilities/pipelines/sharedScripts/Get-ScopeOfTemplateFile.ps1 +++ b/utilities/pipelines/sharedScripts/Get-ScopeOfTemplateFile.ps1 @@ -5,9 +5,9 @@ Get the scope of the given template file .DESCRIPTION Get the scope of the given template file (supports ARM & Bicep) Will return either -- resourceGroup +- resourcegroup - subscription -- managementGroup +- managementgroup - tenant .PARAMETER TemplateFilePath