Terraform alert configuration "Invalid escape sequence"

Hey guys,
I am trying to create conditions containing RLIKE for filtering matching logs via terraform,
provider version v3.6.1
The configuration fails stating Invalid escape sequence
I am unsure of how to add/change these configurations as I am copying them configuration from the UI under create condition-> view in code-> Terraform-> view

Note: The condition is working fine when I try to create via UI.

Terraform Config:

resource "newrelic_alert_policy" "linuxbaseline" {
  account_id = var.new_relic_account_id
  name = "Linux Baseline Policy"
}
resource "newrelic_nrql_alert_condition" "condition1" {
  account_id = var.new_relic_account_id
  policy_id = newrelic_alert_policy.linuxbaseline.id
  type = "static"
  name = "Test-link-down (logmon)"
  enabled = true
  violation_time_limit_seconds = 259200

  nrql {
    query = "SELECT count(message) FROM Log where message RLIKE r'^(\w+\s+\w+\s+[\w,:]+)(.*)kernel:(.*):(.*)Test\sLink\sis\sDown' FACET hostname"
  }
  critical {
    operator = "above_or_equals"
    threshold = 1
    threshold_duration = 300
    threshold_occurrences = "at_least_once"
  }
  fill_option = "none"
  aggregation_window = 60
  aggregation_method = "event_flow"
  aggregation_delay = 120
}

Error

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.
β•·
β”‚ Error: Invalid escape sequence
β”‚ 
β”‚ On linux_baseline_policies.tf line 14: The symbol "w" is not a valid escape
β”‚ sequence selector.
β•΅

β•·
β”‚ Error: Invalid escape sequence
β”‚ 
β”‚ On linux_baseline_policies.tf line 14: The symbol "s" is not a valid escape
β”‚ sequence selector.
β•΅

β•·
β”‚ Error: Invalid escape sequence
β”‚ 
β”‚ On linux_baseline_policies.tf line 14: The symbol "w" is not a valid escape
β”‚ sequence selector.
β•΅

β•·
β”‚ Error: Invalid escape sequence
β”‚ 
β”‚ On linux_baseline_policies.tf line 14: The symbol "s" is not a valid escape
β”‚ sequence selector.
β•΅

β•·
β”‚ Error: Invalid escape sequence
β”‚ 
β”‚ On linux_baseline_policies.tf line 14: The symbol "w" is not a valid escape
β”‚ sequence selector.
β•΅

β•·
β”‚ Error: Invalid escape sequence
β”‚ 
β”‚ On linux_baseline_policies.tf line 14: The symbol "s" is not a valid escape
β”‚ sequence selector.
β•΅

β•·
β”‚ Error: Invalid escape sequence
β”‚ 
β”‚ On linux_baseline_policies.tf line 14: The symbol "s" is not a valid escape
β”‚ sequence selector.
β•΅

β•·
β”‚ Error: Invalid escape sequence
β”‚ 
β”‚ On linux_baseline_policies.tf line 14: The symbol "s" is not a valid escape
β”‚ sequence selector.
β•΅

I have got the solution, just needed to add an extra \ to escape the already present \.
Suggesstion: I think this should come up in newrelic GUI while copying the configuration.

3 Likes

Hi @Sanjeet.Shekhar1

Thanks for reaching out, I hope you are well.

Congrats on your first post in the community, Whoop!, and you even shared your fix.

I have selected your last reply as the β€œSolution” as to indicate that the response resolved your noted challenge. This will help other customers facing similar issues.

@Sanjeet.Shekhar1

Thanks for bringing this to my attention. I’m working on a fix for our Terraform generator. You can track the progress here.

https://issues.newrelic.com/browse/NEWRELIC-5384

I really appreciate feedback like this. If you have any other ideas of how this tool can be improved, please let me know.