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