我正在使用 Terraform 构建和自动化基础设施,但在寻找解决方案来获取 Azure WebApp 的输出(特别是该 WebApp 使用的公共(public) IP 地址)并将其用作更新 Cloudflare 的输入时遇到了困难列表。
output "webapp_ip" {
value = azurerm_linux_web_app.lwa.outbound_ip_addresses
}
将输出如下内容:
webapp_ip = "ip-address-1,ip-address-2,ip-address-3,ip-address-4"
Cloudflare_list terraform 资源接收以下格式的数据:
item {
value {
ip = "ip-address-1"
}
comment = "IP 1"}
item {
value {
ip = "ip-address-2"
}
comment = "IP 2"
}
我正在考虑动态列表,但我不知道这是否是正确的方法......
最佳答案
Dynamic blocks是去这里的正确方法。您的代码应如下所示:
resource "cloudflare_list" "example" {
// some other attributes
dynamic "item" {
for_each = toset(split(",", azurerm_linux_web_app.lwa.outbound_ip_addresses)) // notice split
content {
value {
ip = item.value
}
comment = "IP: ${item.value}"
}
}
}
如果 Azure 和 Cloudflare 位于两个不同的工作区(状态)中,您可以使用 terraform_remote_state或tfe_outputs将 Azure 输出传递到 Cloudflare。
关于azure - 从 terraform Output 获取数据并将其用作输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75629286/