Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/terraform/remote_state_handler.rb')
-rw-r--r--app/services/terraform/remote_state_handler.rb22
1 files changed, 16 insertions, 6 deletions
diff --git a/app/services/terraform/remote_state_handler.rb b/app/services/terraform/remote_state_handler.rb
index 7e79cb9e007..9500a821071 100644
--- a/app/services/terraform/remote_state_handler.rb
+++ b/app/services/terraform/remote_state_handler.rb
@@ -68,12 +68,14 @@ module Terraform
find_params = { project: project, name: params[:name] }
- if find_only
- Terraform::State.find_by(find_params) || # rubocop: disable CodeReuse/ActiveRecord
- raise(ActiveRecord::RecordNotFound.new("Couldn't find state"))
- else
- Terraform::State.create_or_find_by(find_params)
- end
+ return find_state!(find_params) if find_only
+
+ state = Terraform::State.create_or_find_by(find_params)
+
+ # https://github.com/rails/rails/issues/36027
+ return state unless state.errors.of_kind? :name, :taken
+
+ find_state(find_params)
end
def lock_matches?(state)
@@ -86,5 +88,13 @@ module Terraform
def can_modify_state?
current_user.can?(:admin_terraform_state, project)
end
+
+ def find_state(find_params)
+ Terraform::State.find_by(find_params) # rubocop: disable CodeReuse/ActiveRecord
+ end
+
+ def find_state!(find_params)
+ find_state(find_params) || raise(ActiveRecord::RecordNotFound.new("Couldn't find state"))
+ end
end
end