jianyuan / terraform-provider-sentry

Terraform provider for Sentry
https://registry.terraform.io/providers/jianyuan/sentry/latest
MIT License
326 stars 127 forks source link

Bug in sentry_notification_action resource that produced inconsistent result after apply #392

Open bartoszbetkababylon opened 6 months ago

bartoszbetkababylon commented 6 months ago

Inconsistent terraform state

Example:

resource "sentry_project" "default" {
  organization = "my-organization"

  teams = ["my-first-team"]
  name  = "test-service"

  platform = "java"
}

# Create a notification action for the project
resource "sentry_notification_action" "default" {
  organization      = sentry_project.default.organization
  trigger_type      = "spike-protection"
  service_type      = "slack"
  integration_id    = "<sentry_integration_slack_id>"
  target_identifier = "<slack_channel_id>"
  target_display    = "#default"
  projects          = [sentry_project.default.id]
}

Error:

│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to resource.sentry_notification_action.default, provider "provider[\"registry.terraform.io/jianyuan/sentry\"]" produced an unexpected new value: .projects[0]: was cty.StringVal("test-service"), but now cty.StringVal("").
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

This causes the notification to be recreated each time with a terraform plan:

-/+ resource "sentry_notification_action" "this" {
      ~ id                = "1324235" -> (known after apply)
      ~ projects          = [
          - "",
          + "test-service",
        ]
        # (6 unchanged attributes hidden)
    }

Perhaps this is because the project attribute is a list of the project slugs, and the sentry api seems to show the project ID in the response? https://docs.sentry.io/api/alerts/create-a-spike-protection-notification-action/

Additional issue: One notification action for multiple project slugs

Example:

resource "sentry_project" "default" {
  organization = "my-organization"

  teams = ["my-first-team"]
  name  = "test-service"

  platform = "java"
}

resource "sentry_project" "default2" {
  organization = "my-organization"

  teams = ["my-first-team"]
  name  = "test-service2"

  platform = "java"
}

resource "sentry_notification_action" "default" {
  organization      = sentry_project.default.organization
  trigger_type      = "spike-protection"
  service_type      = "slack"
  integration_id    = "<sentry_integration_slack_id>"
  target_identifier = "<slack_channel_id>"
  target_display    = "#default"
  projects          = [sentry_project.default.id, sentry_project.default2.id]
}

Error:

Error: Client Error
│
│   with sentry_notification_action.this,
│   on main.tf line 19, in resource "sentry_notification_action" "this":
│   19: resource "sentry_notification_action" "this" {
│
│ Error creating notification action: POST https://sentry.io/api/0/organizations/test/notifications/actions/: 400 map[projects:[Each action for 'spike-protection' trigger must apply to one project]]
clymerrm commented 1 month ago

Has anyone found a way around this? I thought I had this working previously but now all of my runs to fail because of this.