I need to be able to store the environmental variables from Terraform Output in powershell and I am wandering if anyone has an example of this please.. This is how far i have got. I am just not too sure whats the best way to do this :
$output = terraform output -json
$output
$json = Get-Content $output | Out-String | ConvertFrom-Json
foreach($prop in $json.psobject.properties) {
Write-Host("##vso[task.setvariable variable=$($prop.Name);]$($prop.Value.value)")
}
Many thanks to anyone who can help.
CodePudding user response:
This should assist you with what you want:
$TerraformPath = "C:\tf\terraform.exe"
$Json_Output = (& $TerraformPath output -json) | ConvertFrom-Json
Change $TerraformPath
to the location of your terraform.exe
, I thought it would be best to take this route as I am unsure if you have terrraform in your environmental path.
All properties should then be in $Json_Output
.