Last active
July 17, 2020 22:04
-
-
Save bruceharrison1984/d28416821be864e0f476c21616187d10 to your computer and use it in GitHub Desktop.
Get outputs from terraform.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[string]$workspaceName = $(throw "Please specify a workspace name"), | |
[string]$organizationName = $(throw "Please specify an organization name"), | |
[string]$terraformIoToken = $(throw "Please specify a terraform Io Token") | |
) | |
$ErrorActionPreference = "Stop" | |
$baseUri = "https://app.terraform.io/" | |
$authHeader = @{ Authorization = "Bearer $terraformIoToken" } | |
$contentType = "application/vnd.api+json; charset=utf-8" | |
Write-Host "Getting state information for $organizationName - $workspaceName" | |
$workspaceResp = Invoke-RestMethod -Uri "$baseUri/api/v2/organizations/$organizationName/workspaces/$workspaceName" -Headers $authHeader -ContentType $contentType | |
$currentStateVersionLink = $workspaceResp.data.relationships.'current-state-version'.links.related | |
Write-Host "Current state link: $currentStateVersionLink" | |
$uri = $baseUri + $currentStateVersionLink + "?include=outputs" | |
$outputResp = Invoke-RestMethod -Uri $uri -Headers $authHeader -ContentType $contentType | |
$outputs = @{}; | |
$outputResp.included | % attributes | % { $outputs."$($_.Name)" = $_.Value } | |
$outputs = $outputs.GetEnumerator() | sort -Property Name | |
$outputs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment