From 95dce43d40f90e5422cd0854ca68ad3fa4513e8c Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Thu, 16 Mar 2023 23:29:28 +0100 Subject: [PATCH] replace VM if cloudinit image is replaced --- cloud_init.cfg.tftpl | 6 +----- dnsmasq.conf | 6 +++--- main.tf | 11 ++++++++--- variables.tf | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/cloud_init.cfg.tftpl b/cloud_init.cfg.tftpl index d3c1922..742a0a9 100644 --- a/cloud_init.cfg.tftpl +++ b/cloud_init.cfg.tftpl @@ -1,11 +1,7 @@ #cloud-config -hostname: hermes +hostname: "${name}" manage_etc_hosts: true ssh_pwauth: false disable_root: false ssh_authorized_keys: - "${host_public_key}" -chpasswd: - list: | - root:root - expire: False diff --git a/dnsmasq.conf b/dnsmasq.conf index 5f219c9..2152d52 100644 --- a/dnsmasq.conf +++ b/dnsmasq.conf @@ -15,9 +15,9 @@ domain=dmz # IPv4 DHCP range dhcp-range=192.168.30.100,192.168.30.200,infinite # Predefined DHCP hosts -dhcp-host=b8:27:eb:b9:ab:e2,esrom,192.168.30.2 -dhcp-host=b4:2e:99:77:1b:da,max,192.168.30.3 -dhcp-host=d8:5e:d3:47:33:6e,lewis,192.168.30.6 +dhcp-host=b8:27:eb:b9:ab:e2,esrom +dhcp-host=b4:2e:99:77:1b:da,max +dhcp-host=d8:5e:d3:47:33:6e,lewis # Advertise router dhcp-option=3,192.168.30.1 # Always send the IPv6 DNS server address (this machine) diff --git a/main.tf b/main.tf index 30ea7dc..cb13fed 100644 --- a/main.tf +++ b/main.tf @@ -43,9 +43,8 @@ resource "libvirt_domain" "ubuntu" { network_interface { bridge = "dmzbr" - hostname = "hermes" - /* addresses = ["${var.internal_ip}/24"] */ - mac = "ca:fe:c0:ff:ee:07" + hostname = var.name + mac = "CA:FE:C0:FF:EE:07" } cloudinit = libvirt_cloudinit_disk.cloudinit.id @@ -57,4 +56,10 @@ resource "libvirt_domain" "ubuntu" { ANSIBLE_HOST_KEY_CHECKING = "False" } } + + lifecycle { + replace_triggered_by = [ + libvirt_cloudinit_disk.cloudinit.id + ] + } } diff --git a/variables.tf b/variables.tf index 352093d..66e1760 100644 --- a/variables.tf +++ b/variables.tf @@ -1,5 +1,5 @@ variable "name" { - default = "dmzdns" + default = "hermes" } variable "libvirt_endpoint" {