terraform-provider-sentry
terraform-provider-sentry copied to clipboard
sentry_issue_alert actions/conditions/filters name bug
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?
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.
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.
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?
I found the solution in another issue. https://github.com/jianyuan/terraform-provider-sentry/issues/109
This does the trick to ignore it properly!
lifecycle {
ignore_changes = [
actions[0]["name"],
actions[0]["channel_id"]
]
}
I plan to investigate this further this weekend. I suspect we need a custom diff suppressor function.
Unfortunately, the diff suppressor doesn't work for lists: https://github.com/hashicorp/terraform-plugin-sdk/issues/477
I will have to do something more advanced in the Read method.
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. https://github.com/jianyuan/terraform-provider-sentry/pull/268
@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 Looks like there's a regression of this issue now that the
conditions
/actions
etc arejsonencode()
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: https://github.com/jianyuan/terraform-provider-sentry/pull/362
I'm aiming to release this tomorrow.
@adamstrawson I have just shipped v0.12.1. Let me know if that works!
@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! 👏
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.
@ocdrums3 Can you try conditions = "[]"
?