aboutsummaryrefslogtreecommitdiff
path: root/app/models/backends
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-04-07 15:45:00 +0100
committerChristopher Baines <mail@cbaines.net>2018-04-12 19:05:31 +0100
commitcefa86029c9d4fc4cffaa05d33da9c978dbb1c16 (patch)
tree32287e4378e255c0937f89177ff5a133e057e029 /app/models/backends
parent6670c74eae0cae82319365ee53c8ba01db16b758 (diff)
downloadgovuk-mini-environment-admin-cefa86029c9d4fc4cffaa05d33da9c978dbb1c16.tar
govuk-mini-environment-admin-cefa86029c9d4fc4cffaa05d33da9c978dbb1c16.tar.gz
Improve the support for Libvirt
Separate out the backend things, like the virtual network, from the mini environment. This makes it easier to have resources shared between mini environments. Also handle the deployment of this new backend related Terraform configuration.
Diffstat (limited to 'app/models/backends')
-rw-r--r--app/models/backends/terraform_libvirt.rb42
1 files changed, 38 insertions, 4 deletions
diff --git a/app/models/backends/terraform_libvirt.rb b/app/models/backends/terraform_libvirt.rb
index f108560..b069b70 100644
--- a/app/models/backends/terraform_libvirt.rb
+++ b/app/models/backends/terraform_libvirt.rb
@@ -56,7 +56,11 @@ class Backends::TerraformLibvirt < ApplicationRecord
web_domain: "www.#{slug}.#{domain}",
# Assume that this is a local environment, and not externally
# accessible
- use_https: 'development'
+ use_https: 'development',
+ http_ports_mode: 'standard',
+ host_name: "#{slug}.#{domain}",
+ admin_environment_label: mini_environment.name,
+ signon_instance_name: slug
)
end
@@ -80,10 +84,29 @@ class Backends::TerraformLibvirt < ApplicationRecord
end
end
+ def deploy_backend
+ TerraformWorkingDirectory.new(
+ terraform_state_id,
+ 'terraform/libvirt/backend'
+ ).within_working_directory do
+ RubyTerraform.apply(
+ vars: {
+ uri: uri,
+ domain: domain
+ },
+ auto_approve: true
+ )
+ end
+ end
+
+ def terraform_state_id
+ "backend/terraform_libvirt/#{id}"
+ end
+
def within_terraform_working_directory(mini_environment, &block)
TerraformWorkingDirectory.new(
"mini_environment/#{mini_environment.id}",
- 'terraform/libvirt'
+ 'terraform/libvirt/mini_environment'
).within_working_directory(&block)
end
@@ -92,10 +115,21 @@ class Backends::TerraformLibvirt < ApplicationRecord
end
def terraform_variables(mini_environment)
+ slug = mini_environment.name.parameterize
+
{
uri: uri,
- machine_name: mini_environment.name.parameterize,
- vm_image_and_system: mini_environment.backend_data['build_output']
+ machine_name: slug,
+ host_name: "#{slug}.#{domain}",
+ vm_image_and_system: mini_environment.backend_data['build_output'],
+ backend_remote_state_address: (
+ 'http://localhost:3000' +
+ Rails
+ .application
+ .routes
+ .url_helpers
+ .terraform_http_backend_path(terraform_state_id)
+ )
}
end
end