aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-06-23 13:02:47 +0100
committerChristopher Baines <mail@cbaines.net>2018-06-23 21:16:39 +0100
commitec1039c336a9b3f796b3d805312f3b2dc0a0157c (patch)
tree4b58fdd56e1297556a185e8e91c3a7aee11b3dad /app
parent7bc196dabd3186793880c6d833392e8d8da3d191 (diff)
downloadgovuk-mini-environment-admin-ec1039c336a9b3f796b3d805312f3b2dc0a0157c.tar
govuk-mini-environment-admin-ec1039c336a9b3f796b3d805312f3b2dc0a0157c.tar.gz
Support refreshing the state of backends
Diffstat (limited to 'app')
-rw-r--r--app/controllers/backends/terraform_aws_controller.rb4
-rw-r--r--app/controllers/backends/terraform_libvirt_controller.rb4
-rw-r--r--app/models/backends/terraform_aws/backend_methods.rb11
-rw-r--r--app/models/backends/terraform_libvirt/backend_methods.rb14
-rw-r--r--app/views/backends/terraform_aws/show.html.erb11
-rw-r--r--app/views/backends/terraform_libvirt/show.html.erb11
6 files changed, 55 insertions, 0 deletions
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 %>
</div>
<div class="col-md-6">
<%= 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 %>
</div>
<div class="col-md-6">
<%= render(