Skip to content

Commit

Permalink
Libvirt: enable running parameter for domain
Browse files Browse the repository at this point in the history
This commit enables the "running" (true by default) parameter for the domain
that will define whether or not the domain should be started.
NOTE: this will omit from the network configuration, otherwise the VM will
always be turned up.
  • Loading branch information
rascasoft committed Mar 25, 2024
1 parent 6fe3a76 commit 63fd5d2
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions templates/libvirt/vms.tf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"

Expand All @@ -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
Expand Down Expand Up @@ -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 %}

0 comments on commit 63fd5d2

Please sign in to comment.