support fixed ip address

This commit is contained in:
Pim Kunis 2023-04-07 18:05:37 +02:00
parent 8b6c42e1c5
commit 0096b77f3d
4 changed files with 24 additions and 9 deletions

View file

@ -1,7 +0,0 @@
version: 2
ethernets:
ens3:
dhcp4: true
routes:
- to: 0.0.0.0/0
via: 192.168.30.1

View file

@ -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

View file

@ -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" {

View file

@ -56,6 +56,11 @@ variable "ca_host" {
}
variable "data_disk" {
type = string
type = string
default = null
}
variable "fixed_address" {
type = string
default = null
}