将输出从terraform传递到Azure后端存储中具有状态文件的Azure Devops Pipeline [英] pass output from terraform to Azure Devops Pipeline with state file in azure backend store
问题描述
我似乎无法检索Terraform的公共IP地址输出,以进行AzureDevops中构建管道的下一步.
I cannot seem to retrieve the public ip address output of Terraform for next step in build pipeline in AzureDevops.
地形状态提取有效,并输出到json文件,不能在输出中进行grep.
Terraform state pull works and outputs to json file, cannot grep on output.
Terraform状态显示[选项] ADDRESS不支持Azure后端,因此无法使用或grep或过滤输出
Terraform state show [options] ADDRESS does not support azure backend so cannot use or grep or filter the output
还尝试将其存储为文件并读取该值.
also tried to store as file and read in the value.
resource "local_file" "foo" {
content = "foo!"
filename = "${path.module}/foo.bar"
}
data "azurerm_public_ip" "buildserver-pip" {
name = "${azurerm_public_ip.buildserver-pip.name}"
resource_group_name = "${azurerm_virtual_machine.buildserver.resource_group_name}"
}
output "public_ip_address" {
value = "${data.azurerm_public_ip.buildserver-pip.ip_address}"
}
期望将要传递的公共IP地址,以便可以在下一步的ansible剧本,bash或python脚本中使用
expect the public ip address to be passed out so can be used in ansible playbooks, bash or python script in next step
推荐答案
基于上述解决方案的@JleruOHeP答案,将为terraform
脚本提供的每个输出自动创建一个变量
Building on @JleruOHeP answer above the following solution will automatically create a variable for every output provided by the terraform
script
- 在您的发行版中创建一个PowerShell步骤,并插入以下嵌入式PowerShell:
$json = Get-Content $env:jsonPath | Out-String | ConvertFrom-Json
foreach($prop in $json.psobject.properties) {
Write-Host("##vso[task.setvariable variable=$($prop.Name);]$($prop.Value.value)")
}
- 确保像这样提供了环境变量
jsonPath
:
这篇关于将输出从terraform传递到Azure后端存储中具有状态文件的Azure Devops Pipeline的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!