如何在 Terraform 中为 LogicApps 创建 if 语句

How to create if statement in Terraform for LogicApps

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

我想用 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