From 7a29e2c9ffb0e8449a7c08b5e0d5df03a58f9c70 Mon Sep 17 00:00:00 2001 From: Erika Gressi Date: Mon, 13 Dec 2021 20:07:52 +0100 Subject: [PATCH 01/15] parameter case level 01 --- .../pipelineTemplates/module.jobs.deploy.yml | 8 +++---- .../validateModuleDeployment/action.yml | 8 +++---- .../Initialize-DeploymentRemoval.ps1 | 22 +++++++++---------- .../helper/Get-OrderedResourcesList.ps1 | 2 +- .../helper/Remove-Deployment.ps1 | 3 +++ 5 files changed, 23 insertions(+), 20 deletions(-) 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/utilities/pipelines/resourceRemoval/Initialize-DeploymentRemoval.ps1 b/utilities/pipelines/resourceRemoval/Initialize-DeploymentRemoval.ps1 index 731f866053..476a64fb8f 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' @@ -41,7 +41,7 @@ function Initialize-DeploymentRemoval { } process { - $moduleName = Split-Path (Split-Path $templateFilePath -Parent) -LeafBase + $moduleName = Split-Path (Split-Path $TemplateFilePath -Parent) -LeafBase # The intial sequence is a general order-recommendation $removalSequence = @( @@ -50,7 +50,7 @@ function Initialize-DeploymentRemoval { 'Microsoft.Compute/virtualMachines' ) - foreach ($deploymentName in $deploymentNames) { + foreach ($deploymentName in $DeploymentNames) { Write-Verbose ('Handling resource removal with deployment name [{0}]' -f $deploymentName) -Verbose switch ($moduleName) { 'virtualWans' { @@ -74,10 +74,10 @@ function Initialize-DeploymentRemoval { # Invoke removal $inputObject = @{ - deploymentName = $deploymentName + DeploymentName = $deploymentName ResourceGroupName = $ResourceGroupName - templateFilePath = $templateFilePath - removalSequence = $removalSequence + TemplateFilePath = $TemplateFilePath + RemovalSequence = $removalSequence } Remove-Deployment @inputObject -Verbose } diff --git a/utilities/pipelines/resourceRemoval/helper/Get-OrderedResourcesList.ps1 b/utilities/pipelines/resourceRemoval/helper/Get-OrderedResourcesList.ps1 index 5eb47e4f55..ca92947bbe 100644 --- a/utilities/pipelines/resourceRemoval/helper/Get-OrderedResourcesList.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Get-OrderedResourcesList.ps1 @@ -16,7 +16,7 @@ Each item should be in format: } .PARAMETER order -Optional. The order of resource types to apply. If order is provided, the list is returned as is +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') diff --git a/utilities/pipelines/resourceRemoval/helper/Remove-Deployment.ps1 b/utilities/pipelines/resourceRemoval/helper/Remove-Deployment.ps1 index b19370aede..fe88a9d56c 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' From 1f7b9b29d0c1ba3dca6709be2449c73972587ec1 Mon Sep 17 00:00:00 2001 From: Erika Gressi Date: Mon, 13 Dec 2021 21:29:17 +0100 Subject: [PATCH 02/15] parameter case level 02 1 --- .../helper/Get-ResourceIdsOfDeployment.ps1 | 36 +++++++++++-------- .../helper/Remove-Deployment.ps1 | 6 ++-- .../sharedScripts/Get-ScopeOfTemplateFile.ps1 | 4 +-- 3 files changed, 26 insertions(+), 20 deletions(-) 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/Remove-Deployment.ps1 b/utilities/pipelines/resourceRemoval/helper/Remove-Deployment.ps1 index fe88a9d56c..4b81d88c19 100644 --- a/utilities/pipelines/resourceRemoval/helper/Remove-Deployment.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Remove-Deployment.ps1 @@ -81,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 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 From df747660f6e501b9fbdaffce78d8267a7cb55a4f Mon Sep 17 00:00:00 2001 From: Erika Gressi Date: Mon, 13 Dec 2021 21:44:35 +0100 Subject: [PATCH 03/15] parameter case level 02 2 --- .../helper/Get-DependencyResourceNameList.ps1 | 4 ++-- .../helper/Get-OrderedResourcesList.ps1 | 10 +++++----- .../helper/Get-ResourceIdsAsFormattedObjectList.ps1 | 6 +++--- .../resourceRemoval/helper/Remove-Deployment.ps1 | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) 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 ca92947bbe..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 +.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/Remove-Deployment.ps1 b/utilities/pipelines/resourceRemoval/helper/Remove-Deployment.ps1 index 4b81d88c19..903d81f1f5 100644 --- a/utilities/pipelines/resourceRemoval/helper/Remove-Deployment.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Remove-Deployment.ps1 @@ -93,7 +93,7 @@ function Remove-Deployment { # Format items # ============ - $resourcesToRemove = Get-ResourceIdsAsFormattedObjectList -resourceIds $rawResourceIdsToRemove + $resourcesToRemove = Get-ResourceIdsAsFormattedObjectList -ResourceIds $rawResourceIdsToRemove # Filter all dependency resources # =============================== @@ -102,7 +102,7 @@ function Remove-Deployment { # Order resources # =============== - $resourcesToRemove = Get-OrderedResourcesList -resourcesToOrder $resourcesToRemove -order $RemovalSequence + $resourcesToRemove = Get-OrderedResourcesList -ResourcesToOrder $resourcesToRemove -Order $RemovalSequence # Remove resources # ================ From 4985f3934861090825a0e098c41009839e708a69 Mon Sep 17 00:00:00 2001 From: Erika Gressi Date: Mon, 13 Dec 2021 21:50:05 +0100 Subject: [PATCH 04/15] parameter case level 02 3 --- .../resourceRemoval/helper/Remove-Deployment.ps1 | 2 +- .../resourceRemoval/helper/Remove-ResourceList.ps1 | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/utilities/pipelines/resourceRemoval/helper/Remove-Deployment.ps1 b/utilities/pipelines/resourceRemoval/helper/Remove-Deployment.ps1 index 903d81f1f5..8c74969f42 100644 --- a/utilities/pipelines/resourceRemoval/helper/Remove-Deployment.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Remove-Deployment.ps1 @@ -108,7 +108,7 @@ function Remove-Deployment { # ================ 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 e4fc995aaa..9fe1afc789 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 { @@ -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) { From e75eb04476ac6b0b5d4b955b1ca9952c14b69939 Mon Sep 17 00:00:00 2001 From: Erika Gressi Date: Mon, 13 Dec 2021 22:00:11 +0100 Subject: [PATCH 05/15] parameter case level 03 1 --- .../resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 index a4a61b75ce..942e1e5de2 100644 --- a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 @@ -5,7 +5,7 @@ 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 resourceToRemove +.PARAMETER ResourceToRemove Mandatory. The resource to remove. Should have format @{ name = '...' @@ -14,7 +14,7 @@ Mandatory. The resource to remove. Should have format } .EXAMPLE -Invoke-ResourcePostRemoval -resourceToRemove @{ name = 'myVault'; resourceId '(..)/Microsoft.KeyVault/vaults/myVault'; type = 'Microsoft.KeyVault/vaults'} +Invoke-ResourcePostRemoval -ResourceToRemove @{ name = 'myVault'; resourceId '(..)/Microsoft.KeyVault/vaults/myVault'; type = 'Microsoft.KeyVault/vaults'} Purge resource 'myVault' of type 'Microsoft.KeyVault/vaults' if no purge protection is enabled #> @@ -23,7 +23,7 @@ function Invoke-ResourcePostRemoval { [CmdletBinding(SupportsShouldProcess)] param ( [Parameter(Mandatory)] - [hashtable] $resourceToRemove + [hashtable] $ResourceToRemove ) switch ($resourceToRemove.type) { From 92f3f72cfe95ddf605cc2113608a2b7682b59dc1 Mon Sep 17 00:00:00 2001 From: Erika Gressi Date: Tue, 14 Dec 2021 00:19:41 +0100 Subject: [PATCH 06/15] purge api --- .../helper/Invoke-ResourcePostRemoval.ps1 | 52 +++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 index 942e1e5de2..21757e853f 100644 --- a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 @@ -50,29 +50,49 @@ function Invoke-ResourcePostRemoval { 'Microsoft.ApiManagement/service' { $subscriptionId = $resourceToRemove.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 + # } + # } + # $softDeletedService = (Invoke-RestMethod @requestInputObject).value | Where-Object { $_.properties.serviceId -eq $resourceToRemove.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, $resourceToRemove.name + # $requestInputObject = @{ + # Method = 'DELETE' + # Uri = $purgeUri + # Headers = @{ + # Authorization = 'Bearer {0}' -f (Get-AzAccessToken).Token + # } + # } + # if ($PSCmdlet.ShouldProcess(('API management service with ID [{0}]' -f $softDeletedService.properties.serviceId), 'Purge')) { + # $null = Invoke-RestMethod @requestInputObject + # } + # } + # 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 $resourceToRemove.resourceId } + $softDeletedService = ((Invoke-AzRestMethod @getRequestInputObject).Content | ConvertFrom-Json).value | Where-Object { $_.properties.serviceId -eq $resourceToRemove.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, $resourceToRemove.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, $resourceToRemove.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 } } } From dab332aca487678a53cb47a78e176bda90f6ff9d Mon Sep 17 00:00:00 2001 From: Erika Gressi Date: Tue, 14 Dec 2021 00:35:15 +0100 Subject: [PATCH 07/15] res removal object --- .../helper/Invoke-ResourceRemoval.ps1 | 49 ++++++++++--------- .../helper/Remove-ResourceList.ps1 | 7 +-- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 index 3468d99e64..6cb18214bb 100644 --- a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 @@ -21,23 +21,28 @@ Remove the resource 'sxx-vm-linux-001-nic-01-diagnosticSettings' of type 'Micros #> function Invoke-ResourceRemoval { - [CmdletBinding(SupportsShouldProcess)] - param ( - [Parameter()] - [string] $resourceId, + # [CmdletBinding(SupportsShouldProcess)] + # param ( + # [Parameter()] + # [string] $resourceId, - [Parameter()] - [string] $name, + # [Parameter()] + # [string] $name, - [Parameter()] - [string] $type + # [Parameter()] + # [string] $type + # ) + [CmdletBinding(SupportsShouldProcess)] + param ( + [Parameter(Mandatory)] + [hashtable] $ResourceToRemove ) - switch ($type) { + switch ($resourceToRemove.type) { 'Microsoft.Insights/diagnosticSettings' { - $parentResourceId = $resourceId.Split('/providers/{0}' -f $type)[0] - if ($PSCmdlet.ShouldProcess("Diagnostic setting [$name]", 'Remove')) { - $null = Remove-AzDiagnosticSetting -ResourceId $parentResourceId -Name $name + $parentResourceId = $resourceToRemove.resourceId.Split('/providers/{0}' -f $resourceToRemove.type)[0] + if ($PSCmdlet.ShouldProcess("Diagnostic setting [$resourceToRemove.name]", 'Remove')) { + $null = Remove-AzDiagnosticSetting -ResourceId $parentResourceId -Name $resourceToRemove.name } break } @@ -45,33 +50,33 @@ function Invoke-ResourceRemoval { # Pre-Removal # ----------- # Remove protected VMs - if ((Get-AzRecoveryServicesVaultProperty -VaultId $resourceId).SoftDeleteFeatureState -ne 'Disabled') { - if ($PSCmdlet.ShouldProcess(('Soft-delete on RSV [{0}]' -f $resourceId), 'Set')) { - $null = Set-AzRecoveryServicesVaultProperty -VaultId $resourceId -SoftDeleteFeatureState 'Disable' + if ((Get-AzRecoveryServicesVaultProperty -VaultId $resourceToRemove.resourceId).SoftDeleteFeatureState -ne 'Disabled') { + if ($PSCmdlet.ShouldProcess(('Soft-delete on RSV [{0}]' -f $resourceToRemove.resourceId), 'Set')) { + $null = Set-AzRecoveryServicesVaultProperty -VaultId $resourceToRemove.resourceId -SoftDeleteFeatureState 'Disable' } } - $backupItems = Get-AzRecoveryServicesBackupItem -BackupManagementType 'AzureVM' -WorkloadType 'AzureVM' -VaultId $resourceId + $backupItems = Get-AzRecoveryServicesBackupItem -BackupManagementType 'AzureVM' -WorkloadType 'AzureVM' -VaultId $resourceToRemove.resourceId foreach ($backupItem in $backupItems) { - Write-Verbose ('Removing Backup item [{0}] from RSV [{1}]' -f $backupItem.Name, $resourceId) -Verbose + Write-Verbose ('Removing Backup item [{0}] from RSV [{1}]' -f $backupItem.Name, $resourceToRemove.resourceId) -Verbose if ($backupItem.DeleteState -eq 'ToBeDeleted') { if ($PSCmdlet.ShouldProcess('Soft-deleted backup data removal', 'Undo')) { - $null = Undo-AzRecoveryServicesBackupItemDeletion -Item $backupItem -VaultId $resourceId -Force + $null = Undo-AzRecoveryServicesBackupItemDeletion -Item $backupItem -VaultId $resourceToRemove.resourceId -Force } } - if ($PSCmdlet.ShouldProcess(('Backup item [{0}] from RSV [{1}]' -f $backupItem.Name, $resourceId), 'Remove')) { - $null = Disable-AzRecoveryServicesBackupProtection -Item $backupItem -VaultId $resourceId -RemoveRecoveryPoints -Force + if ($PSCmdlet.ShouldProcess(('Backup item [{0}] from RSV [{1}]' -f $backupItem.Name, $resourceToRemove.resourceId), 'Remove')) { + $null = Disable-AzRecoveryServicesBackupProtection -Item $backupItem -VaultId $resourceToRemove.resourceId -RemoveRecoveryPoints -Force } } # Actual removal # -------------- - $null = Remove-AzResource -ResourceId $resourceId -Force -ErrorAction 'Stop' + $null = Remove-AzResource -ResourceId $resourceToRemove.resourceId -Force -ErrorAction 'Stop' } Default { - $null = Remove-AzResource -ResourceId $resourceId -Force -ErrorAction 'Stop' + $null = Remove-AzResource -ResourceId $resourceToRemove.resourceId -Force -ErrorAction 'Stop' } } } diff --git a/utilities/pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 b/utilities/pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 index 9fe1afc789..603e05029f 100644 --- a/utilities/pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 @@ -47,7 +47,8 @@ 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 -ResourceId $resource.resourceId -name $resource.name -type $resource.type + Invoke-ResourceRemoval -ResourceToRemove $resource } # If we removed a parent remove its children @@ -59,9 +60,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 explicitely removed because they were 'alreadyProcessed' if ($PSCmdlet.ShouldProcess(('Post-resource-removal for [{0}]' -f $resource.resourceId), 'Execute')) { - Invoke-ResourcePostRemoval -resourceToRemove $resource + Invoke-ResourcePostRemoval -ResourceToRemove $resource } } Write-Verbose '----------------------------------' -Verbose From 49c5d0f69616e2ffa3ba549c82a7e1f9a20caf42 Mon Sep 17 00:00:00 2001 From: Erika Gressi Date: Tue, 14 Dec 2021 00:44:10 +0100 Subject: [PATCH 08/15] body param to lower --- .../resourceRemoval/Initialize-DeploymentRemoval.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utilities/pipelines/resourceRemoval/Initialize-DeploymentRemoval.ps1 b/utilities/pipelines/resourceRemoval/Initialize-DeploymentRemoval.ps1 index 476a64fb8f..54f8ad6d05 100644 --- a/utilities/pipelines/resourceRemoval/Initialize-DeploymentRemoval.ps1 +++ b/utilities/pipelines/resourceRemoval/Initialize-DeploymentRemoval.ps1 @@ -41,7 +41,7 @@ function Initialize-DeploymentRemoval { } process { - $moduleName = Split-Path (Split-Path $TemplateFilePath -Parent) -LeafBase + $moduleName = Split-Path (Split-Path $templateFilePath -Parent) -LeafBase # The intial sequence is a general order-recommendation $removalSequence = @( @@ -50,7 +50,7 @@ function Initialize-DeploymentRemoval { 'Microsoft.Compute/virtualMachines' ) - foreach ($deploymentName in $DeploymentNames) { + foreach ($deploymentName in $deploymentNames) { Write-Verbose ('Handling resource removal with deployment name [{0}]' -f $deploymentName) -Verbose switch ($moduleName) { 'virtualWans' { @@ -75,8 +75,8 @@ function Initialize-DeploymentRemoval { # Invoke removal $inputObject = @{ DeploymentName = $deploymentName - ResourceGroupName = $ResourceGroupName - TemplateFilePath = $TemplateFilePath + ResourceGroupName = $resourceGroupName + TemplateFilePath = $templateFilePath RemovalSequence = $removalSequence } Remove-Deployment @inputObject -Verbose From 29236bdac5aa30d227ded202ef0699ca58df43fc Mon Sep 17 00:00:00 2001 From: Erika Gressi Date: Tue, 14 Dec 2021 00:46:54 +0100 Subject: [PATCH 09/15] typo --- .../pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilities/pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 b/utilities/pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 index 603e05029f..70a143a48b 100644 --- a/utilities/pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 @@ -60,7 +60,7 @@ function Remove-ResourceListInner { } } - # We want to purge resources even if they were not explicitely 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 -ResourceToRemove $resource } From df66a2feda29ccf6c6659b06ab8cc9a6d96f4d7c Mon Sep 17 00:00:00 2001 From: Erika Gressi Date: Tue, 14 Dec 2021 01:05:35 +0100 Subject: [PATCH 10/15] nw comment --- .github/workflows/ms.network.networkwatchers.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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]' From eab0e6d157302e41a604d3e462d59e7f6afa35fa Mon Sep 17 00:00:00 2001 From: Erika Gressi Date: Tue, 14 Dec 2021 01:23:38 +0100 Subject: [PATCH 11/15] remove diagnostic --- .github/workflows/ms.insights.diagnosticsettings.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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]' From bb9dccf14d0febb11ffddb49e81deb84ef3ccd7c Mon Sep 17 00:00:00 2001 From: Erika Gressi Date: Tue, 14 Dec 2021 01:31:05 +0100 Subject: [PATCH 12/15] invoke removal docs --- .../helper/Invoke-ResourceRemoval.ps1 | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 index 6cb18214bb..d8a11afcbd 100644 --- a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 @@ -5,33 +5,21 @@ Remove a specific resource .DESCRIPTION Remove a specific resource. Tries to handle different resource types accordingly -.PARAMETER resourceId -Mandatory. The resourceID of the resource to remove - -.PARAMETER name -Mandatory. The name of the resource to remove - -.PARAMETER type -Mandatory. The type of the resource to remove +.PARAMETER ResourceToRemove +Mandatory. The resource to remove. Should have format +@{ + name = '...' + resourceID = '...' + type = '...' +} .EXAMPLE -Invoke-ResourceRemoval -name 'sxx-vm-linux-001-nic-01-diagnosticSettings' -type 'Microsoft.Insights/diagnosticSettings' -resourceId '/subscriptions/a7439831-1cd9-435d-a091-4aa863c96556/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-ResourcePostRemoval -ResourceToRemove @{ name = 'sxx-vm-linux-001-nic-01-diagnosticSettings'; resourceId '(..)/Microsoft.Network/networkInterfaces/sxx-vm-linux-001-nic-01/providers/Microsoft.Insights/diagnosticSettings/sxx-vm-linux-001-nic-01-diagnosticSettings'; type = 'Microsoft.Insights/diagnosticSettings'} Remove the resource 'sxx-vm-linux-001-nic-01-diagnosticSettings' of type 'Microsoft.Insights/diagnosticSettings' from resource '/subscriptions/a7439831-1cd9-435d-a091-4aa863c96556/resourceGroups/validation-rg/providers/Microsoft.Network/networkInterfaces/sxx-vm-linux-001-nic-01' #> function Invoke-ResourceRemoval { - # [CmdletBinding(SupportsShouldProcess)] - # param ( - # [Parameter()] - # [string] $resourceId, - - # [Parameter()] - # [string] $name, - - # [Parameter()] - # [string] $type - # ) [CmdletBinding(SupportsShouldProcess)] param ( [Parameter(Mandatory)] From 08ef22d4a20164b4323794e3005bad844bd1db86 Mon Sep 17 00:00:00 2001 From: Erika Gressi Date: Tue, 14 Dec 2021 01:31:45 +0100 Subject: [PATCH 13/15] cleanup --- .../pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/utilities/pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 b/utilities/pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 index 70a143a48b..8e5df0515c 100644 --- a/utilities/pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Remove-ResourceList.ps1 @@ -47,7 +47,6 @@ 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 -ResourceToRemove $resource } From d08abbc3d5746debde18a4c47f9ab3b5867debb9 Mon Sep 17 00:00:00 2001 From: Erika Gressi Date: Tue, 14 Dec 2021 01:42:11 +0100 Subject: [PATCH 14/15] invoke removal docs example --- .../pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 index d8a11afcbd..b3b4c857ad 100644 --- a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 @@ -14,7 +14,7 @@ Mandatory. The resource to remove. Should have format } .EXAMPLE -Invoke-ResourcePostRemoval -ResourceToRemove @{ name = 'sxx-vm-linux-001-nic-01-diagnosticSettings'; resourceId '(..)/Microsoft.Network/networkInterfaces/sxx-vm-linux-001-nic-01/providers/Microsoft.Insights/diagnosticSettings/sxx-vm-linux-001-nic-01-diagnosticSettings'; type = 'Microsoft.Insights/diagnosticSettings'} +Invoke-ResourceRemoval -ResourceToRemove @{ name = 'sxx-vm-linux-001-nic-01-diagnosticSettings'; resourceId '(..)/Microsoft.Network/networkInterfaces/sxx-vm-linux-001-nic-01/providers/Microsoft.Insights/diagnosticSettings/sxx-vm-linux-001-nic-01-diagnosticSettings'; type = 'Microsoft.Insights/diagnosticSettings'} Remove the resource 'sxx-vm-linux-001-nic-01-diagnosticSettings' of type 'Microsoft.Insights/diagnosticSettings' from resource '/subscriptions/a7439831-1cd9-435d-a091-4aa863c96556/resourceGroups/validation-rg/providers/Microsoft.Network/networkInterfaces/sxx-vm-linux-001-nic-01' #> From 427c89c92403ef8f61d72df930277f938915b70b Mon Sep 17 00:00:00 2001 From: Erika Gressi Date: Tue, 14 Dec 2021 01:58:17 +0100 Subject: [PATCH 15/15] cleanup --- .../helper/Invoke-ResourcePostRemoval.ps1 | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 index 21757e853f..4ec78746c3 100644 --- a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 @@ -50,32 +50,6 @@ function Invoke-ResourcePostRemoval { 'Microsoft.ApiManagement/service' { $subscriptionId = $resourceToRemove.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 - # } - # } - # $softDeletedService = (Invoke-RestMethod @requestInputObject).value | Where-Object { $_.properties.serviceId -eq $resourceToRemove.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, $resourceToRemove.name - # $requestInputObject = @{ - # Method = 'DELETE' - # Uri = $purgeUri - # Headers = @{ - # Authorization = 'Bearer {0}' -f (Get-AzAccessToken).Token - # } - # } - # if ($PSCmdlet.ShouldProcess(('API management service with ID [{0}]' -f $softDeletedService.properties.serviceId), 'Purge')) { - # $null = Invoke-RestMethod @requestInputObject - # } - # } - # Fetch service in soft-delete $getPath = '/subscriptions/{0}/providers/Microsoft.ApiManagement/deletedservices?api-version=2021-08-01' -f $subscriptionId $getRequestInputObject = @{