newrelic / terraform-provider-newrelic

Terraform provider for New Relic
https://registry.terraform.io/providers/newrelic/newrelic/latest/docs
Mozilla Public License 2.0
200 stars 244 forks source link

newrelic_notification_channel cannot use private channel IDs on create but works on update #2634

Open jmangs opened 3 months ago

jmangs commented 3 months ago

I'm unable to directly create newrelic_notification_destination objects with a private Slack channel ID set. In order to use private Slack channels, I have to first create it with a public Slack channel, then do a second terraform apply to update the existing object to point at a private Slack channel. I've verified the NR integration can see all private channels already in the UI. Not sure if this is intended behaviour but it's just annoying to deal with.

Terraform Version

Terraform v1.7.5

Affected Resource(s)

newrelic_notification_channel

Terraform Configuration

data "newrelic_notification_destination" "slack" {
  id = "fake-id"
}

resource "newrelic_notification_channel" "notify_slack" {
  name           = "example-service-default-notify-slack"
  type           = "SLACK"
  destination_id = data.newrelic_notification_destination.slack.id

  product = "IINT"

  property {
    key   = "channelId"
    value = "placeholder-fake-value" # private channel ID
  }
}

Actual Behavior

When trying to create, the channel can never be found. It takes two applies to use private channels with this pattern, first we have to set it to a public Slack channel, then update it to a private channel afterwards:

Error: UNKNOWN_ERROR: An unknown error has occurred

  with module.bootstrap["example-service"].newrelic_notification_channel.notify_slack,
  on ../../modules/bootstrap/default-service-workflows/main.tf line 83, in resource "newrelic_notification_channel" "notify_slack":
  83: resource "newrelic_notification_channel" "notify_slack" {

channel_not_found

The second apply successfully updates:

module.bootstrap["example-service"].newrelic_notification_channel.notify_slack: Modifications complete after 1s [id=fake-id]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Expected Behavior

What should have happened?

Steps to Reproduce

  1. Create a newrelic_notification_channel with a private channel ID set.
  2. terraform apply
  3. Observe the failure.
  4. Update the newrelic_notification_channel to a public channel ID.
  5. terraform apply
  6. Notification channel is created.
  7. Update the newrelic_notification_channel to a private channel ID.
  8. terraform apply
  9. The update path successfully changes it to the private channel.

Debug Output

N/A

Panic Output

N/A

Important Factoids

N/A

References

Other users have seen this issue in #2070 - similar validation failure happens there:

nzur-newrelic commented 2 months ago

Hey @jmangs, I tried to reproduce your error but it worked for me. I'm not sure exactly what is the problem, can it be the provider version you're using? I suggest bumping the version to the latest one and check it again. Also the reference seem to be related to using slack channel name, not to channel id, and from what I understand your issue is solely with channel id.

jmangs commented 2 months ago

We're on 3.34.1. I've resorted to doing double applies to work around it for now:

module.bootstrap["apns"].newrelic_notification_channel.notify_slack: Creating...
Error: UNKNOWN_ERROR: An unknown error has occurred

  with module.bootstrap["apns"].newrelic_notification_channel.notify_slack,
  on ../../modules/bootstrap/default-service-workflows/main.tf line 83, in resource "newrelic_notification_channel" "notify_slack":
  83: resource "newrelic_notification_channel" "notify_slack" {

channel_not_found

Plan for updating back to a private channel (only showing one entry to avoid spam):

  # module.bootstrap["apns"].newrelic_notification_channel.notify_slack will be updated in-place
  ~ resource "newrelic_notification_channel" "notify_slack" {
        id             = "OBJECT_ID"
        name           = "apns-default-notify-slack"
        # (6 unchanged attributes hidden)

      - property {
          - key   = "channelId" -> null
          - value = "OLD_ID" -> null
        }
      - property {
          - key   = "source" -> null
          - label = "terraform-source-internal" -> null
          - value = "terraform" -> null
        }
      + property {
          + key   = "channelId"
          + value = "NEW_ID"
        }
      + property {
          + key   = "source"
          + label = "terraform-source-internal"
          + value = "terraform"
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.
module.bootstrap["apns"].newrelic_notification_channel.notify_slack: Modifying... [id=OBJECT_ID]
module.bootstrap["apns"].newrelic_notification_channel.notify_slack: Modifications complete after 1s [id=OBJECT_ID]

Looking at the Go code, it's getting the error in this call I believe: resource_newrelic_notifications_channel.go#L93 - maybe it's something with our Workflow permissions since the failure is coming from newrelic-client-go. Doesn't explain why create doesn't work but update does.