diff options
author | Christopher Baines <mail@cbaines.net> | 2018-04-07 15:45:00 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2018-04-12 19:05:31 +0100 |
commit | cefa86029c9d4fc4cffaa05d33da9c978dbb1c16 (patch) | |
tree | 32287e4378e255c0937f89177ff5a133e057e029 /terraform | |
parent | 6670c74eae0cae82319365ee53c8ba01db16b758 (diff) | |
download | govuk-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 'terraform')
-rw-r--r-- | terraform/libvirt/backend/main.tf | 20 | ||||
-rw-r--r-- | terraform/libvirt/mini_environment/main.tf (renamed from terraform/libvirt/mini_environment.tf) | 31 |
2 files changed, 43 insertions, 8 deletions
diff --git a/terraform/libvirt/backend/main.tf b/terraform/libvirt/backend/main.tf new file mode 100644 index 0000000..24995e0 --- /dev/null +++ b/terraform/libvirt/backend/main.tf @@ -0,0 +1,20 @@ +variable "uri" { + type = "string" +} + +terraform { + backend "http" {} +} + +provider "libvirt" { + uri = "${var.uri}" +} + +resource "libvirt_network" "vm_network" { + name = "vm_network" + addresses = ["10.0.1.0/24"] +} + +output "network_name" { + value = "${libvirt_network.vm_network.name}" +} diff --git a/terraform/libvirt/mini_environment.tf b/terraform/libvirt/mini_environment/main.tf index 4b9965d..00c3394 100644 --- a/terraform/libvirt/mini_environment.tf +++ b/terraform/libvirt/mini_environment/main.tf @@ -1,11 +1,15 @@ -terraform { - backend "http" {} +variable "backend_remote_state_address" { + type = "string" } variable "machine_name" { type = "string" } +variable "host_name" { + type = "string" +} + variable "uri" { type = "string" } @@ -14,17 +18,27 @@ variable "vm_image_and_system" { type = "string" } +terraform { + backend "http" {} +} + provider "libvirt" { uri = "${var.uri}" } -resource "libvirt_network" "vm_network" { - name = "vm_network" - addresses = ["10.0.1.0/24"] +data "terraform_remote_state" "backend" { + backend = "http" + config { + address = "${var.backend_remote_state_address}" + } +} + +resource "local_file" "dnsmasq-config" { + content = "address=/${var.host_name}/${libvirt_domain.main.network_interface.0.addresses.0}" + filename = "/etc/NetworkManager/dnsmasq.d/${var.host_name}.conf" } -# Create the machine -resource "libvirt_domain" "domain-ubuntu" { +resource "libvirt_domain" "main" { name = "${var.machine_name}" memory = "8196" vcpu = 4 @@ -51,7 +65,8 @@ resource "libvirt_domain" "domain-ubuntu" { } network_interface { - network_name = "${libvirt_network.vm_network.name}" + network_name = "${data.terraform_remote_state.backend.network_name}" + wait_for_lease = true } console { |