由于我要声明许多事件规则,因此我试图在云监视事件规则的模式部分中动态传递JSON数据。我看不到“变量”支持的文件格式,该格式可以将JSON数据传递给事件模式。我试图在terraform.tfvars.json列表中声明的JSON传递无效,文章底部提到了事件模式的JSON数据。请给我一个解决方案。
#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