diff --git a/templates/libvirt/vms.tf.j2 b/templates/libvirt/vms.tf.j2 index 60b54f4..5c85e1b 100644 --- a/templates/libvirt/vms.tf.j2 +++ b/templates/libvirt/vms.tf.j2 @@ -25,6 +25,7 @@ resource "libvirt_volume" "{{ disk.volume_id }}" { # VM {{ vm.name }} specification resource "libvirt_domain" "{{ vm.name }}" { name = "{{ vm.name }}" + running = "{{ vm.running | default('true') | lower() }}" memory = "{{ vm.memory }}" vcpu = "{{ vm.vcpu }}" @@ -37,21 +38,6 @@ resource "libvirt_domain" "{{ vm.name }}" { cloudinit = libvirt_cloudinit_disk.{{ vm.cloudinit_disk }}.id {% endif %} -{% for interface in vm.network_interfaces %} - network_interface { - network_id = libvirt_network.{{ interface.network_id }}.id -{% if interface.addresses is defined %} - addresses = [{% for address in interface.addresses %}"{{ address }}"{%- if not loop.last -%}, {%- endif -%}{% endfor %}] -{% endif %} -{% if interface.mac is defined %} - mac = "{{ interface.mac }}" -{% endif %} -{% if interface.wait_for_lease is defined %} - wait_for_lease = {{ interface.wait_for_lease }} -{% endif %} - } -{% endfor %} - {% for disk in vm.disks %} disk { volume_id = libvirt_volume.{{ disk.volume_id }}.id @@ -79,5 +65,22 @@ resource "libvirt_domain" "{{ vm.name }}" { } {% endfor %} {% endif %} + +{% if vm.running | default('true') | bool() %} +{% for interface in vm.network_interfaces %} + network_interface { + network_id = libvirt_network.{{ interface.network_id }}.id +{% if interface.addresses is defined %} + addresses = [{% for address in interface.addresses %}"{{ address }}"{%- if not loop.last -%}, {%- endif -%}{% endfor %}] +{% endif %} +{% if interface.mac is defined %} + mac = "{{ interface.mac }}" +{% endif %} +{% if interface.wait_for_lease is defined %} + wait_for_lease = {{ interface.wait_for_lease }} +{% endif %} + } +{% endfor %} +{% endif %} } {% endfor %}