Public/Get-TerraformOutput.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
25
26
27
28
29
function Get-TerraformOutput {

    param (
        [Parameter(Mandatory=$false,Position=1)]
        [string]$Path,
        [Parameter(Mandatory=$false,Position=2)]
        [string]$OutputName
    )

    $Params = @{}

    if ($PSBoundParameters['Path']) {
        $Params['Path'] = $PSBoundParameters['Path']
    }

    # Set terraform arguments
    $Params['ArgumentList'] = @("output")

    if ($PSBoundParameters['OutputName']) {
        $Params['ArgumentList'] += $OutputName
     }
     
    Write-Verbose "Current location is [$(Get-Location)]"
    
    $Output = Invoke-Terraform @Params

    Write-Output $Output.Trim()

}