简体   繁体   中英

How to create if statement in Terraform for LogicApps

I'm creating LogicApps with Terraform. Logic Apps will do webhook and I would like to post text.

I would like to customize text field of Terraform code with If statement. I would like to certain part of text to be displayed at only prod environment. However my terraform code with pass entire if statement to LogicApps and I get payload error with LogicApps execution.

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"
            }
    }

You can use conditions in your BODY as follows:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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