aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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