3

I have a terraform file that I'm reusing to create several AWS Eventbridge (as triggers for some lambdas). On a different part of the file I'm able to use For Each method to create several eventbridge and naming them accordingly. My problem is that I'm not being able to do the same thing inside EOF tag (that need to be different on each Eventbridge) since it takes everything as a string. I would need to replace the ARN in "prefix": "arn:aws:medialive:us-west-2:11111111111:channel:3434343" with a variable. How could I do that?

This is the EOF part of the terraform code:

      event_pattern = <<EOF
{
  "source": ["aws.medialive"],
  "detail-type": ["AWS API Call via CloudTrail"],
  "detail": {
    "eventSource": ["medialive.amazonaws.com"],
    "eventName": ["StopChannel"],
    "responseElements": {
      "arn": [{
        "prefix": "arn:aws:medialive:us-west-2:11111111111:channel:3434343"
      }]
    }
  }
}
EOF
}
Naxxio
  • 63
  • 1
  • 10

1 Answers1

8

It's called a Heredoc String, not an EOF tag. "EOF" just happens to be the string you are using to tag the beginning and ending of a multi-line string. You could use anything there that doesn't occurr in your actual multiline string. You could be replacing "EOF" with "MYMULTILINESTRING".

To place the value of a variable in a Heredoc String in Terraform, you do the exact same thing you would do with other strings in Terraform: You use String Interpolation.

      event_pattern = <<EOF
{
  "source": ["aws.medialive"],
  "detail-type": ["AWS API Call via CloudTrail"],
  "detail": {
    "eventSource": ["medialive.amazonaws.com"],
    "eventName": ["StopChannel"],
    "responseElements": {
      "arn": [{
        "prefix": "${var.my_arn_variable}"
      }]
    }
  }
}
EOF
}
Mark B
  • 183,023
  • 24
  • 297
  • 295