aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-07-04 12:06:25 +0100
committerChristopher Baines <mail@cbaines.net>2018-07-04 12:06:25 +0100
commit8bd3eac92e0b098608b4b4f0becc9516d872213a (patch)
treec6f087725bef61be23079d8a8582fad5462eaf14
parent74fb581d6aedc321b64e43c82bff01bc35a0f7da (diff)
downloadgovuk-mini-environment-admin-8bd3eac92e0b098608b4b4f0becc9516d872213a.tar
govuk-mini-environment-admin-8bd3eac92e0b098608b4b4f0becc9516d872213a.tar.gz
Use database locking to prevent concurrent Terraform jobs
Currently, the Terraform code uses chdir in the Ruby process to change to the right working directory. This affects all threads in the process, and thus means that all Terraform jobs conflict with each other. It would be good to fix this somehow, e.g. not changing directory, and just specifying the directory in which to run Terraform when starting it, but for now, use the advisory locks to force the jobs to run sequentially.
-rw-r--r--app/models/backends/terraform_aws/backend_methods.rb2
-rw-r--r--app/models/backends/terraform_aws/mini_environment_methods.rb2
-rw-r--r--app/models/backends/terraform_libvirt/backend_methods.rb2
-rw-r--r--app/models/backends/terraform_libvirt/mini_environment_methods.rb2
4 files changed, 4 insertions, 4 deletions
diff --git a/app/models/backends/terraform_aws/backend_methods.rb b/app/models/backends/terraform_aws/backend_methods.rb
index 5ade46c..ca2bd83 100644
--- a/app/models/backends/terraform_aws/backend_methods.rb
+++ b/app/models/backends/terraform_aws/backend_methods.rb
@@ -80,7 +80,7 @@ module Backends::TerraformAws::BackendMethods
def within_backend_terraform_working_directory(&block)
with_advisory_lock(
- "aws_backend_terraform_working_directory/#{id}"
+ "terraform"
) do
TerraformWorkingDirectory.new(
terraform_state_id,
diff --git a/app/models/backends/terraform_aws/mini_environment_methods.rb b/app/models/backends/terraform_aws/mini_environment_methods.rb
index 36fd70d..d0a8ab5 100644
--- a/app/models/backends/terraform_aws/mini_environment_methods.rb
+++ b/app/models/backends/terraform_aws/mini_environment_methods.rb
@@ -82,7 +82,7 @@ module Backends::TerraformAws::MiniEnvironmentMethods
def within_terraform_working_directory(mini_environment, &block)
with_advisory_lock(
- "aws_mini_environment_terraform_working_directory/#{mini_environment.id}"
+ "terraform"
) do
TerraformWorkingDirectory.new(
mini_environment_state_id(mini_environment),
diff --git a/app/models/backends/terraform_libvirt/backend_methods.rb b/app/models/backends/terraform_libvirt/backend_methods.rb
index 06b89e4..d14affa 100644
--- a/app/models/backends/terraform_libvirt/backend_methods.rb
+++ b/app/models/backends/terraform_libvirt/backend_methods.rb
@@ -56,7 +56,7 @@ module Backends::TerraformLibvirt::BackendMethods
def within_backend_terraform_working_directory(&block)
with_advisory_lock(
- "libvirt_backend_terraform_working_directory/#{id}"
+ "terraform"
) do
TerraformWorkingDirectory.new(
terraform_state_id,
diff --git a/app/models/backends/terraform_libvirt/mini_environment_methods.rb b/app/models/backends/terraform_libvirt/mini_environment_methods.rb
index 9b68d49..ef2b4c1 100644
--- a/app/models/backends/terraform_libvirt/mini_environment_methods.rb
+++ b/app/models/backends/terraform_libvirt/mini_environment_methods.rb
@@ -79,7 +79,7 @@ module Backends::TerraformLibvirt::MiniEnvironmentMethods
def within_terraform_working_directory(mini_environment, &block)
with_advisory_lock(
- "libvirt_mini_environment_terraform_working_directory/#{mini_environment.id}"
+ "terraform"
) do
TerraformWorkingDirectory.new(
mini_environment_state_id(mini_environment),