From ec1039c336a9b3f796b3d805312f3b2dc0a0157c Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sat, 23 Jun 2018 13:02:47 +0100 Subject: Support refreshing the state of backends --- app/controllers/backends/terraform_aws_controller.rb | 4 ++++ app/controllers/backends/terraform_libvirt_controller.rb | 4 ++++ app/models/backends/terraform_aws/backend_methods.rb | 11 +++++++++++ app/models/backends/terraform_libvirt/backend_methods.rb | 14 ++++++++++++++ app/views/backends/terraform_aws/show.html.erb | 11 +++++++++++ app/views/backends/terraform_libvirt/show.html.erb | 11 +++++++++++ 6 files changed, 55 insertions(+) (limited to 'app') diff --git a/app/controllers/backends/terraform_aws_controller.rb b/app/controllers/backends/terraform_aws_controller.rb index f11403f..004f601 100644 --- a/app/controllers/backends/terraform_aws_controller.rb +++ b/app/controllers/backends/terraform_aws_controller.rb @@ -69,6 +69,10 @@ class Backends::TerraformAwsController < ApplicationController Backends::TerraformAwsJob.enqueue(@backend.id, :deploy_backend) flash[:notice] = 'Deploying the backend' + when 'Refresh state' + Backends::TerraformAwsJob.enqueue(@backend.id, :refresh_backend_state) + + flash[:notice] = 'Refreshing the backend state information' else flash[:error] = "Unknown action #{action}" end diff --git a/app/controllers/backends/terraform_libvirt_controller.rb b/app/controllers/backends/terraform_libvirt_controller.rb index 1feae41..3a69b5b 100644 --- a/app/controllers/backends/terraform_libvirt_controller.rb +++ b/app/controllers/backends/terraform_libvirt_controller.rb @@ -71,6 +71,10 @@ class Backends::TerraformLibvirtController < ApplicationController Backends::TerraformLibvirtJob.enqueue(@backend.id, :deploy_backend) flash[:notice] = 'Deploying the backend' + when 'Refresh state' + Backends::TerraformLibvirtJob.enqueue(@backend.id, :refresh_backend_state) + + flash[:notice] = 'Refreshing the backend state information' else flash[:error] = "Unknown action #{action}" end diff --git a/app/models/backends/terraform_aws/backend_methods.rb b/app/models/backends/terraform_aws/backend_methods.rb index 8c867d9..f8338a4 100644 --- a/app/models/backends/terraform_aws/backend_methods.rb +++ b/app/models/backends/terraform_aws/backend_methods.rb @@ -55,6 +55,17 @@ module Backends::TerraformAws::BackendMethods end end + def refresh_backend_state + TerraformWorkingDirectory.new( + terraform_state_id, + 'terraform/aws/backend' + ).within_working_directory do + RubyTerraform.refresh( + vars: backend_terraform_variables + ) + end + end + def destroy_backend TerraformWorkingDirectory.new( terraform_state_id, diff --git a/app/models/backends/terraform_libvirt/backend_methods.rb b/app/models/backends/terraform_libvirt/backend_methods.rb index 7595611..9507e2c 100644 --- a/app/models/backends/terraform_libvirt/backend_methods.rb +++ b/app/models/backends/terraform_libvirt/backend_methods.rb @@ -49,6 +49,20 @@ module Backends::TerraformLibvirt::BackendMethods end end + def refresh_backend_state + TerraformWorkingDirectory.new( + terraform_state_id, + 'terraform/libvirt/backend' + ).within_working_directory do + RubyTerraform.refresh( + vars: { + uri: uri, + domain: domain + } + ) + end + end + def backend_terraform_states TerraformState.where( state_id: terraform_state_id diff --git a/app/views/backends/terraform_aws/show.html.erb b/app/views/backends/terraform_aws/show.html.erb index eca5d3f..f468567 100644 --- a/app/views/backends/terraform_aws/show.html.erb +++ b/app/views/backends/terraform_aws/show.html.erb @@ -52,6 +52,17 @@ License along with the GOV.UK Mini Environment Admin. If not, see class: 'btn btn-lg btn-danger') %> <% end %> + + <%= form_with( + url: perform_action_terraform_aws_backend_path(@backend), + local: true, + method: "post" + ) do %> + <%= submit_tag("Refresh state", + role: 'button', + class: 'btn btn-lg btn-info') + %> + <% end %>
<%= render( diff --git a/app/views/backends/terraform_libvirt/show.html.erb b/app/views/backends/terraform_libvirt/show.html.erb index 5b2213b..f97b4e2 100644 --- a/app/views/backends/terraform_libvirt/show.html.erb +++ b/app/views/backends/terraform_libvirt/show.html.erb @@ -52,6 +52,17 @@ License along with the GOV.UK Mini Environment Admin. If not, see class: 'btn btn-lg btn-danger') %> <% end %> + + <%= form_with( + url: perform_action_terraform_libvirt_backend_path(@backend), + local: true, + method: "post" + ) do %> + <%= submit_tag("Refresh state", + role: 'button', + class: 'btn btn-lg btn-info') + %> + <% end %>
<%= render( -- cgit v1.2.3