ExportedFunctions/Invoke-PulumiApi.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function Invoke-PulumiApi {
    param(
        [Parameter(Mandatory=$true)]
        $Url,

        [ValidateSet("GET","DELETE")]
        $Method = "GET",

        [ValidateNotNullOrEmpty()]
        $Pulumi = $Global:DefaultPulumi
    )
    $Headers = @{
        Authorization = "token $($Pulumi.Token)"
        "Accept"="application/vnd.pulumi+3"
    }
    $RequestUrl = "$($Pulumi.PulumiUrl)$Url"
    Write-Debug $RequestUrl
    Invoke-RestMethod -Method $Method -Uri $RequestUrl -ContentType "application/json" -Headers $Headers | ForEach-Object {$_}
}