Skip to content

Queue Terraform state destroy worker outside of transaction

Tiger Watson requested to merge queue-terraform-state-destroy-after-commit into master

What does this MR do and why?

If Terraform::States::TriggerDestroyService is called from within a database transaction, an error is raised because we need to be outside of a transaction to schedule a Sidekiq worker.

Instead, we queue the worker after the current transaction is committed using AfterCommitQueue.

Screenshots or screen recordings

These are strongly recommended to assist reviewers and reduce the time to merge your change.

How to set up and validate locally

  1. Using the Rails console, create a Terraform state:
      > Terraform::State.create!(project_id: <project-id>, name: 'test-state')
  2. Create a project/group/personal access token with maintainer permissions for the associated project
  3. Send a request to remove the state:
      > curl --header "Private-Token: <your_access_token>" --request DELETE "https://localhost:3000/api/v4/projects/<project-id>/terraform/state/test-state"
  4. Visit http://path/to/project/-/terraform and verify the state is (eventually) removed

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Tiger Watson

Merge request reports

Loading