Hi,
Terrafrom Version: 0.11.14.7
Plugin Version: 2.1.1
resource "newrelic_alert_policy" "slack" {
name = "${var.application_name} Policy"
}
resource "newrelic_alert_channel" "slack" {
name = "${var.application_name} Channel"
type = "slack"
config = {
url = "${var.slack_channel_url}"
}
}
resource "newrelic_alert_policy_channel" "slack" {
policy_id = "${newrelic_alert_policy.slack.id}"
channel_ids = ["${newrelic_alert_channel.slack.id}"]
}
newrelic_alert_channel.slack: Creating...
config.#: "" => "1"
config.0.url: "<sensitive>" => "<sensitive>"
name: "" => "Team Channel"
type: "" => "slack"
newrelic_alert_channel.slack: Creation complete after 0s (ID: <channel-id>)
newrelic_alert_policy_channel.slack: Creating...
channel_ids.#: "" => "1"
channel_ids.0: "" => "<channel-id>"
policy_id: "" => "<policy-id>"
Error: Error applying plan:
1 error occurred:
* newrelic_alert_policy_channel.slack: 1 error occurred:
* newrelic_alert_policy_channel.slack: 422 response returned: There was an error. Unable to add channel IDs: [<channel-id>].
The channel id should have been associated to the policy.
The channel id failed to be associated correctly resulting in a 422 response code from New Relic.
terraform applyThe slack channel is an existing channel and is maintained in our Terraform state. It is being recreated every time due to what appears to be GH-763. The response from New Relic however is consistently a 422.
Hi, thank you for raising the issue. I'm unable to reproduce this on the latest master build. Using the following manifest, I get the behavior described in #763.
resource "newrelic_alert_policy" "z" {
incident_preference = "PER_CONDITION"
name = "Zach is Testing"
}
resource "newrelic_alert_channel" "slack" {
name = "slack-example"
type = "slack"
config {
url = "https://<YourOrganization>.slack.com"
channel = "example-alerts-channel"
}
}
resource "newrelic_alert_policy_channel" "slack" {
policy_id = newrelic_alert_policy.z.id
channel_ids = ["${newrelic_alert_channel.slack.id}"]
}
Hi @zlesnr thanks for your update. Unfortunately the only difference between my code and yours is there is no "channel" in the config section for slack. I have tried using the channel and still it complains about a 422 response status. I have updated to use the latest version of the provider and I am still getting these errors. Do you have any thoughts on where I might be able to investigate further?
Hmm, that's strange. Do any of those variables have special characters in them maybe? I'd like to see trace logging for that request, but you'll want to scrub the credentials out of it until https://github.com/newrelic/newrelic-client-go/pull/424 is worked through. Or if you have a way to proxy the connection and grab the body and response, I could take that to the alerts team. Almost certainly it's just some strange combination of attributes or something that is getting in the way, but I'm not seeing it in what you've posted so far unless its perhaps special characters in the variable contents. In the mean time, I'll see if there is a particular circumstance the alerts team knows about when a 422 would be thrown.
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs.
This issue has been automatically closed due to a lack of activity for an extended period of time.
Just set up a new alert for the first time for a new team and I'm getting this too. I'm using Pulumi but it's Terraform-by-proxy:
Diagnostics:
newrelic:index:AlertPolicyChannel (wwwMarketingTest-ap-channel-newrelic-marketing WWW Test Policy):
error: 422 response returned: There was an error. Unable to add channel IDs: [4451817].
The channel ID is my email address which I created manually in the console and I can verify both its existence and the channel ID is correct. The code does a lookup of the channel based on name and then passes the ID into the constructor for the AlertPolicyChannel object.
I am also getting this problem. Consistent 422 error. The channel seems to create just fine but does not show up in the NewRelic UI. I can even re-import the channel back into my tfstate file so it does seem to be there. But when I try to assign to an alert policy it fails every time.
Support?
We are also facing this problem while adding email alert channels to certain policies.
The notification channel ID given in the error message refers to the notification channel in our test account even though we are fully in production.
We have double check the tfstate file and even deleted the same to make sure everything is being created from scratch.
best
mathias
@suki-chima-ck and @mathias-burkl could you provide additional details on your configuration so we can troubleshoot? The TF configuration file and debug output is super useful to see.
As requested I created a bug report with more info last week:
On Tue, Feb 16, 2021 at 5:53 PM John P Vajda notifications@github.com
wrote:
@suki-chima-ck https://github.com/suki-chima-ck and @mathias-burkl
https://github.com/mathias-burkl could you provide additional details
on your configuration so we can troubleshoot? The TF configuration file
and debug output is super useful to see.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/newrelic/terraform-provider-newrelic/issues/840#issuecomment-780170054,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AOIQT73D6BVL2CJD3RBKTVDS7LZQJANCNFSM4P3VRU5Q
.
--
Suki Chima | Senior Mobile Software Engineer II | *Credit Karma*
suki.[email protected] | www.creditkarma.com
This email may contain confidential and privileged information. Any review,
use, distribution, or disclosure by anyone other than the intended
recipient(s) is prohibited. If you are not the intended recipient, please
contact the sender by reply email and delete all copies of this message.
As requested I created a bug report with more info last week:
https://github.com/newrelic/terraform-provider-newrelic/issues/1197
On Tue, Feb 16, 2021 at 6:27 PM Suki Chima suki.chima@creditkarma.com
wrote:
As requested I created a bug report with more info last week:
On Tue, Feb 16, 2021 at 5:53 PM John P Vajda notifications@github.com
wrote:@suki-chima-ck https://github.com/suki-chima-ck and @mathias-burkl
https://github.com/mathias-burkl could you provide additional details
on your configuration so we can troubleshoot? The TF configuration file
and debug output is super useful to see.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/newrelic/terraform-provider-newrelic/issues/840#issuecomment-780170054,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AOIQT73D6BVL2CJD3RBKTVDS7LZQJANCNFSM4P3VRU5Q
.--
Suki Chima | Senior Mobile Software Engineer II | *Credit Karma*
suki.[email protected] | www.creditkarma.comThis email may contain confidential and privileged information. Any
review, use, distribution, or disclosure by anyone other than the
intended recipient(s) is prohibited. If you are not the intended recipient,
please contact the sender by reply email and delete all copies of this
message.
--
Suki Chima | Senior Mobile Software Engineer II | *Credit Karma*
suki.[email protected] | www.creditkarma.com
This email may contain confidential and privileged information. Any review,
use, distribution, or disclosure by anyone other than the intended
recipient(s) is prohibited. If you are not the intended recipient, please
contact the sender by reply email and delete all copies of this message.
@suki-chima-ck Thank you!
It looks like newrelic_alert_channel does not use the default account id set in the provider. I am not sure if the API KEY is tied to a default account. If yes, this may explain this odd behavior.
I tried this setup with two different configs with distinct account ids: a "main" account and a sub-account. The "main" account config set-up everything as expected. The sub-account config created the alert channel in the "main" account and the policy in the sub-account. The linking did not work.
I spent some time digging into this and here is what I found:
The channels-create API only accepts the following:
And as such, it seems to use the Account of your User API Key for creation. It can't create a channel under a different Account. See the API docs
Policies and Conditions, on the other hand, can be created under a specified Account. This is all fine as long as you have the proper permissions, i.e. the User API Key can operate on all Accounts.
Now the problem seems to be when you have a Policy/Condition under a different Account than the Alert Channel. Wiring the two together fails with this 422 error. I think, and I'm testing it, this can all work fine if your User API Key has access to everything. Hopefully I'll have an update shortly.
Update: Creating an User API Key under the Account where the Alert Channel is located fixed the issue.
@sdedovic I had a similar issue with multiple accounts. In my case I was trying to move a notification channel from the parent account to the child account. The notification channel already existed in the parent account, but I did not destroy the channel in the parent account before using the API key for the child account to create the new notification channel. Creating the policy then failed with a 422.
I resolved this by:
I ran into this problem.
Based on @rlmv's comment I identified my state file was tracking a resource newrelic_alert_policy.policy which didn't seem to exist in the account I was expecting. Turns out it had created it in our development environment (different account ID) because the automation used a default value for account_id in provider the first time it deployed. All of the dependent resources that referenced the alert policy were trying to refer to an "existing" resource that wasn't in the account it was now correctly configured with.
Manually cleaning up the resource and removing from state with terraform state rm <address> resolved my issue.
Most helpful comment
We are also facing this problem while adding email alert channels to certain policies.
The notification channel ID given in the error message refers to the notification channel in our test account even though we are fully in production.
We have double check the tfstate file and even deleted the same to make sure everything is being created from scratch.
best
mathias