aboutsummaryrefslogtreecommitdiff
path: root/app/jobs
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-02-06 23:32:48 +0000
committerChristopher Baines <mail@cbaines.net>2018-03-29 07:30:29 +0100
commit700b8b0a112fa976b9850418a7f0c71d95b6dd79 (patch)
tree6e0b4b20f3bd319c4d70b5e363c521ed3c19bdb7 /app/jobs
parent2d7bc302ad6d15461a10a67bd5e7e83e3dda279b (diff)
downloadgovuk-mini-environment-admin-700b8b0a112fa976b9850418a7f0c71d95b6dd79.tar
govuk-mini-environment-admin-700b8b0a112fa976b9850418a7f0c71d95b6dd79.tar.gz
AWS related tweaks
Diffstat (limited to 'app/jobs')
-rw-r--r--app/jobs/destroy_job.rb26
-rw-r--r--app/jobs/setup_job.rb40
2 files changed, 51 insertions, 15 deletions
diff --git a/app/jobs/destroy_job.rb b/app/jobs/destroy_job.rb
new file mode 100644
index 0000000..7f13fdd
--- /dev/null
+++ b/app/jobs/destroy_job.rb
@@ -0,0 +1,26 @@
+require 'ruby_terraform'
+
+class DestroyJob < TerraformJob
+ @retry_interval = 30
+
+ def run_terraform
+ puts "Destroying #{@mini_environment.name}"
+
+ Dir.chdir('terraform/aws') do
+ RubyTerraform.destroy(
+ vars: {
+ aws_region: 'eu-west-1',
+ slug: @mini_environment.name.parameterize,
+ ssh_public_key: ssh_public_key,
+ },
+ force: true
+ )
+ end
+ end
+
+ def ssh_public_key
+ File.open("#{ENV['HOME']}/.ssh/id_rsa.pub") do |file|
+ file.readline()
+ end
+ end
+end
diff --git a/app/jobs/setup_job.rb b/app/jobs/setup_job.rb
index 6b4f9fe..6791dd6 100644
--- a/app/jobs/setup_job.rb
+++ b/app/jobs/setup_job.rb
@@ -1,24 +1,34 @@
require 'ruby_terraform'
class SetupJob < TerraformJob
+ @retry_interval = 30
+
def run_terraform
puts "Setting up #{@mini_environment.name}"
- RubyTerraform.init(
- source: 'terraform/aws',
- path: 'terraform/aws',
- backend: true,
- backend_config: {
- address: 'http://localhost:3000' + Rails.application.routes.url_helpers.terraform_http_backend_path
- }
- )
+ Dir.chdir('terraform/aws') do
+ RubyTerraform.init(
+ backend: true,
+ backend_config: {
+ address: 'http://localhost:3000' + Rails.application.routes.url_helpers.terraform_http_backend_path
+ }
+ )
+
+ RubyTerraform.apply(
+ directory: 'mini_environment',
+ vars: {
+ aws_region: 'eu-west-1',
+ slug: @mini_environment.name.parameterize,
+ ssh_public_key: ssh_public_key,
+ },
+ auto_approve: true
+ )
+ end
+ end
- RubyTerraform.apply(
- directory: 'terraform/aws',
- vars: {
- slug: @mini_environment.name.parameterize
- },
- auto_approve: true
- )
+ def ssh_public_key
+ File.open("#{ENV['HOME']}/.ssh/id_rsa.pub") do |file|
+ file.readline()
+ end
end
end