azure - 从 terraform Output 获取数据并将其用作输入

标签 azure terraform cloudflare terraform-provider-azure terraform-provider-cloudflare

我正在使用 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_statetfe_outputs将 Azure 输出传递到 Cloudflare。

关于azure - 从 terraform Output 获取数据并将其用作输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75629286/

相关文章:

azure - VNET 中的 Terraform AKS 此处不应出现名为 "user_assigned_identity_id"的参数

azure - 当逻辑应用中的 "Get Entities"没有结果时如何阻止下一步

python - 时间触发的 Azure 函数不会每分钟触发一次

terraform - 从具有多个子网的虚拟网络中选择特定的子网 ID

Terraform JSON 需要嵌套在 Azure Vnet 对象中的 Azure 子网才能拥有 ID,但不允许对其进行设置

amazon-web-services - 使用 AWS API Gateway 时出现 Cloudflare 521 错误

json - SuperObject - 使用 "."文字解析字段名中的数据

node.js - 迁移到 CloudFlare 后 Chrome 中的无效重定向错误

javascript - 具有认知语音功能的 Azure Bot 框架无法正常工作

azure - 在 NServiceBus 中接收 MessageDeserialization 异常