Home > database >  How to create if statement in Terraform for LogicApps
How to create if statement in Terraform for LogicApps

Time:10-15

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

CodePudding user response:

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

  • Related