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_integration_pagerduty resource when provisioning multiple resources in a plan #462

Open dgeorges opened 2 months ago

dgeorges commented 2 months ago

When provisioning multiple resources of type sentry_integration_pagerduty the terraform plan will fail with an error. Usual after the first resource has succeeded. The error is:

Service table item not found: ####

eg.

image

Looking at the code here it seems the sentry API is behaving as eventually consistent, instead of transactional because the code it does the following:

  1. Calls GET to the list the organization available integration for PD
  2. Calls Update to update the organization available integration for PD
  3. Calls GET to confirm that the update was successful. <- This throws the errors after inspecting the results

I should mention this only happens when there are multiple "sentry_integration_pagerduty" resources to provision. The first one succeeds and the following ones all fail. When this happens the terraform state is left in a bad state and "terraform state rm" needs to be run to remove the last "sentry_integration_pagerduty" resource that didn't succeed.

It should fail gracefully without resulting in a bad statefile.

In the event the downstream api can not be changed. A retry or wait might help it not fail at all.

jianyuan commented 2 months ago

Thanks for reporting this. It may be due to the endpoint only accepting a list of service table items, leading to a race condition when run concurrently. For example, the first process edits a table item while the second process also edits a table item. A fix is to ensure that the resource can run only once concurrently against the same integration.