terraform-provider-newrelic
terraform-provider-newrelic copied to clipboard
newrelic_nrql_drop_rule not getting created via terraform
Hello Team,
I'm having an issue in where i'm unable to create a newrelic drop rule via terraform. Initially i was working to create a module which takes in a list of objects; where each object is a drop filter rule (contains description , action, account id, and query), and simple creates and applies the drop rule. I created a simple drop rule resource and removed my module code (to eliminate issues), However on the apply is where i'am getting an error. The error is reporting the drop rule is not getting returned and to validate the action value or NRQL. The NRQL is validd, and action type is also valid. We attempted to use charles to debug http traffic, and we can even see the nerdgraph result of success. It looks like there appears to be a bug.
Error
[31m╷[0m[0m [31m│[0m [0m[1m[31mError: [0m[0m[1merr: drop rule create result wasn't returned. Validate the action value or NRQL query.[0m [31m│[0m [0m [31m│[0m [0m[0m with module.newrelic-drop-rule.newrelic_nrql_drop_rule.drop_filter_rule["0"], [31m│[0m [0m on newrelic-drop-rule/1_nr_drop_rule.tf line 3, in resource "newrelic_nrql_drop_rule" "drop_filter_rule": [31m│[0m [0m 3: resource "newrelic_nrql_drop_rule" "drop_filter_rule" [4m{[0m[0m [31m│[0m [0m [31m╵[0m[0m
Provider config
`terraform {
required_version = ">= 0.15.0"
required_providers { google-beta = ">= 3.66.1" graphql = { source = "sullivtr/graphql" version = "2.0.0-rc" } newrelic = { source = "newrelic/newrelic" version = ">= 2.49.1" } } } `
source code ` resource "newrelic_nrql_drop_rule" "drop_filter_rule" { description = "dropping value not found logs" action = "drop_data" nrql = "SELECT * FROM Log, LogExtendedRecord WHERE message LIKE '%value not found%' AND newrelic.logs.customEventType IS NULL" }
`
Terraform Version
Run terraform -v
to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed.
Affected Resource(s)
Please list the resources as a list, for example:
-
newrelic_alert_policy
-
newrelic_alert_channel
If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.
Actual Behavior
No drop rule resource getting created
Expected Behavior
drop rule resource should e getting created
Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
-
terraform apply
Thanks @aravind-bigfish We'll see if we can reproduce the issue.
Thank you, I'm using terraform version 1.0.0 and above so even with latest version its failing
Hi @aravind-bigfish ,
Able to recreate the issue by using the following script.
resource "newrelic_nrql_drop_rule" "foo" {
account_id = xxxxxxxxxxx
description = "Drops all data for MyCustomEvent that comes from the LoadGeneratingApp in the dev environment, because there is too much and we don’t look at it."
action = "drop_data"
nrql = "SELECT * FROM Log, Log_123, LogExtendedRecord WHERE (`timestamp` = xxxxxxxxxxx OR `timestamp` = ‘xxxxxxxxxxx’) AND (newrelic.logs.customEventType IS NULL OR newrelic.logs.customEventType IN (‘Log’))"
}
we will provide update once fix is available.
Hi there! We are currently running onto this issue as well. When the fix is allocated, will it be backported to 2.x? I know 3.x was released a few days ago but we've had no time to migrate our synthetic checks to account for the breaking change. Thanks.
Hi @aravind-bigfish & @danielgblanco, This error seems to be problem with the query, Please enter a valid query and try again. Drop rule
Thanks @shiva-bandari, are there any docs on any limitations that perhaps we're not aware on NRQL used in drop rules?
The following queries:
FROM Log SELECT * WHERE service.name = 'my-service' AND message RLIKE '.*(eyJ[A-Za-z0-9-_=]+\\.[A-Za-z0-9-_=]+\\.?[A-Za-z0-9-_.+=]*).*'
And
FROM Log SELECT * WHERE service.name = 'my-service' AND message RLIKE '.*([a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}).*'
Seems to work in the NRQL console, but not in drop rules. We hit the problem mentioned above when trying to create those rules.
Also, probably worth pointing out that the query that @aravind-bigfish had in the original post:
SELECT * FROM Log, LogExtendedRecord WHERE message LIKE '%value not found%' AND newrelic.logs.customEventType IS NULL
Seems like a pretty standard query. Cannot see anything that could be unsupported there.
@danielgblanco Can you try adding a r
in front of the query, this is required for RLIKE: https://docs.newrelic.com/docs/query-your-data/nrql-new-relic-query-language/get-started/nrql-syntax-clauses-functions/
example: FROM Log SELECT * WHERE service.name = 'my-service' AND message RLIKE r'.*([a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}).*'
After adding 'r' in front of the query, our problem was resolved. However, the same query is not working with query builder and does not return any result. We removed 'r' to test it with the query builder. Thanks for the help!
As @SelinErkan said, this worked, thanks! Perhaps something to follow up on separately because the NRQL console did not seem to like the query with r
. Possibly nothing relate to the Terraform provider though.
Never mind, found the original issue. The query above
FROM Log SELECT * WHERE service.name = 'my-service' AND message RLIKE r'.*([a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}).*'
Would not work in the NRQL console (it would not match anything). But if we remove the double backslash it would.
FROM Log SELECT * WHERE service.name = 'my-service' AND message RLIKE r'.*([a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}).*'
There may be some escaping/unescaping that happens when applying Terraform values that is affecting this so the behaviour is not the same between NRQL console and Terraform provider.
Hi @aravind-bigfish & @danielgblanco, This error seems to be problem with the query, Please enter a valid query and try again. Drop rule
@shiva-bandari I am a colleague of @aravind-bigfish - I cannot find anything unsupported in this query, similar to what @danielgblanco said. What exactly is wrong with this query?
Hey @bfgkory
I don't see any issue with the actual query being used here. However the Provider and Resource configs are different and naturally there will be a main.tf that allows for the variability of the module architecture that @aravind-bigfish mentioned in his original post.
I was able to implement the below without any issue, and this was to my personal account which doesn't have any logs that match this variable (just ruling out any issues with requiring some kind of validation, which would be nonsensical).
Let's chat about this on Slack, however I had this issue re-opened because I didn't like how it was closed without a resolution for yourself and others.
terraform {
# Require Terraform version 1.0 (recommended)
required_version = "~> 1.3.1"
# Require the latest 2.x version of the New Relic provider
required_providers {
newrelic = {
source = "newrelic/newrelic"
}
}
}
provider "newrelic" {
version = "~> 3.3.0"
account_id = XXXXXX
api_key = "XXXXXXXXXXXXXXXXXXXXXXXXXX"
region = "US" # Valid regions are US and EU
}
resource "newrelic_nrql_drop_rule" "test" {
account_id = 1044047
description = "Descri[tion Example]"
action = "drop_data"
nrql = "SELECT * FROM Log, LogExtendedRecord WHERE message LIKE '%value not found%' AND newrelic.logs.customEventType IS NULL"
}
```
@NSSPKrishna , could you please take a look and validate
Hey, is the issue is still valid? I don't think the issue is from the terraform side.
We haven’t heard back from you in a long time so we will close the ticket. If you feel this is still a valid request or bug, feel free to create a new issue.