summaryrefslogtreecommitdiff
path: root/app/services/terraform
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 10:34:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 10:34:06 +0000
commit859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch)
treed7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /app/services/terraform
parent446d496a6d000c73a304be52587cd9bbc7493136 (diff)
downloadgitlab-ce-859a6fb938bb9ee2a317c46dfa4fcc1af49608f0.tar.gz
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'app/services/terraform')
-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