diff options
author | Christopher Baines <mail@cbaines.net> | 2018-06-23 22:51:48 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2018-06-23 22:51:48 +0100 |
commit | e5c3d2979282404e7d89b4facc4e4f138aa2ae1d (patch) | |
tree | adb62654cab677a40ad45ffc4423dd723e0bd1c4 | |
parent | 1026a19ee13805c6cb44c676f0b648b06bf2efd2 (diff) | |
download | govuk-mini-environment-admin-e5c3d2979282404e7d89b4facc4e4f138aa2ae1d.tar govuk-mini-environment-admin-e5c3d2979282404e7d89b4facc4e4f138aa2ae1d.tar.gz |
Support 'Stopping' the AWS backend
Which means just destroying the build machine.
-rw-r--r-- | app/controllers/backends/terraform_aws_controller.rb | 4 | ||||
-rw-r--r-- | app/models/backends/terraform_aws/backend_methods.rb | 13 | ||||
-rw-r--r-- | app/views/backends/terraform_aws/show.html.erb | 13 |
3 files changed, 30 insertions, 0 deletions
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 @@ -85,6 +85,19 @@ License along with the GOV.UK Mini Environment Admin. If not, see </p> </li> <li class="list-group-item"> + <%= submit_tag("Stop", + role: 'button', + style: 'margin-bottom: 5px;', + class: 'btn btn-lg btn-warning btn-block') + %> + <p class="list-group-item-text"> + 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. + </p> + </li> + <li class="list-group-item"> <%= submit_tag("Destroy", role: 'button', style: 'margin-bottom: 5px;', |