Public/Start-DuneComputeNode.ps1

<#
.SYNOPSIS
Start a compute node (resource).

.DESCRIPTION
Requests the Dune API to start a compute node resource. Identify the resource by `Id` or pass a `DuneResource` object via pipeline. An optional transaction id (`TxId`) can be supplied.

.PARAMETER Id
The GUID of the resource to start. Use the `Id` parameter set.

.PARAMETER Resource
A `DuneResource` object; pipeline input supported to identify the resource to start.

.PARAMETER TxId
Optional transaction id passed to the API. Defaults to the `SB_TXID` environment variable when not specified.

.EXAMPLE
PS> Start-DuneComputeNode -Id 3d8f6b5a-...
Starts the compute node with the given id.

.EXAMPLE
PS> Get-DuneResource -Name "webvm" | Start-DuneComputeNode
Pipeline example using the `Resource` parameter set.
#>

function Start-DuneComputeNode {
    [CmdletBinding(DefaultParameterSetName = "Id")]
    param (
        [Parameter(ParameterSetName = "Id")]
        [guid]$Id,

        [Parameter(Mandatory, ParameterSetName = "Resource", ValueFromPipeline)]
        [DuneResource]$Resource,

        [Parameter()]
        [String]$TxId = $env:SB_TXID
    )

    begin {}

    process {
        Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)"
        if ($PSCmdlet.ParameterSetName -eq "Resource") {
            $Id = $Resource.Id
        }
        $Body = @{TxId = $TxId}
        $Null = Invoke-DuneApiRequest -Uri "resources/$($Id)/start" -Method POST -Body $Body
    }

    end {}
}