繁体   English   中英

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

[英]How to create if statement in Terraform for LogicApps

我正在使用 Terraform 创建 LogicApps。 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"
            }
    }

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM