"Validation Error" when trying to run `terraform apply`

I have the following resources that I'm trying to create:

resource "newrelic_alert_policy" "rpm_production_alert_policy" { name = "RPM (Production) Alert Policy (Terraform)" incident_preference = "PER_CONDITION" } resource "newrelic_alert_channel" "rpm_production_slack" { name = "RPM Production Slack (Terraform)" type = "slack" config { channel = "rpm-terrarelic" url = "URLGOESHERE (obfuscated)" } } resource "newrelic_alert_policy_channel" "rpm_production_alert_policy_slack" { policy_id = newrelic_alert_policy.rpm_production_alert_policy.id channel_ids = [ newrelic_alert_channel.rpm_production_slack.id ] } resource "newrelic_nrql_alert_condition" "median_duration" { policy_id = newrelic_alert_policy.rpm_production_alert_policy.id name = "median_duration" description = "Alert when transactions are taking too long (this is a test description)" nrql { query = "SELECT median(duration) from Transaction where team = 'rpm' facet name since 1 month ago limit 500" evaluation_offset = 3 } critical { operator = "above" threshold = 2 threshold_duration = 60 threshold_occurrences = "AT_LEAST_ONCE" } violation_time_limit_seconds = 3600 value_function = "single_value" } 

When I comment out the newrelic_nrql_alert_condition resource and run terraform apply with my New Relic API key and -var-file flag, the resources are successfully created. But when I un-comment the newrelic_nrql_alert_condition resource and re-run the command, I get the following error:

newrelic_nrql_alert_condition.median_duration: Creating... ╷ │ Error: Validation Error │ │ with newrelic_nrql_alert_condition.median_duration, │ on foobar.tf line 22, in resource "newrelic_nrql_alert_condition" "median_duration": │ 22: resource "newrelic_nrql_alert_condition" "median_duration" { │ ╵ 

The { in the last line (22: resource "newrelic_nrql_alert_condition" "median_duration" {) was underlined, implying that this is where the validation error lies, but I don't see any deviation between this resource statement and an identical one with different values for certain keywords such as nrql.query, therefore the error message doesn't appear to be terribly helpful on its face.

I tried different values for the name param of the resource, thinking there might be a uniqueness constraint on alert conditions in New Relic, but that didn't work.

I tried moving the problematic resource block to the top of the file, in case the error was a red herring for a syntax problem earlier in the file, but I then saw the same error message but with a reference to line 1 instead of line 22. This tells me the problem really is with this resource block, and the error is not a red herring.

I Googled around for docs which would explain the different types of validation errors, but I wasn't able to find any.

Can anyone see what I'm doing wrong here?

EDIT:

When I run terraform validate for this module, I get the message Success! The configuration is valid..

1

1 Answer

While researching current and closed issues in the New Relic Terraform Provider GitHub page, I found that the TF_LOG flag can be passed for more granular logging. After passing this flag and discovering that the logging details at version 2.21.0 were insufficient, I discovered that version 2.29.0 of the gem has more granular log details. I upgraded and passed the flag again, and discovered that the NRQL queries passed to an alert condition must not contain LIMIT clauses. I removed the one I had included, and re-ran terraform apply, and it worked fine.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like