Hey Team,
I am having issues creating a newrelic_infra_alert_condition resource. I have managed to create the following:
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.
Please list the resources as a list, for example:
```hcl main.tf
provider "newrelic" {
}
resource "newrelic_alert_policy" "Austin_Aurora_Policy_UK" {
name = "Austin Alert Policies"
incident_preference = "PER_POLICY"
}
resource "newrelic_alert_channel" "email" {
name = "Martyn Langlands "
type = "email"
config {
recipients = "martyn.langlands@..."
include_json_attachment = "1"
}
}
resource "newrelic_alert_channel" "CitNow_Pager" {
name = "pagerduty-alert"
type = "pagerduty"
config {
service_key = "(need customer key)"
}
}
resource "newrelic_alert_policy_channel" "alert_email" {
policy_id = newrelic_alert_policy.Austin_Aurora_Policy_UK.id
channel_ids = [
newrelic_alert_channel.email.id
]
}
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
]
}
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"
}
}
```
https://gist.github.com/martynlanglands/1d97fb9f8b5b1a7077413b14a80bab4a
n/a
An alert is created within NewRelic
401 error message
terraform apply --auto-approveI 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="...."
n/a
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

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
401response 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_conditionwill 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.

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_conditionwill 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.
Most helpful comment
I've been able to test this out and it looks like the resources are working correctly for me. The
401response 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_conditionwill 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.