Json data inside event pattern section of cloudwatch event rule

Hi Folks,

I am trying to pass a JSON data in the pattern section of cloud watch event rule dynamically since I have many event rules to be declared. I don’t see a supported file format in “variable” where I can pass a JSON data to the event pattern. I tried to pass with the help of JSON declared in the list in terraform.tfvars.json which didn’t work. The JSON data’s of event pattern are mentioned at the bottom of the post. Please give me a solution.

#Cloud watch event Rule
variable “resource_rule” {
description = “Cloud watch event rule patterns for config,iam and ec2”
default = [“config”, “iam”, “ec2”]

}

resource “aws_cloudwatch_event_rule” “event_rule” {
count = length(var.resource_rule)
name = “aws_${(var.resource_rule)[count.index]}_config_rule”

event_pattern = <<PATTERN
var.event_pattern_${(var.resource_rule)[count.index]} --> didn’t work
PATTERN
}

resource “aws_cloudwatch_event_target” “event_rule_target” {
count = length(var.resource_rule)
rule == “${aws_cloudwatch_event_rule.event_rule[count.index].name}”

target_id = “SendToSQS”
arn = “${aws_sqs_queue.cmdb_queue.arn}”
}

event pattern for config:
event_pattern = <<PATTERN
{
“source”: [
“aws.config”
],
“detail-type”: [
“AWS API Call via CloudTrail”
],
“detail”: {
“eventSource”: [
config.amazonaws.com
]
}
}
PATTERN

Event pattern for IAM:
event_pattern = <<PATTERN
{
“source”: [
“aws.iam”
],
“detail-type”: [
“AWS API Call via CloudTrail”
],
“detail”: {
“eventSource”: [
iam.amazonaws.com
]
}
}
PATTERN

event_pattern = <<PATTERN
{
“source”: [
“aws.ec2”
]
}
PATTERN