1
votes

I am trying to setup cloudwatch log filter using terrafom using below resource element (The logs are in the default format):

resource "aws_cloudwatch_log_metric_filter" "exception-filter" {
  name           = "Exception filter"
  pattern        = "Exception:"
  log_group_name = "/ecs/application/log"
  metric_transformation {
    name          = "Exceptions"
    namespace     = "app-custom"
    value         = "1"
    default_value = "0"
  }
}

The terraform apply command fails stating InvalidParameterException: Invalid metric filter pattern.

I tried to escape ":" using \ but doing do also I got an error that the symbol ":" is not a valid escape.

Is there any other way to specify the pattern here?

1

1 Answers

2
votes

If the pattern does contain other characters then than alphanumeric or underscore, then (froo docs) it must be placed inside double quotes ("") . :

So instead of:

  pattern        = "Exception:"

you should have

  pattern        = "\"Exception:\""