Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform doesn't add log group name on cloudwatch event target

I create a rule in Cloudwatch and attach a log group as its target in 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"
  }
}

You see the above configuration includes a log group resource definition and two event target, one for log group the other is for triggering a lambda. Below is the screenshot of this configuration in aws cloudwatch rule console.

enter image description here

You see the target in the bottom of the screenshot shows lambda correctly but it doesn't show the name of the log group I created. Instead, it shows a * for the log group name. I wonder what wrong with my configuration.

like image 400
Joey Yi Zhao Avatar asked Jan 19 '26 12:01

Joey Yi Zhao


1 Answers

After checking the value of the arn attribute of cloudwatch log group, for some reason it is appending an asterisk at the end in this format format arn:aws:logs:eu-west-1:12345678912:log-group:crawler_log:*
Change your code like this to remove the last 2 characters:

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)}"
}
like image 73
WalKh Avatar answered Jan 21 '26 06:01

WalKh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!