newrelic / terraform-provider-newrelic

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

Resource `newrelic_nrql_alert_condition`: Cannot change account ID of the resource. #2690

Open RobertoGraham opened 3 months ago

RobertoGraham commented 3 months ago

Terraform Version

1.8.5

Affected Resource(s)

Terraform Configuration

provider "newrelic" {
  account_id = var.newrelic_account_id
  api_key    = jsondecode(data.vault_kv_secret_v2.tfvars.data_json).newrelic-api-key
  region     = "US"
}

resource "newrelic_nrql_alert_condition" "foo" {
  name        = "foo"
  policy_id   = newrelic_alert_policy.foo.id
  account_id  = var.alternate_newrelic_account_id
  description = <<EOT
  Alert.
  EOT

  nrql {
    query = <<EOT
    SELECT count(*)
    FROM Metric
    EOT
  }

  critical {
    operator              = "above"
    threshold             = 5
    threshold_duration    = 300
    threshold_occurrences = "at_least_once"
  }
}

Actual Behavior

When applying the below plan, the below error was surfaced by Terraform.

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place
Terraform will perform the following actions:
  # newrelic_nrql_alert_condition.foo will be updated in-place
  ~ resource "newrelic_nrql_alert_condition" "foo" {
      ~ account_id                     = ******* -> *******
        id                             = "*******:*******"
        name                           = "foo"
        # (16 unchanged attributes hidden)
        # (2 unchanged blocks hidden)
    }
Plan: 0 to add, 1 to change, 0 to destroy.
newrelic_nrql_alert_condition.foo: Modifying... [id=*******:*******]
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to
│ newrelic_nrql_alert_condition.foo, provider
│ "provider[\"registry.terraform.io/newrelic/newrelic\"]" produced an
│ unexpected new value: Root object was present, but now absent.
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.
╵
Error: Terraform exited with code 1.
Error: Process completed with exit code 1.

Expected Behavior

The resource should have been modified to use the new account ID.

Steps to Reproduce

  1. Apply a plan to a newrelic_nrql_alert_condition resource that modifies its account_id value.
pranav-new-relic commented 3 months ago

Thank you for reporting this @RobertoGraham, appreciate the detail. We shall take a look at this sometime, based on our current priority queue.