diff --git a/files/network_config.cfg b/files/network_config.cfg deleted file mode 100644 index e488916..0000000 --- a/files/network_config.cfg +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -ethernets: - ens3: - dhcp4: true - routes: - - to: 0.0.0.0/0 - via: 192.168.30.1 diff --git a/files/network_config.cfg.tftpl b/files/network_config.cfg.tftpl new file mode 100644 index 0000000..930e15d --- /dev/null +++ b/files/network_config.cfg.tftpl @@ -0,0 +1,14 @@ +version: 2 +ethernets: + ens3: +%{ if fixed_address } + dhcp4: false + addresses: + - "${fixed_address}" +%{ else } + dhcp4: true +%{ endif } + dhcp4: true + routes: + - to: 0.0.0.0/0 + via: 192.168.30.1 diff --git a/main.tf b/main.tf index a21f3d4..3c6f055 100644 --- a/main.tf +++ b/main.tf @@ -16,6 +16,9 @@ locals { private_key = tls_private_key.debian.private_key_openssh, data_disk = var.data_disk != null }) + cloudinit_network_config = templatefile("${path.module}/files/network_config.cfg.tftpl", { + fixed_address = var.fixed_address + }) } resource "tls_private_key" "debian" { @@ -66,7 +69,7 @@ resource "libvirt_cloudinit_disk" "debian" { name = "${var.name}.iso" pool = var.cloudinit_pool user_data = local.cloudinit_user_data - network_config = file("${path.module}/files/network_config.cfg") + network_config = local.cloudinit_network_config } resource "libvirt_domain" "debian" { diff --git a/variables.tf b/variables.tf index 4353bd3..d728190 100644 --- a/variables.tf +++ b/variables.tf @@ -56,6 +56,11 @@ variable "ca_host" { } variable "data_disk" { - type = string + type = string + default = null +} + +variable "fixed_address" { + type = string default = null }