【问题标题】:How to create if statement in Terraform for LogicApps如何在 Terraform for Logic Apps 中创建 if 语句
【发布时间】:2021-10-14 09:43:59
【问题描述】:

我正在使用 Terraform 创建 LogicApp。 Logic Apps 将执行 webhook,我想发布文本。

我想用 If 语句自定义 Terraform 代码的文本字段。 我希望仅在 prod 环境中显示某些文本部分。 但是,我的 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"
            }
    }

【问题讨论】:

    标签: azure terraform azure-logic-apps


    【解决方案1】:

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

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

    【讨论】:

    • 如何在if语句前添加提示文字?建议:“文本”:“警报:” + ${var.environment_name == “产品”? "这是产品警报" : "---"},
    • @Kenny_I 我更新了答案。
    猜你喜欢
    • 2019-08-28
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 2021-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多