Terraform-provider-newrelic: Upgrading provider from 1.8.0 to 1.9.0 produced perpetual drift in some newrelic_infra_alert_condition conditions

Created on 6 Dec 2019  路  3Comments  路  Source: newrelic/terraform-provider-newrelic

Terraform Version

Terraform v0.11.11

  • provider.newrelic v1.9.0

Affected Resource(s)

  • newrelic_infra_alert_condition

Terraform Configuration Files

resource "newrelic_infra_alert_condition" "iis_service_stopped_sweb" {
  comparison = "equal"

  critical {
    duration = 5
  }

  enabled       = true
  event         = "ProcessSample"
  name          = "IIS Service stopped for Library Web"
  policy_id     = data.newrelic_alert_policy.ops_notify_pagerduty.id
  process_where = "(`processDisplayName` = 'w3wp.exe')"
  select        = "processId"
  type          = "infra_process_running"
  where         = "(`apmApplicationNames` LIKE '|LibraryService.WebRole%')"
}

resource "newrelic_infra_alert_condition" "redis_load" {
  comparison = "above"

  critical {
    duration      = "10"
    time_function = "all"
    value         = "25"
  }

  enabled              = "true"
  integration_provider = "AzureRedisCache"
  name                 = "Redis Server Load Percentage"
  policy_id            = data.newrelic_alert_policy.ops_notify_pagerduty.id
  select               = "serverLoadPercent.Average"
  type                 = "infra_metric"
}

Output

  # newrelic_infra_alert_condition.iis_service_stopped_lsweb will be updated in-place
~ resource "newrelic_infra_alert_condition" "iis_service_stopped_lsweb" {
        comparison    = "equal"
        created_at    = 1565738328870
        enabled       = true
      + event         = "ProcessSample"
        id            = "439821:10857215"
        name          = "IIS Service stopped for LiveShare Web"
        policy_id     = 439821
        process_where = "(`processDisplayName` = 'w3wp.exe')"
      + select        = "processId"
        type          = "infra_process_running"
        updated_at    = 1575490744865
        where         = "(`apmApplicationNames` LIKE '|LiveShare.WebRole%')"

        critical {
            duration = 15
            value    = 0
        }
    }

  # newrelic_infra_alert_condition.redis_load will be updated in-place
~ resource "newrelic_infra_alert_condition" "redis_load" {
        comparison           = "above"
        created_at           = 1572375196070
        enabled              = true
      - event                = "AzureRedisCacheSample" -> null
        id                   = "439821:11115711"
        integration_provider = "AzureRedisCache"
        name                 = "Redis Server Load Percentage"
        policy_id            = 439821
        select               = "serverLoadPercent.Average"
        type                 = "infra_metric"
        updated_at           = 1572375196160

        critical {
            duration      = 10
            time_function = "all"
            value         = 25
        }
    }

Expected Behavior

With no code changes, no configuration drift should appear after upgrading the provider from 1.8.0 to 1.9.0

Actual Behavior

Instead, the output above appeared. Applying the changes did not clear the configuration drift.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Create the resources with provider version 1.8.0. Verify terraform plan shows no changes after creation.
  2. Upgrade the provider to 1.9.0
  3. Re-run terraform plan and observe unexpected changes like above.
  4. Try terraform apply (which is successful) and then re-run terraform plan and observe the changes are still present.
  5. Also, tried deleting and re-creating resources and the drift was still present.
  6. The only way I found to fix this was to revert the provider upgrade AND also the state file.

References

@ctrombley I suspect this may be related to
https://github.com/terraform-providers/terraform-provider-newrelic/pull/254/files

In the state file, I noticed that some of the fields such as "event" had been changed from

"event": null,

to

"event": "AzureRedisCacheSample",

(for the second example above)

Note that there were two scenarios scene, but they are most likely related. For the first case, the state file difference was something like

            ],
             "enabled": true,
-            "event": "",
+            "event": "ProcessSample",
             "id": "439821:11264590",
             "integration_provider": null,
             "name": "IIS Service stopped for LiveShare Web",
             "policy_id": 439821,
             "process_where": "(`processDisplayName` = 'w3wp.exe')",
             "runbook_url": "",
-            "select": "",
+            "select": "processId",
             "type": "infra_process_running",
             "updated_at": 1575592976189,
             "warning": [],`
bug

All 3 comments

@pickgr I've reproduced this locally. You uncovered two separate issues here:

  • Validation does not exist in the provider for specific infra condition types, which can lead to confusing usage scenarios. In your first example above, you are using the event and select attributes for the infra_process_running condition type, which doesn't support them. The Infra API is ignoring those fields on resource creation and returning a payload that doesn't contain them. Previous versions of the provider didn't track these values in state and therefore didn't result in drift. We recommend that you remove those attributes from your config file to resolve the drift for that resource. We'll follow this up with a PR for stricter validation and some documentation updates.
  • event can act as a computed value. I'll address this with a PR shortly.

@ctrombley Thanks for the quick turn-around on this. I've updated our provider version to v1.10.0 and verified this is fixed. Really appreciate all the recent attention to supporting this provider!

@pickgr You're welcome! We (New Relic) are actively working to improve the tools available for automated workflows, and the Terraform provider is a major part of that initiative. If you're interested in seeing / participating on the overall vision we'd love some feedback on the public roadmap. We've created a space for an RFC here: https://discuss.newrelic.com/t/rfc-developer-toolkit-roadmap-2020/90528

Was this page helpful?
0 / 5 - 0 ratings