ExportedFunctions/Remove-PulumiStack.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function Remove-PulumiStack {
    [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(ValueFromPipeline=$true)]
        $Stack,

        [switch]$Force,

        $Pulumi = $Global:DefaultPulumi
    )
    process {
        if($Stack) {
            $StackName = $Stack.Name
            $ProjectName = $Stack.RoutingProject
        }
        $url = "/api/stacks/$($Pulumi.Org)/$ProjectName/$StackName"
        if($PSCmdlet.ShouldProcess("$($Pulumi.Org)/$ProjectName/$StackName", "Delete Stack")) {
            if($Force) {
                $Url = "${Url}?force=true"
            }
            Invoke-PulumiApi -Method DELETE -Url $Url -Pulumi $Pulumi
        }
    }
}