I'm trying to create a new relic alert condition using Terraform that looks at a certain metric, tunnel Data Out, for the last 24 hours, and alerts us if the the threshold is bigger than 50GB.
This works fine in the UI query builder:
SELECT provider.tunnelDataOut.Sum FROM PrivateNetworkSample WHERE provider = 'VpcVpnTunnel' AND vpnId = 'vpn-xxx' SINCE 1 day ago
But when applying through Terraform, it tells me I cannot use [SINCE] with nrql. So, I tried replacing [SINCE] with aggregation_window:
resource "newrelic_nrql_alert_condition" "vpn_outbound_data" {
(...)
aggregation_window = 86400 # 1 day
nrql {
query = "SELECT provider.tunnelDataOut.Sum FROM PrivateNetworkSample WHERE provider = 'VpcVpnTunnel' AND vpnId = '${aws_vpn_connection.aws_azure.id}'"
}
critical {
operator = "above"
threshold = 53687091200 # 50GB in bytes
threshold_duration = 60
threshold_occurrences = "all"
}
}
But then I get:
│ Error: Validation Error: BAD_USER_INPUT
│
│ with newrelic_nrql_alert_condition.vpn_outbound_data,
│ on nr_vpn.tf line 23, in resource "newrelic_nrql_alert_condition" "vpn_outbound_data":
│ 23: resource "newrelic_nrql_alert_condition" "vpn_outbound_data" {
│
│ terms[].thresholdDuration: Term duration must be a multiple of the
│ aggregation window (86400 seconds) but was 60 seconds
╵
╷
│ Error: Validation Error: BAD_USER_INPUT
│
│ with newrelic_nrql_alert_condition.vpn_outbound_data,
│ on nr_vpn.tf line 23, in resource "newrelic_nrql_alert_condition" "vpn_outbound_data":
│ 23: resource "newrelic_nrql_alert_condition" "vpn_outbound_data" {
│
│ signal.aggregationWindow: Aggregation window must be in range 30 - 21600
│ seconds but was 86400 seconds
Any suggestions on how to make this work?
you cannot set aggregation windows for 86400 seconds or 1 day. The max you can set is 6 hours or 21600 seconds that's the reason you are getting the validation error. You can try to create your condition in New relic UI and then view it as terraform code. Once you are done creating your condition, on the bottom right you will get an option "view as code" click on that and select terraform