Terraform throws an error generating the output if an IP address can't be read
seumasdunlop opened this issue · comments
If the VM doesn't get assigned an IP address for any reason terraform will throw an error when trying to read the IP address when generating the output.
Fix in terraform/modules/vm/output.tf
ip = try(libvirt_domain.vm_domain.network_interface.0.addresses.0, null)
Hi,
your PR would fix this issue, but could you help me understand why this is an issue in the first place?
If Terraform can not retrieve an IP address, the cluster setup is guaranteed to fail because the target host must have an associated IP address. Otherwise, the Ansible script does not know where to connect to configure the virtual machine.
I don't remember the details I'm afraid but it's something that I hit when testing. The IP would have been assigned statically and I think it was still reachable and the rest of the script worked after this change. I need to spend some time understanding how the IP address published by libvirt (and read by terraform) actually works because I thought there were some inconsistencies there but I haven't had a chance. Apologies this is so vague.
Regarding this specific change, my thoughts are that terraform should never throw an error like this and if not having an IP is a fatal error then it should be detected at a higher level.