用于在 PowerShell 中设置变量的 Terraform 输出
Terraform Output to set variables in PowerShell
我需要能够将来自 Terraform 输出的环境变量存储在 powershell 中,如果有人有这方面的示例,我正在徘徊......
这就是我的进展。我只是不太确定最好的方法是什么:
$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)")
}
非常感谢任何能提供帮助的人。
这应该可以帮到您:
$TerraformPath = "C:\tf\terraform.exe"
$Json_Output = (& $TerraformPath output -json) | ConvertFrom-Json
将 $TerraformPath
更改为您 terraform.exe
的位置,我认为最好走这条路线,因为我不确定您的环境路径中是否有 terrraform。
所有属性都应该在 $Json_Output
.
我需要能够将来自 Terraform 输出的环境变量存储在 powershell 中,如果有人有这方面的示例,我正在徘徊...... 这就是我的进展。我只是不太确定最好的方法是什么:
$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)")
}
非常感谢任何能提供帮助的人。
这应该可以帮到您:
$TerraformPath = "C:\tf\terraform.exe"
$Json_Output = (& $TerraformPath output -json) | ConvertFrom-Json
将 $TerraformPath
更改为您 terraform.exe
的位置,我认为最好走这条路线,因为我不确定您的环境路径中是否有 terrraform。
所有属性都应该在 $Json_Output
.