Terraform不会在cloudwatch事件目标上添加日志组名称

时间:2019-07-29 00:48:12

标签: amazon-web-services terraform amazon-cloudwatch

我在Cloudwatch中创建一条规则,并在log group中附加一个Terraform作为其目标。

resource "aws_cloudwatch_event_target" "trigger_glue_job_lambda" {
  rule = "${aws_cloudwatch_event_rule.crawler.name}"
  target_id = "SendToLambda"
  arn = "${aws_lambda_function.trigger_glue_job.arn}"
}

resource "aws_cloudwatch_event_target" "log_glue_crawler_result" {
  rule = "${aws_cloudwatch_event_rule.crawler.name}"
  target_id = "LogCrawler"
  arn = "${aws_cloudwatch_log_group.grue_crawler_log_group.arn}"
}

resource "aws_cloudwatch_log_group" "grue_crawler_log_group" {
  name = "crawler_log"
  tags = {
    Application = "reddit_movies"
  }
}

您会看到上面的配置包括一个log group资源定义和两个event target,一个用于日志组,另一个用于触发lambda。下面是AWS CloudWatch规则控制台中此配置的屏幕截图。

enter image description here

您看到屏幕截图底部的目标正确显示了lambda,但未显示我创建的日志组的名称。而是显示日志组名称的*。我想知道我的配置有什么问题。

1 个答案:

答案 0 :(得分:3)

检查cloudwatch日志组的in this tutorial属性的值后,由于某种原因,它在末尾以这种格式添加一个星号arn:aws:logs:eu-west-1:12345678912:log-group:crawler_log:*
像这样更改代码以删除最后两个字符:

resource "aws_cloudwatch_event_target" "log_glue_crawler_result" {
  rule = "${aws_cloudwatch_event_rule.crawler.name}"  
  target_id = "LogCrawler"
  arn = "${substr(aws_cloudwatch_log_group.grue_crawler_log_group.arn,0,length(aws_cloudwatch_log_group.grue_crawler_log_group.arn) - 2)}"
}