azure - 如何在 Terraform for LogicApps 中创建 if 语句

标签 azure terraform azure-logic-apps

我正在使用 Terraform 创建 LogicApps。逻辑应用程序将执行 Webhook,我想发布文本。

我想使用 If 语句自定义 Terraform 代码的文本字段。 我希望文本的某些部分仅在产品环境中显示。 但是,我的 terraform 代码将整个 if 语句传递给 LogicApps,并且在 LogicApps 执行时出现有效负载错误。

resource "azurerm_logic_app_action_http" "example" {
  name         = "webhook"
  logic_app_id = azurerm_logic_app_workflow.example.id
  method       = "GET"
  uri          = "http://example.com/some-webhook"
  method       = "POST"
  headers      = { "Content-Type" = "application/json" }
  body = <<-BODY
    {
        "blocks": [
            {
                "text": {
                "text": "[${var.environment_name}] == "prod" ? *This is prod alert* : *---*",
                "type": "mrkdwn"
            }
    }

最佳答案

您可以在 BODY 中使用条件,如下所示:

  body = <<-BODY
    {
        "blocks": [
            {
              "text": {
                "text": "Alert: ${var.environment_name == "prod" ? "*This is prod alert*" : "*---*"}",
                "type": "mrkdwn"
            }
    }
    BODY

关于azure - 如何在 Terraform for LogicApps 中创建 if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69568501/

相关文章:

kubernetes - 是否可以使用kubernetes_config_map资源--from-file ConfigMap?

terraform - 插件。(*GRPCProvider)

azure - 使用 Azure 逻辑应用程序的 SQL 连接器我想获取插入的行 ID

azure - 调用 API 管理 API 时为逻辑应用创建触发器的方法

azure - 无法在 azure 通知中心上传 '.p12' 证书

java - 在 Azure API 应用服务上部署 JAX-RS Java API Webapp

azure 的 Blob ,它们有什么用?

node.js - 使用多方流调整图像大小

azure - Azure 上的 Terraform 公共(public) IP 输出

ssis - 使用 API 的 ETL/数据仓库方法