Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sentry_issue_alert actions/conditions/filters name bug #200

Closed
gurpreet-infogrid opened this issue Aug 12, 2022 · 13 comments · Fixed by #268
Closed

sentry_issue_alert actions/conditions/filters name bug #200

gurpreet-infogrid opened this issue Aug 12, 2022 · 13 comments · Fixed by #268

Comments

@gurpreet-infogrid
Copy link

I have created the following sentry_metric_alert:

resource "sentry_issue_alert" "main" {
    organization = sentry_project.main.organization
    project            = sentry_project.main.id
    name               = "My issue alert"
    frequency       = 30
    environment   = null
    action_match = "any"
    actions = [{
        id                = "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
        channel      = "#sentry",
        workspace = local.infogrid_slack_workspace_id,
        tags            = "environment,level,user"
    }]
    conditions = [{
        id   = "sentry.rules.conditions.every_event.EveryEventCondition"
        }]
    filter_match = "any"
    filters = []
    }

I don't want to set the name of actions and conditions, so I created the alert without this. But when I then try and run another plan terraform thinks that a name has been added outside of the terraform and so tries to remove this:

sentry_issue_alert.main will be updated in-place
 ~ resource "sentry_issue_alert" "main" {
     ~ actions      = [
         - {
             - "channel"    = "#sentry"
             - "channel_id" = "xxx"
             - "id"         = "sentry.integrations.slack.notify_action.SlackNotifyServiceAction"
             - "name"       = "Send a notification to the Infogrid Slack workspace to #sentry (optionally, an ID: xxx) and show tags [level, user] in notification"
             - "tags"       = "level,user"
             - "workspace"  = "xxx"
           },
         + {
             + "channel"   = "#sentry"
             + "id"        = "sentry.integrations.slack.notify_action.SlackNotifyServiceAction"
             + "tags"      = "level,user"
             + "workspace" = "xxx"
           },
       ]
     ~ conditions   = [
         - {
             - "comparisonType" = "count"
             - "id"             = "sentry.rules.conditions.every_event.EveryEventCondition"
             - "name"           = "The event occurs"
           },
         + {
             + "id"       = "sentry.rules.conditions.every_event.EveryEventCondition"
           },
       ]
       # (11 unchanged attributes hidden)
   }

This bug really clutters up any plans I run, as I have 100 alert rules all claiming there are changes to apply. I have tried to use the lifecycle ignore rule but the plan still shows changes each time :( Is there anything we could do about this?

@GertVil
Copy link

GertVil commented Sep 6, 2022

I had a similar situation where we set a name, but Sentry changed it every time. I just changed the name to make it match what Sentry always did and the behaviour stopped. So I guess you could work around it by explicitly setting the name to what Sentry puts into the field.

@elithompson
Copy link

elithompson commented Dec 6, 2022

I'm also getting bit by this issue. I am able to use lifecycle/ignore_changes (docs) to ignore the name change, but since these are specified in arrays, there has to be an ignore_changes entry for ever filter/condition/action that needs ignoring :/

Should name actually be a readonly field? On the website, I edited an existing rule, then copied the HTTP request as a curl, updated the name there, submitted, and the name did not change in Sentry at all.

@larosek
Copy link

larosek commented Jan 11, 2023

This problem is also affecting me and I was not able to ignore changes for actions 🤔 . I only have 1 actions specified in my resource and when adding the following lifecycle block I still see the same result as posted above where the action is removed and created again without the name and channel_id.

lifecycle {
    ignore_changes = [
      actions[0].name,
      actions[0].channel_id
    ]
  }

How did you achieved the ignore?

@larosek
Copy link

larosek commented Jan 12, 2023

I found the solution in another issue. #109

This does the trick to ignore it properly!

  lifecycle {
    ignore_changes = [
      actions[0]["name"],
      actions[0]["channel_id"]
    ]
  }

@jianyuan
Copy link
Owner

I plan to investigate this further this weekend. I suspect we need a custom diff suppressor function.

@jianyuan
Copy link
Owner

Unfortunately, the diff suppressor doesn't work for lists: hashicorp/terraform-plugin-sdk#477

I will have to do something more advanced in the Read method.

@jianyuan
Copy link
Owner

I have changed it so that the provider now compares the action, condition, and filter definitions from the server against the shape of the user's definitions. This means you can safely omit things like the name and channel id. #268

@adamstrawson
Copy link

@jianyuan Looks like there's a regression of this issue now that the conditions/actions etc are jsonencode() strings

│ When applying changes to sentry_issue_alert.alert, provider
│ "provider[\"registry.terraform.io/jianyuan/sentry\"]" produced an
│ unexpected new value: .actions: was cty.StringVal("[\n  {\n    \"id\":
│ \"sentry.integrations.slack.notify_action.SlackNotifyServiceAction\",\n
│ \"workspace\": \"XXX\",\n    \"channel\": \"alert-xxx\",\n
│ \"tags\": \"environment,level\"\n  }\n]\n"), but now
│ cty.StringVal("[{\"channel\":\"#alert-sandbox\",\"channel_id\":\"XXX\",\"id\":\"sentry.integrations.slack.notify_action.SlackNotifyServiceAction\",\"tags\":\"environment,level\",\"workspace\":\"XXX\"}]").

Happy to raise as a new issue if preferred.

@jianyuan
Copy link
Owner

@jianyuan Looks like there's a regression of this issue now that the conditions/actions etc are jsonencode() strings

│ When applying changes to sentry_issue_alert.alert, provider
│ "provider[\"registry.terraform.io/jianyuan/sentry\"]" produced an
│ unexpected new value: .actions: was cty.StringVal("[\n  {\n    \"id\":
│ \"sentry.integrations.slack.notify_action.SlackNotifyServiceAction\",\n
│ \"workspace\": \"XXX\",\n    \"channel\": \"alert-xxx\",\n
│ \"tags\": \"environment,level\"\n  }\n]\n"), but now
│ cty.StringVal("[{\"channel\":\"#alert-sandbox\",\"channel_id\":\"XXX\",\"id\":\"sentry.integrations.slack.notify_action.SlackNotifyServiceAction\",\"tags\":\"environment,level\",\"workspace\":\"XXX\"}]").

Happy to raise as a new issue if preferred.

This should hopefully reinstate the lossy check: #362

I'm aiming to release this tomorrow.

@jianyuan
Copy link
Owner

@adamstrawson I have just shipped v0.12.1. Let me know if that works!

@adamstrawson
Copy link

@adamstrawson I have just shipped v0.12.1. Let me know if that works!

That did the trick, thanks for the quick turn around on a solution! 👏

@outdoortejan
Copy link

What is the proper way to set conditions to an empty list? I keep getting either an error, or terraform is adding its own value, no matter what I try.

@jianyuan
Copy link
Owner

jianyuan commented Jan 4, 2024

@ocdrums3 Can you try conditions = "[]"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants