Terraform-provider-newrelic: NewRelic Provider 2.7.0 - newrelic_infra_alert_condition (Not working)

Created on 11 Sep 2020  路  12Comments  路  Source: newrelic/terraform-provider-newrelic

Hey Team,

I am having issues creating a newrelic_infra_alert_condition resource. I have managed to create the following:

  • newrelic_alert_policy
  • newrelic_alert_channel (Email)
  • newrelic_alert_channel (Pagerduty)
  • newrelic_alert_policy_channel x2

Even using the examples in the documentation I can not for the life of me get this to work. I have also looked at the specific resource attributes and still nothing.

Terraform Version

  • Terraform v0.13.2

    • provider registry.terraform.io/newrelic/newrelic v2.7.0

  • Go runtime version: go1.14.7

Affected Resource(s)

Please list the resources as a list, for example:

  • newrelic_infra_alert_condition

Terraform Configuration Files

```hcl main.tf

Configure the New Relic provider

provider "newrelic" {
}

Create an alert policy

resource "newrelic_alert_policy" "Austin_Aurora_Policy_UK" {
name = "Austin Alert Policies"
incident_preference = "PER_POLICY"
}

Add a notification channel

resource "newrelic_alert_channel" "email" {
name = "Martyn Langlands "
type = "email"

config {
recipients = "martyn.langlands@..."
include_json_attachment = "1"
}
}

PagerDuty Config for CitNow

resource "newrelic_alert_channel" "CitNow_Pager" {
name = "pagerduty-alert"
type = "pagerduty"

config {
service_key = "(need customer key)"
}
}

Link the channel to the policy

resource "newrelic_alert_policy_channel" "alert_email" {
policy_id = newrelic_alert_policy.Austin_Aurora_Policy_UK.id
channel_ids = [
newrelic_alert_channel.email.id
]
}

Link the channel to the policy

resource "newrelic_alert_policy_channel" "pager_duty" {
policy_id = newrelic_alert_policy.Austin_Aurora_Policy_UK.id
channel_ids = [
newrelic_alert_channel.CitNow_Pager.id
]
}

Generate High CPU Alert

resource "newrelic_infra_alert_condition" "high_cpu" {
policy_id = newrelic_alert_policy.Austin_Aurora_Policy_UK.id
name = "High CPU usage"
type = "infra_metric"
event = "SystemSample"
select = "cpuPercent"
comparison = "above"
where = "(applicationId = '%CitNOW%')"
critical {
duration = 300
value = 90
time_function = "all"
}
}

```

Debug Output

https://gist.github.com/martynlanglands/1d97fb9f8b5b1a7077413b14a80bab4a

Panic Output

n/a

Expected Behavior

An alert is created within NewRelic

Actual Behavior

401 error message

Steps to Reproduce

  1. terraform apply --auto-approve

Important Factoids

I have full admin on this account with the following exports

export TF_LOG="TRACE" export NEW_RELIC_API_KEY="NRAK-...." export NEW_RELIC_ADMIN_API_KEY="NRRA-...." export NEW_RELIC_REGION="EU" export NEW_RELIC_ACCOUNT_ID="...."

References

n/a

Most helpful comment

I've been able to test this out and it looks like the resources are working correctly for me. The 401 response here makes me think that the accountID might not match the account the credentials came from. The credentials you are using just need to have the access on the account for the resource you are managing.

Also worth noting is that in the future, the newrelic_alert_condition will be the only alerts available, so you may want to start moving your resources to that in place of the infra condition, but I don't think that's why the 401.

All 12 comments

I have also tried the following from PR: https://github.com/newrelic/terraform-provider-newrelic/pull/859/commits/6f7594531ba08a95f0dbbd8bd6d28030ae4a65c4
resource "newrelic_infra_alert_condition" "high_cpu" { policy_id = newrelic_alert_policy.Austin_Aurora_Policy_UK.id name = "High CPU usage" type = "infra_metric" event = "SystemSample" select = "cpuPercent" comparison = "above" where = "(applicationId = '%CitNOW%')" critical { duration = 300 value = 90 time_function = "all" } }

Thank you for the report. Can you tell me if you continue to see this issue on v2.7.1?

Thank you for the report. Can you tell me if you continue to see this issue on v2.7.1?

Thanks for getting back so promptly @zlesnr - I can confirm this is still an issue in v2.7.1

Screenshot 2020-09-11 at 19 53 37

I've been able to test this out and it looks like the resources are working correctly for me. The 401 response here makes me think that the accountID might not match the account the credentials came from. The credentials you are using just need to have the access on the account for the resource you are managing.

Also worth noting is that in the future, the newrelic_alert_condition will be the only alerts available, so you may want to start moving your resources to that in place of the infra condition, but I don't think that's why the 401.

I've been able to test this out and it looks like the resources are working correctly for me. The 401 response here makes me think that the accountID might not match the account the credentials came from. The credentials you are using just need to have the access on the account for the resource you are managing.

Also worth noting is that in the future, the newrelic_alert_condition will be the only alerts available, so you may want to start moving your resources to that in place of the infra condition, but I don't think that's why the 401.

I really appreciate you coming back to me on this so frequently!

Thanks for the heads up on the resource update! I wasn't aware of that!

The 401 on that screenshot is because I attempted to change the region within the EXPORT vars. I set it back to US now.
Screenshot 2020-09-11 at 22 15 21

The 403 is also likely related to the credentials having the appropriate access to the account in question. Are you working with multiple accounts? Can you confirm the user's credentials have access to manage these resources?

Hey @zlesnr - yes. I should have included that. I can create the resources directly with the REST API. Would it help if I gave you access to Terraform Cloud? Thanks again!

@zlesnr are you using the exported environment variables for running this or the provider variables?

Also I should note every other resource works fine. It's only when I add in the alert condition it throws the 403. My user account can do all this fine within the console. Have you ran that terraform I posted against a new relic account?

@zlesnr - I changed the alert as per your advice to newrelic_alert_condition and it now works and has been applied. Im happy for you to close this issue off.

Oh good, I'm glad you got it working.

We do recommend using environment variables. This is our most recent guidance on configuring the provider.

https://registry.terraform.io/providers/newrelic/newrelic/latest/docs/guides/provider_configuration

Let us know if anything else comes up.

Also worth noting is that in the future, the newrelic_alert_condition will be the only alerts available, so you may want to start moving your resources to that in place of the infra condition, but I don't think that's why the 401.

Is this documented somewhere? Bummer - have a lot of people using infra alert conditions. Will they just roll up under there and be an infra alert type now?

I'm not sure if that's documented somewhere, but I think I misspoke anyway. It's the NRQL alert conditions that will be the preferred method of configuring alerts. This is information from the Alerts team as part of their future plans.

Was this page helpful?
0 / 5 - 0 ratings