aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-06-03 14:16:58 +0100
committerChristopher Baines <mail@cbaines.net>2018-06-03 14:16:58 +0100
commitc087576f60213b3dce45074b79b13c752f070d5c (patch)
treea4d7c2e2092538c99a4dd16b06217ef462e8ebdc
parentd5616c7f0f9f36d640ad60a69d3b235efabe77e4 (diff)
downloadgovuk-mini-environment-admin-c087576f60213b3dce45074b79b13c752f070d5c.tar
govuk-mini-environment-admin-c087576f60213b3dce45074b79b13c752f070d5c.tar.gz
Add support for destroying Terraform AWS backends
-rw-r--r--app/models/backends/terraform_aws.rb12
-rw-r--r--lib/tasks/backend.rake7
2 files changed, 19 insertions, 0 deletions
diff --git a/app/models/backends/terraform_aws.rb b/app/models/backends/terraform_aws.rb
index 204eaf0..299b5b5 100644
--- a/app/models/backends/terraform_aws.rb
+++ b/app/models/backends/terraform_aws.rb
@@ -127,6 +127,18 @@ class Backends::TerraformAws < ApplicationRecord
end
end
+ def destroy_backend
+ TerraformWorkingDirectory.new(
+ terraform_state_id,
+ 'terraform/aws/backend'
+ ).within_working_directory do
+ RubyTerraform.destroy(
+ vars: backend_terraform_variables,
+ force: true
+ )
+ end
+ end
+
def available_data_snapshots
GovukGuix::DataSnapshot.where(backend: self)
end
diff --git a/lib/tasks/backend.rake b/lib/tasks/backend.rake
index b2db905..c23a3df 100644
--- a/lib/tasks/backend.rake
+++ b/lib/tasks/backend.rake
@@ -15,5 +15,12 @@ namespace :backend do
.find(args.backend_id)
.deploy_backend
end
+
+ desc 'Destroy a Terraform AWS backend'
+ task :destroy, [:backend_id] => :environment do |t, args|
+ Backends::TerraformAws
+ .find(args.backend_id)
+ .destroy_backend
+ end
end
end