Terraform-provider-newrelic: newrelic_alert_policy_channel resource recreated every time

Created on 22 Jan 2021  路  7Comments  路  Source: newrelic/terraform-provider-newrelic

IT seems like when the channel_ids list is ordered in the API response some way and in the HCL config another way, the resource is re-created again and again.
The provider should use set instead of list to avoid this ordering issue.

Terraform Version

Terraform v0.14.2

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

Affected Resource(s)

Please list the resources as a list, for example:

  • newrelic_alert_policy_channel

Terraform Configuration

resource "newrelic_alert_policy_channel" "path-prod-hr-api" {
  policy_id = newrelic_alert_policy.path-prod-hr-api.id
  channel_ids = [
    newrelic_alert_channel.ops.id,
    data.newrelic_alert_channel.slack.id,
    newrelic_alert_channel.insight.id
  ]
}

Actual Behavior

  # newrelic_alert_policy_channel.path-synthetics must be replaced
-/+ resource "newrelic_alert_policy_channel" "path-synthetics" {
      ~ channel_ids = [ # forces replacement
            2602225,
          - 3654790,
            3703482,
          + 3654790,
        ]
      ~ id          = "947883:2602225:3654790:3703482" -> (known after apply)
        # (1 unchanged attribute hidden)
    }

Expected Behavior

The resource should not be changed

Steps to Reproduce

  1. Create the resource
  2. change the order of the channel IDs (channel resources) in the array
  3. terraform plan/apply
bug

All 7 comments

I am having the same issue (with webhook). I was wondering if it was normal. That being said this creates logs every time to recreate many resources even if they didn't change.

@rizalgowandy, how is this related to the issue?

@ZsoltPath would you be interesting in committing the fix for this? It's an open source repo, so we are happy to help you get it to release if you feel comfortable working on the provider.

@ZsoltPath you can try to wrap array of your channel ids into sort() function, so their order will be aligned between TF and underlying NewRelic's API responses.
There is suggestions about sorting in provider's source code (see this line)
For me, sort() function solved the issue with resources recreation.

@bohdanborovskyi-ma interestingly some sorting is already in place in the code:
https://github.com/newrelic/terraform-provider-newrelic/blob/6613e1bb5aa01e34cd8d6c6818f69f5ecf939fef/newrelic/resource_newrelic_alert_policy_channel.go#L50
https://github.com/newrelic/terraform-provider-newrelic/blob/6613e1bb5aa01e34cd8d6c6818f69f5ecf939fef/newrelic/resource_newrelic_alert_policy_channel.go#L84

It was a while ago, but I think I've tried to sort them in my HCL code, but still got the same issue.
I might give it another try.

This is a huge pain point for us. It results in multiple pipeline runs to rectify it. Channels disappear then get re-added.

@casey-robertson Thanks for confirming this is still an issue. From my testing it like reverse-sorting in the config solves it... That said, put this into #1259 as a few line fix (Set instead of List, ignore the order in HCL).

Was this page helpful?
0 / 5 - 0 ratings