diff options
author | Christopher Baines <mail@cbaines.net> | 2018-06-23 11:40:52 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2018-06-23 21:16:39 +0100 |
commit | 7bc196dabd3186793880c6d833392e8d8da3d191 (patch) | |
tree | 027f3faffdfeda646cb4535b0df8c59e338c68a3 /app/models | |
parent | 76f7351c19777379d4d42a348a7f8da735a30649 (diff) | |
download | govuk-mini-environment-admin-7bc196dabd3186793880c6d833392e8d8da3d191.tar govuk-mini-environment-admin-7bc196dabd3186793880c6d833392e8d8da3d191.tar.gz |
Add support for managing Terraform AWS backends from the show page
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/backends/terraform_aws.rb | 3 | ||||
-rw-r--r-- | app/models/backends/terraform_aws/backend_methods.rb | 20 |
2 files changed, 23 insertions, 0 deletions
diff --git a/app/models/backends/terraform_aws.rb b/app/models/backends/terraform_aws.rb index 4db7c51..d0655ee 100644 --- a/app/models/backends/terraform_aws.rb +++ b/app/models/backends/terraform_aws.rb @@ -39,6 +39,9 @@ require 'ruby_terraform' class Backends::TerraformAws < ApplicationRecord + include MiniEnvironmentMethods + include BackendMethods + has_many :mini_environments, as: :backend self.table_name = 'terraform_aws_backends' diff --git a/app/models/backends/terraform_aws/backend_methods.rb b/app/models/backends/terraform_aws/backend_methods.rb index 726494c..8c867d9 100644 --- a/app/models/backends/terraform_aws/backend_methods.rb +++ b/app/models/backends/terraform_aws/backend_methods.rb @@ -70,4 +70,24 @@ module Backends::TerraformAws::BackendMethods def available_data_snapshots GovukGuix::DataSnapshot.where(backend: self) end + + def backend_terraform_states + TerraformState.where( + state_id: terraform_state_id + ) + end + + def status + latest_terraform_state = backend_terraform_states.order(:id).last + + running = ( + latest_terraform_state && + (latest_terraform_state.output_value('backend_up') == 'true') + ) + + { + running: running, + updated_at: latest_terraform_state.try(:created_at) + } + end end |