Home > Back-end >  Terraform error creating a pattern of a aws_cloudwatch_log_metric_filter
Terraform error creating a pattern of a aws_cloudwatch_log_metric_filter

Time:07-15

Im trying to create a metric filter like this:

resource "aws_cloudwatch_log_metric_filter" "name_resource" {
  name           = "MetricName"
  pattern        = "{($.errorCode="*UnauthorizedOperation") || ($.errorCode="AccessDenied*")}"
  log_group_name = var.log_group_cloudtrail_name


  metric_transformation {
    name          = "MetricName"
    namespace     = "MetricNameSpace"
    value         = "1"
    default_value = "0"
  }
}

However Im getting this error:

│ Error: Missing newline after argument
│
│   on metric_filter.tf line 3, in resource "aws_cloudwatch_log_metric_filter" "name_resource":
│    3:   pattern        = "{($.errorCode="*UnauthorizedOperation") || ($.errorCode="AccessDenied*")}"
│
│ An argument definition must end with a newline.

I think that the problem is the quotes, but if I try to use single quotes, I get another error because they are not available.

How can I deal with this problem?

CodePudding user response:

You have to escape the quotes:

pattern        = "{($.errorCode=\"*UnauthorizedOperation\") || ($.errorCode=\"AccessDenied*\")}"
  • Related