Commit 23c37405 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'fix-terraform-state-version-unique-constraint-violations' into 'master'

Use pessimistic locking when accessing Terraform state

See merge request gitlab-org/gitlab!71873
parents 9ab1066c ac3916a5
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
module Terraform module Terraform
class RemoteStateHandler < BaseService class RemoteStateHandler < BaseService
include Gitlab::OptimisticLocking
StateLockedError = Class.new(StandardError) StateLockedError = Class.new(StandardError)
UnauthorizedError = Class.new(StandardError) UnauthorizedError = Class.new(StandardError)
...@@ -60,7 +58,7 @@ module Terraform ...@@ -60,7 +58,7 @@ module Terraform
private private
def retrieve_with_lock(find_only: false) def retrieve_with_lock(find_only: false)
create_or_find!(find_only: find_only).tap { |state| retry_optimistic_lock(state, name: 'terraform_remote_state_handler_retrieve') { |state| yield state } } create_or_find!(find_only: find_only).tap { |state| state.with_lock { yield state } }
end end
def create_or_find!(find_only:) def create_or_find!(find_only:)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment