From e5c3d2979282404e7d89b4facc4e4f138aa2ae1d Mon Sep 17 00:00:00 2001
From: Christopher Baines
Date: Sat, 23 Jun 2018 22:51:48 +0100
Subject: Support 'Stopping' the AWS backend
Which means just destroying the build machine.
---
app/controllers/backends/terraform_aws_controller.rb | 4 ++++
app/models/backends/terraform_aws/backend_methods.rb | 13 +++++++++++++
app/views/backends/terraform_aws/show.html.erb | 13 +++++++++++++
3 files changed, 30 insertions(+)
diff --git a/app/controllers/backends/terraform_aws_controller.rb b/app/controllers/backends/terraform_aws_controller.rb
index ab9b323..e5b66d4 100644
--- a/app/controllers/backends/terraform_aws_controller.rb
+++ b/app/controllers/backends/terraform_aws_controller.rb
@@ -65,6 +65,10 @@ class Backends::TerraformAwsController < ApplicationController
Backends::TerraformAwsJob.enqueue(@backend.id, :destroy_backend)
flash[:notice] = 'Destroying the backend'
+ when 'Stop'
+ Backends::TerraformAwsJob.enqueue(@backend.id, :stop_backend)
+
+ flash[:notice] = 'Stopping the backend'
when 'Deploy'
Backends::TerraformAwsJob.enqueue(@backend.id, :deploy_backend)
diff --git a/app/models/backends/terraform_aws/backend_methods.rb b/app/models/backends/terraform_aws/backend_methods.rb
index f8338a4..89509bd 100644
--- a/app/models/backends/terraform_aws/backend_methods.rb
+++ b/app/models/backends/terraform_aws/backend_methods.rb
@@ -78,6 +78,19 @@ module Backends::TerraformAws::BackendMethods
end
end
+ def stop_backend
+ TerraformWorkingDirectory.new(
+ terraform_state_id,
+ 'terraform/aws/backend'
+ ).within_working_directory do
+ RubyTerraform.destroy(
+ vars: backend_terraform_variables,
+ target: 'aws_spot_instance_request.main',
+ force: true
+ )
+ end
+ end
+
def available_data_snapshots
GovukGuix::DataSnapshot.where(backend: self)
end
diff --git a/app/views/backends/terraform_aws/show.html.erb b/app/views/backends/terraform_aws/show.html.erb
index 6a576ab..0160798 100644
--- a/app/views/backends/terraform_aws/show.html.erb
+++ b/app/views/backends/terraform_aws/show.html.erb
@@ -84,6 +84,19 @@ License along with the GOV.UK Mini Environment Admin. If not, see
is setup to create new mini environments.
+
+ <%= submit_tag("Stop",
+ role: 'button',
+ style: 'margin-bottom: 5px;',
+ class: 'btn btn-lg btn-warning btn-block')
+ %>
+
+ Run Terraform to stop this backend, terminating the
+ build machine used to build new mini
+ environments. Existing environments will continue to
+ run, but new environments cannot be created.
+
+
<%= submit_tag("Destroy",
role: 'button',
--
cgit v1.2.3