terraform-provider-newrelic icon indicating copy to clipboard operation
terraform-provider-newrelic copied to clipboard

newrelic_workflow | Provider tries to recreate workflow and crashes.

Open AdrienKuhn opened this issue 2 years ago • 7 comments

Terraform Version

Terraform v1.2.7
on darwin_amd64
+ provider registry.terraform.io/newrelic/newrelic v3.2.0

Affected Resource(s)

  • newrelic_notification_channel
  • newrelic_workflow

Terraform Configuration

resource "newrelic_notification_channel" "test_channel" {
  account_id = "(supposed to be optional but is actually required, see https://github.com/newrelic/terraform-provider-newrelic/issues/1993)"
  name = "Test Channel"
  type  = "PAGERDUTY_SERVICE_INTEGRATION"
  destination_id = "(pagerduty_destination_id)"
  product  = "IINT"

  property {
    key = "summary"
    value = "{{ annotations.title.[0] }}"
    label = "PagerDuty Summary"
  }

}

resource "newrelic_workflow" "test_workflow" {
  destinations_enabled = false
  enrichments_enabled = false
  muting_rules_handling = "NOTIFY_ALL_ISSUES"
  name = "Test Workflow"
  workflow_enabled  = true

  issues_filter {
    name = "policyName"
    type = "FILTER"

    predicates {
      attribute = "accumulations.policyName"
      operator  = "CONTAINS"
      values = ["something"]
    }
  }

  destination_configuration {
    channel_id = newrelic_notification_channel.test_channel.id
  }
}

Actual Behavior

  • First apply is working as expected
  • Subsequent plan is trying to recreate the workflow
Terraform will perform the following actions:

  # module.newrelic_alayamarket_workflow.newrelic_workflow.test_workflow must be replaced
-/+ resource "newrelic_workflow" "test_workflow" {
      - account_id            = 123456 -> null # forces replacement
      ~ destinations_enabled  = true -> false
      ~ enrichments_enabled   = true -> false

     [...]

Plan: 1 to add, 0 to change, 1 to destroy.
  • An apply will delete the workflow (which will also delete the channel on NewRelic side, which is unexpected) and the apply will fail
module.newrelic_alayamarket_workflow.newrelic_workflow.test_workflow: Destroying... [id=78f97f58-b884-4dae-9481-1a0a6a74b903]
module.newrelic_alayamarket_workflow.newrelic_workflow.test_workflow: Destruction complete after 3s
module.newrelic_alayamarket_workflow.newrelic_workflow.test_workflow: Creating...
╷
│ Error: INVALID_PARAMETER: A channel with id f35f0b02-8ba2-45a0-8f38-5e60b58e1f31 was not found
│
│   with module.newrelic_alayamarket_workflow.newrelic_workflow.test_workflow,
│   on modules/alert-workflow/main.tf line 52, in resource "newrelic_workflow" "test_workflow":
│   52: resource "newrelic_workflow" "test_workflow" {
  • Subsequent applies make the provider crash
Stack trace from the terraform-provider-newrelic_v3.2.0 plugin:

panic: runtime error: index out of range [0] with length 0

goroutine 866 [running]:
github.com/newrelic/terraform-provider-newrelic/v2/newrelic.resourceNewRelicNotificationChannelRead({0x1c0a530, 0xc00005ac60}, 0xc000972500, {0x193fee0?, 0xc00090d1d0})
	/home/runner/work/terraform-provider-newrelic/terraform-provider-newrelic/newrelic/resource_newrelic_notifications_channel.go:132 +0x44e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc0004dd500, {0x1c0a568, 0xc000868d20}, 0xd?, {0x193fee0, 0xc00090d1d0})
	/home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:724 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc0004dd500, {0x1c0a568, 0xc000868d20}, 0xc000a96ea0, {0x193fee0, 0xc00090d1d0})
	/home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:1015 +0x585
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc0001119c8, {0x1c0a568?, 0xc000868c00?}, 0xc0002a08c0)
	/home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:613 +0x497
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0xc00046d2c0, {0x1c0a568?, 0xc000868600?}, 0xc00005a600)
	/home/runner/go/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:747 +0x41e
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0x1a39e40?, 0xc00046d2c0}, {0x1c0a568, 0xc000868600}, 0xc0002703f0, 0x0)
	/home/runner/go/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:349 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00049e000, {0x1c0de70, 0xc000582340}, 0xc0008b6120, 0xc0004e7b60, 0x21d24f0, 0x0)
	/home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:1295 +0xb0b
google.golang.org/grpc.(*Server).handleStream(0xc00049e000, {0x1c0de70, 0xc000582340}, 0xc0008b6120, 0x0)
	/home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:1636 +0xa1b
google.golang.org/grpc.(*Server).serveStreams.func1.2()
	/home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:932 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
	/home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:930 +0x28a

Error: The terraform-provider-newrelic_v3.2.0 plugin crashed!
  • The only way out is to manipulate the terraform state to delete the module reference.

Expected Behavior

  • Plan should not try to recreate the workflow since there are no changes
  • Deleting the workflow should not delete the channel since those are 2 distinct resources in the Terraform configuration.

Steps to Reproduce

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

  1. Add the above configuration
  2. terraform apply
  3. terraform plan (this should show that it will recreate the workflow)
  4. terraform apply (this will delete the workflow and the channel)
  5. terraform apply (this will make the provider crash)

References

  • May be related to https://github.com/newrelic/terraform-provider-newrelic/issues/1974, but in the case above there are no changes in the configuration.

AdrienKuhn avatar Sep 13 '22 15:09 AdrienKuhn

Hi @AdrienKuhn thanks for raising the issue. We will prioritise it.

NSSPKrishna avatar Sep 14 '22 14:09 NSSPKrishna

Hi @AdrienKuhn please try with the latest release V3.2.1

NSSPKrishna avatar Sep 20 '22 10:09 NSSPKrishna

I can confirm this still occurs on V3.2.1.

I can work around it by either performing a terraform destroy before the apply, or deleting the .tfstate file... but that causes other issues obviously.

arhill05 avatar Sep 20 '22 13:09 arhill05

Ok, we will prioritise this issue.

NSSPKrishna avatar Sep 21 '22 10:09 NSSPKrishna

I am having the same issue with version 3.4.1 image

thoriqtoped avatar Oct 04 '22 04:10 thoriqtoped

Hi! Thank you for the detailed report! I have reproduced the issue and we are going to work on fixing it.

As a temporary workaround, you could specify account id on the workflow resources explicitly. This is obviously not ideal, but should at least unblock you until the problem is fixed.

IliaShurygin avatar Oct 11 '22 10:10 IliaShurygin

The problem with account_id is fixed in v3.5.0, you should now be able to create (was already possible before) and update (the previously broken part) workflows without specifying account_id in workflow resource explicitly.

IliaShurygin avatar Oct 17 '22 17:10 IliaShurygin