aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-06-24 09:52:29 +0100
committerChristopher Baines <mail@cbaines.net>2018-06-24 09:52:29 +0100
commitf5024ad542f221e13882cc0c01985625e45f0f7c (patch)
treea55899db9bf214aec6b1347b0af45e4506ca0c75
parenta60b2982ad8b2a9966fb16aa251ea21a376d711a (diff)
downloadgovuk-mini-environment-admin-f5024ad542f221e13882cc0c01985625e45f0f7c.tar
govuk-mini-environment-admin-f5024ad542f221e13882cc0c01985625e45f0f7c.tar.gz
Refactor the backends to use a method for working with Terraform
-rw-r--r--app/models/backends/terraform_aws/backend_methods.rb27
-rw-r--r--app/models/backends/terraform_libvirt/backend_methods.rb22
2 files changed, 21 insertions, 28 deletions
diff --git a/app/models/backends/terraform_aws/backend_methods.rb b/app/models/backends/terraform_aws/backend_methods.rb
index b21c83e..52875e6 100644
--- a/app/models/backends/terraform_aws/backend_methods.rb
+++ b/app/models/backends/terraform_aws/backend_methods.rb
@@ -48,10 +48,7 @@ module Backends::TerraformAws::BackendMethods
end
def deploy_backend
- TerraformWorkingDirectory.new(
- terraform_state_id,
- 'terraform/aws/backend'
- ).within_working_directory do
+ within_backend_terraform_working_directory do
RubyTerraform.apply(
vars: backend_terraform_variables,
auto_approve: true
@@ -60,10 +57,7 @@ module Backends::TerraformAws::BackendMethods
end
def refresh_backend_state
- TerraformWorkingDirectory.new(
- terraform_state_id,
- 'terraform/aws/backend'
- ).within_working_directory do
+ within_backend_terraform_working_directory do
RubyTerraform.refresh(
vars: backend_terraform_variables
)
@@ -71,10 +65,7 @@ module Backends::TerraformAws::BackendMethods
end
def destroy_backend
- TerraformWorkingDirectory.new(
- terraform_state_id,
- 'terraform/aws/backend'
- ).within_working_directory do
+ within_backend_terraform_working_directory do
RubyTerraform.destroy(
vars: backend_terraform_variables,
force: true
@@ -83,10 +74,7 @@ module Backends::TerraformAws::BackendMethods
end
def stop_backend
- TerraformWorkingDirectory.new(
- terraform_state_id,
- 'terraform/aws/backend'
- ).within_working_directory do
+ within_backend_terraform_working_directory do
RubyTerraform.destroy(
vars: backend_terraform_variables,
target: 'aws_spot_instance_request.main',
@@ -95,6 +83,13 @@ module Backends::TerraformAws::BackendMethods
end
end
+ def within_backend_terraform_working_directory(&block)
+ TerraformWorkingDirectory.new(
+ terraform_state_id,
+ 'terraform/aws/backend'
+ ).within_working_directory(&block)
+ end
+
def available_data_snapshots
GovukGuix::DataSnapshot.where(backend: self)
end
diff --git a/app/models/backends/terraform_libvirt/backend_methods.rb b/app/models/backends/terraform_libvirt/backend_methods.rb
index 9507e2c..00ac432 100644
--- a/app/models/backends/terraform_libvirt/backend_methods.rb
+++ b/app/models/backends/terraform_libvirt/backend_methods.rb
@@ -20,10 +20,7 @@
module Backends::TerraformLibvirt::BackendMethods
def deploy_backend
- TerraformWorkingDirectory.new(
- terraform_state_id,
- 'terraform/libvirt/backend'
- ).within_working_directory do
+ within_backend_terraform_working_directory do
RubyTerraform.apply(
vars: {
uri: uri,
@@ -35,10 +32,7 @@ module Backends::TerraformLibvirt::BackendMethods
end
def destroy_backend
- TerraformWorkingDirectory.new(
- terraform_state_id,
- 'terraform/libvirt/backend'
- ).within_working_directory do
+ within_backend_terraform_working_directory do
RubyTerraform.destroy(
vars: {
uri: uri,
@@ -50,10 +44,7 @@ module Backends::TerraformLibvirt::BackendMethods
end
def refresh_backend_state
- TerraformWorkingDirectory.new(
- terraform_state_id,
- 'terraform/libvirt/backend'
- ).within_working_directory do
+ within_backend_terraform_working_directory do
RubyTerraform.refresh(
vars: {
uri: uri,
@@ -63,6 +54,13 @@ module Backends::TerraformLibvirt::BackendMethods
end
end
+ def within_backend_terraform_working_directory(&block)
+ TerraformWorkingDirectory.new(
+ terraform_state_id,
+ 'terraform/libvirt/backend'
+ ).within_working_directory(&block)
+ end
+
def backend_terraform_states
TerraformState.where(
state_id: terraform_state_id