Skip to content
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
8 changes: 4 additions & 4 deletions .azuredevops/pipelineTemplates/module.jobs.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions .github/actions/templates/validateModuleDeployment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ms.insights.diagnosticsettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ms.network.networkwatchers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
#>
Expand All @@ -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'
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
@{
Expand All @@ -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.
#>
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/<subscriptionID>/resourceGroups/test-analysisServices-parameters.json-rg/providers/Microsoft.Storage/storageAccounts/adpsxxazsaaspar01')
Get-ResourceIdsAsFormattedObjectList -ResourceIds @('/subscriptions/<subscriptionID>/resourceGroups/test-analysisServices-parameters.json-rg/providers/Microsoft.Storage/storageAccounts/adpsxxazsaaspar01')

Returns an object @{
resourceId = '/subscriptions/<subscriptionID>/resourceGroups/test-analysisServices-parameters.json-rg/providers/Microsoft.Storage/storageAccounts/adpsxxazsaaspar01'
Expand All @@ -22,7 +22,7 @@ function Get-ResourceIdsAsFormattedObjectList {
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[string[]] $resourceIds = @()
[string[]] $ResourceIds = @()
)

$formattedResources = [System.Collections.ArrayList]@()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -38,9 +38,9 @@ function Get-ResourceIdsOfDeploymentInner {

[Parameter(Mandatory)]
[ValidateSet(
'resourceGroup',
'resourcegroup',
'subscription',
'managementGroup',
'managementgroup',
'tenant'
)]
[string] $Scope
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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'
}
}
}
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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 {

Expand All @@ -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,
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
#>
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}
}
}
Expand Down
Loading