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

Error when handling externally-deleted organization member #446

Open
ben-z opened this issue May 18, 2024 · 3 comments
Open

Error when handling externally-deleted organization member #446

ben-z opened this issue May 18, 2024 · 3 comments

Comments

@ben-z
Copy link
Contributor

ben-z commented May 18, 2024

Currently, the provider doesn't appear to handle unexpected organization member deletions well. For example:

resource "sentry_organization_member" "test_member" {
  organization = data.sentry_organization.watonomous.slug
  email        = var.email
  role         = var.org_role
}

resource "sentry_team_member" "test_team_membership" {
  organization = data.sentry_organization.watonomous.slug
  team         = var.team
  member_id    = sentry_organization_member.test_member.internal_id
}

An unexpected organization member removal would cause:

sentry_organization_member.test_member: Refreshing state... [id=watonomous/12488290]

...

2024-05-18T18:59:05.234Z [INFO]  provider.terraform-provider-sentry_v0.12.3: Removed organization membership from state because it no longer exists in Sentry: @module=sentry tf_mux_provider=tf5to6server.v5tov6Server tf_provider_addr=registry.terraform.io/jianyuan/sentry tf_rpc=ReadResource @caller=github.com/jianyuan/terraform-provider-sentry/sentry/resource_sentry_organization_member.go:105 memberID=12487829 org=watonomous tf_req_id=c2ca2d6f-826a-4d8a-30d2-f2c0c06f89d6 tf_resource_type=sentry_organization_member timestamp=2024-05-18T18:59:05.234Z

...

│ Error: Client Error
│
│   with sentry_team_member.managed_team_memberships.test_team_membership,
│   on main.tf line 220, in resource "sentry_team_member" "test_team_membership":
│  220: resource "sentry_team_member" "test_team_membership" {
│
│ unable to read organization member, got error: GET https://sentry.io/api/0/organizations/watonomous/members/12488290/: 404 The requested resource does not exist
╵

This seems to happen when a member doesn't accept their invite for an extended period of time and Sentry appears to remove the invite.

@coutantal
Copy link

Thanks for this one 🙏

@dimitri-fert
Copy link

Hello, I feel this is not specific to team members but generic to multiple resources.
I had similar problem on issue alerts and keys after external deletions (performed from Sentry's UI)

resource "sentry_key" "this" {
  organization = data.sentry_organization.this.id
  project      = sentry_project.this[0].slug
  name         = local.sentry_env
}
Planning failed. Terraform encountered an error while generating this plan.
╷
│ Error: Client Error
│
│   with module.sentry.sentry_key.this,
│   on ../../../home/dfert/code/IAC/terraform-modules/modules/sentry/keys.tf line 1, in resource "sentry_key" "this":
│    1: resource "sentry_key" "this" {
│
│ Not found: GET https://sentry.io/api/0/projects/xxxxxxxx/yyyyyyyyy/keys/vvvvvvvvvvvv/: 404 The requested resource does not exist
╵

resource "sentry_issue_alert" "main" {
  count        = contains(local.tf_workspaces_for_sentry, terraform.workspace) ? 1 : 0
  organization = data.sentry_organization.this.id
  project      = sentry_project.this[0].slug
  name         = "[${local.sentry_env}] Send a notification for high priority issues"

  environment = local.sentry_env

  filter_match = "all"
  conditions = jsonencode([
    { "id" : "sentry.rules.conditions.high_priority_issue.NewHighPriorityIssueCondition" },
    { "id" : "sentry.rules.conditions.high_priority_issue.ExistingHighPriorityIssueCondition" }
  ])

  frequency    = 30
  action_match = "any"
  actions = jsonencode([
    { 
      "id" : "sentry.mail.actions.NotifyEmailAction",
      "targetType" :  "Team",
      "targetIdentifier" : tonumber(data.sentry_team.this.internal_id),
      "fallthroughType" : "AllMembers",
    },
    {
      "id" : "sentry.integrations.msteams.notify_action.MsTeamsNotifyServiceAction",
      "team" : tonumber(data.sentry_organization_integration.msteams.id),
      "channel" : var.project.alerts.notification.ms_teams.channel_name
    }
  ])
}
Planning failed. Terraform encountered an error while generating this plan.
╷
│ Error: Client Error
│
│   with module.sentry.sentry_issue_alert.main[0],
│   on ../../../home/dfert/code/IAC/terraform-modules/modules/sentry/alerts.tf line 1, in resource "sentry_issue_alert" "main":
│    1: resource "sentry_issue_alert" "main" {
│
│ Issue alert not found: GET https://sentry.io/api/0/projects/xxxxxxxxx/yyyyyyyyyyy/rules/vvvvvvvv/: 404 The requested resource does not exist
╵

@ahublersos
Copy link

I've encountered the same issue for sentry_project_spike_protection, sentry_project_inbound_data_filter, and sentry_key resources after a project was deleted via the UI.

Error: Client Error

  with module.sentry_project["foo"].sentry_project_spike_protection.this,
  on .terraform/modules/sentry_project/terraform/modules/sentry-project/main.tf line 13, in resource "sentry_project_spike_protection" "this":
  13: resource "sentry_project_spike_protection" "this" {

Project not found: GET https://sentry.io/api/0/projects/<org>/foo/:
404 The requested resource does not exist

Error: Client Error

  with module.sentry_project["foo"].sentry_project_inbound_data_filter.data_filters["browser-extensions"],
  on .terraform/modules/sentry_project/terraform/modules/sentry-project/main.tf line 19, in resource "sentry_project_inbound_data_filter" "data_filters":
  19: resource "sentry_project_inbound_data_filter" "data_filters" {

Error reading project inbound data filters: GET
https://sentry.io/api/0/projects/<org>/foo/filters/: 404 The requested
resource does not exist

Error: Client Error

  with module.sentry_project["foo"].sentry_key.this["non-prod"],
  on .terraform/modules/sentry_project/terraform/modules/sentry-project/main.tf line 36, in resource "sentry_key" "this":
  36: resource "sentry_key" "this" {

Not found: GET
https://sentry.io/api/0/projects/<org>/foo/keys/<key-id>/:
404 The requested resource does not exist

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

No branches or pull requests

4 participants