gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 02:19:40 26 4
gpt4 key购买 nike

我正在使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com