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

Slack notification rule: map[actions:[Ensure at least one action is enabled and all required fields are filled in.]]

Open PavelMikhailouski opened this issue 4 years ago • 9 comments

Hi!

I've been trying to create new rule for the project via terraform resource

resource "sentry_plugin" "slack" {
  organization = sentry_project.this.organization
  project      = sentry_project.this.name
  plugin       = "slack"
  config = {
    webhook = "https://hooks.slack.com/services/****/****"
    channel = "#sentry"
  }
}

resource "sentry_rule" "slack" {
  organization = sentry_project.this.organization
  project      = sentry_project.this.name
  action_match = "all"
  frequency    = 5

  name = "slack"

  actions = [{
    id      = "sentry.rules.actions.notify_event_service.NotifyEventServiceAction"
    service = "slack"
  }]

  conditions = [{
    id = "sentry.rules.conditions.every_event.EveryEventCondition"
  }]
}

Please find below that for rule parameters I have used the exact payload from rule creation in UI to make sure I won't miss anything: image image

To my surprise it did not work, the following error was thrown:

Error: sentry: map[actions:[Ensure at least one action is enabled and all required fields are filled in.]]

  on main.tf line 177, in resource "sentry_rule" "slack":
 177: resource "sentry_rule" "slack" {

Could you please assist me in figuring out whether it is my mistake or the provider issue?

Thank you.

PavelMikhailouski avatar Feb 26 '20 09:02 PavelMikhailouski

If you use the latest sentry plugin working with workspace, I suggest you to use sentry.integrations.slack.notify_action.SlackNotifyServiceAction

Here is a example:

resource "sentry_rule" "slack" {
  organization = sentry_project.this.organization
  project      = sentry_project.this.name
  action_match = "all"
  frequency    = 5

  name = "slack"

  actions = [{
    id        = "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
    channel   = "#sentry,
    workspace = "000000"
  }]

  conditions = [{
    id = "sentry.rules.conditions.every_event.EveryEventCondition"
  }]
}

mced avatar Feb 26 '20 10:02 mced

@mced, is there a solution for legacy plugin?

PavelMikhailouski avatar Feb 26 '20 10:02 PavelMikhailouski

As I don't use it anymore I can't help you. However you can search and found the json response which contains what you're looking for from the sentry page when posting the rule.

mced avatar Feb 26 '20 11:02 mced

Thanks for the tip.

I did the same exercise with response values but bumped into the same error.

resource "sentry_rule" "slack" {
  organization = sentry_project.this.organization
  project      = sentry_project.this.name
  action_match = "all"
  frequency    = 30

  name = "slack"

  actions = [{
    enabled = true
    id      = "sentry.rules.actions.notify_event_service.NotifyEventServiceAction"
    service = "slack"
    name    = "Send a notification via slack"
    label   = "Send a notification via {service}"
  }]

  conditions = [{
    id   = "sentry.rules.conditions.every_event.EveryEventCondition"
    name = "An event is seen"
  }]
}

I believe that enabled seem to be this missed required parameter (Error: sentry: map[actions:[Ensure at least one action is enabled and all required fields are filled in.]])

However, I've noticed that action map values are being converted to strings on apply (including boolean enabled). Can't this cause the issue?

Terraform will perform the following actions:

  # sentry_rule.slack will be created
  + resource "sentry_rule" "slack" {
      + action_match = "all"
      + actions      = [
          + {
              + "enabled" = "true"
              + "id"      = "sentry.rules.actions.notify_event_service.NotifyEventServiceAction"
              + "label"   = "Send a notification via {service}"
              + "name"    = "Send a notification via slack"
              + "service" = "slack"
            },
        ]
      + conditions   = [
          + {
              + "id"   = "sentry.rules.conditions.every_event.EveryEventCondition"
              + "name" = "An event is seen"
            },
        ]
      + environment  = (known after apply)
      + frequency    = 30
      + id           = (known after apply)
      + name         = "***"
      + organization = "***"
      + project      = "***
    }

PavelMikhailouski avatar Feb 26 '20 12:02 PavelMikhailouski

I've created the sentry_rule resource, I will have a look into that! Thanks for reporting 👍

chreble avatar Mar 10 '20 13:03 chreble

@PavelMikhailouski I've investigated and it is not related to the Terraform resource AT ALL. I got it working with the below:

resource "sentry_rule" "slack" {
  organization = sentry_project.this.organization
  project      = sentry_project.this.name
  name         = "Slack"
  action_match = "any"
  frequency    = 30

  actions = [{
    id        = "sentry.integrations.slack.notify_action.SlackNotifyServiceAction"
    channel   = "#sentry"
    name      = "Send a notification via slack"
    label     = "Send a slack notification"
    workspace = "XXXX"
    tags      = "environment"
  }]

  conditions = [{
    id   = "sentry.rules.conditions.every_event.EveryEventCondition"
  }]
}

You can get your own workspace value by going to configuration URL of Slack integration on Sentry admin.

Example https://sentry.io/settings/XXX/integrations/slack/XXXX/

chreble avatar Mar 10 '20 17:03 chreble

Thanks @chreble! As far as I can judge your solution works for the latest plugin version.

Is there something we can to to make rules work with legacy one?

PavelMikhailouski avatar Mar 11 '20 08:03 PavelMikhailouski

What would be really nice would to be able to do a data lookup to get the workspace value

budgester avatar Apr 22 '20 22:04 budgester

Would really be nice if this worked with legacy plugins as it looks like Sentry still makes heavy use of them for certain plugins, such as opsgenie. When creating a rule on the website, they only send over the action id=sentry.rules.actions.notify_event_service.NotifyEventServiceAction and service=opsgenie. When I follow the same format with this provider it still returns Error: sentry: map[actions:[Ensure all required fields are filled in.]]

CodechCFA avatar Sep 22 '20 21:09 CodechCFA

Would really be nice if this worked with legacy plugins as it looks like Sentry still makes heavy use of them for certain plugins, such as opsgenie. When creating a rule on the website, they only send over the action id=sentry.rules.actions.notify_event_service.NotifyEventServiceAction and service=opsgenie. When I follow the same format with this provider it still returns Error: sentry: map[actions:[Ensure all required fields are filled in.]]

@CodechCFA I'm getting the same error. Did you manage to find a work around?

AnitaErnszt avatar May 10 '23 12:05 AnitaErnszt

@AnitaErnszt we did not unfortunately. We use terraform to create the plugin but not any rules.

CodechCFA avatar May 10 '23 19:05 CodechCFA

I'm going to close this since it's likely fixed in the latest version.

jianyuan avatar Dec 16 '23 02:12 jianyuan