Public/Remove-DuneDeployment.ps1
|
<# .SYNOPSIS Removes DuneDeployment object. .DESCRIPTION Removes DuneDeployment object. By default removes from Dune only (no resources will be deleted) Specify IncludeChildren to also delete all child objects. In order to delete all resources from provider, specify unstage switch to invoke the unstage automation process. Deployment will be deleted when unstage process sucessfully completes. .PARAMETER Name Specifies the DuneDeployment name. .PARAMETER Id Specifies the DuneDeployment id. .PARAMETER Deployment Specifies the DuneDeployment object. .PARAMETER IncludeChildren Specifies whether ResourceGroups/Resources belonging to that Deployment are deleted as well. .PARAMETER Unstage Invokes unstage automation process. Deployment will be deleted if process is successfull, otherwise it will be set to failed. .PARAMETER Unlock Unlocks the deployment before removing/unstaging .INPUTS DuneDeployment object. .OUTPUTS Invoke-WebRequest output. .EXAMPLE > Remove-DuneDeployment -Name foo .EXAMPLE > Get-DuneDeployment foo | Remove-DuneDeployment -Unstage .EXAMPLE > Get-DuneDeployment foo | Remove-DuneDeployment -IncludeChildren -Unlock .EXAMPLE > Get-DuneDeployment foo | Remove-DuneDeployment .LINK https://gitlab.com/yendico1/products/starburst/backend-workflow/ps-modules/starburst/-/blob/main/Starburst/Public/Remove-DuneDeployment.ps1 #> function Remove-DuneDeployment { [CmdletBinding( SupportsShouldProcess, ConfirmImpact = 'High', DefaultParameterSetName = 'Id' )] param ( [Parameter(Mandatory, ParameterSetName = "Name", Position = 0)] [string]$Name, [Parameter(Mandatory, ParameterSetName = "Id")] [guid]$Id, [Parameter(Mandatory, ParameterSetName = "Deployment", ValueFromPipeline)] [DuneDeployment]$Deployment, [Parameter()] [switch]$IncludeChildren, [Parameter()] [switch]$Unstage, [Parameter()] [switch]$Unlock ) begin { Write-Debug "$($MyInvocation.MyCommand)|begin" $Uri = "deployments" } process { Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)" switch ($PSCmdlet.ParameterSetName) { 'Name' { Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)|$($Name)" $Deployment = Get-DuneDeployment -Name $Name } 'Id' { Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)|$($Id)" $Deployment = Get-DuneDeployment -Id $Id } 'Deployment' { Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)|$($Deployment.Id)" } Default { return } } if ($PSCmdlet.ShouldProcess($Deployment.Name)) { If ($Unlock) { $Deployment | Unlock-DuneDeployment -Confirm:$false } If ($Unstage) { $Url = $("{0}/{1}/unstage" -f $Uri, $Deployment.Id) $Null = Invoke-DuneApiRequest $Url -Method POST } else { $Url = $("{0}/{1}" -f $Uri, $Deployment.Id) if ($IncludeChildren) { $Deployment | Get-DuneResourceGroup | Remove-DuneResourceGroup -IncludeChildren } $Null = Invoke-DuneApiRequest $Url -Method DELETE } } } end { Write-Debug "$($MyInvocation.MyCommand)|end" } } |