From 59a3fa8f91b7d94419cfbf4113540eb956c1e868 Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Sat, 11 Mar 2023 19:05:42 +0100 Subject: [PATCH] parameterize ip --- main.tf | 6 +++--- network_config.cfg.tftpl | 2 +- variables.tf | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/main.tf b/main.tf index dd15196..2b17a72 100644 --- a/main.tf +++ b/main.tf @@ -29,7 +29,7 @@ resource "libvirt_cloudinit_disk" "cloudinit" { name = "${var.name}.iso" pool = "init" user_data = templatefile("cloud_init.cfg.tftpl", { name = var.name, host_public_key = var.host_public_key }) - network_config = templatefile("network_config.cfg.tftpl", {}) + network_config = templatefile("network_config.cfg.tftpl", { internal_ip = var.internal_ip}) } resource "libvirt_domain" "ubuntu" { @@ -44,13 +44,13 @@ resource "libvirt_domain" "ubuntu" { network_interface { network_name = "dmzbr" hostname = var.name - addresses = ["192.168.30.7/24"] + addresses = ["${var.internal_ip}/24"] mac = "ca:fe:c0:ff:ee:07" } cloudinit = libvirt_cloudinit_disk.cloudinit.id provisioner "local-exec" { - command = "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -T 60 -u root -i '192.168.30.7,' ansible.yml" + command = "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -T 60 -u root -i '${var.internal_ip}' ansible.yml" } } diff --git a/network_config.cfg.tftpl b/network_config.cfg.tftpl index 62fb8d4..762f752 100644 --- a/network_config.cfg.tftpl +++ b/network_config.cfg.tftpl @@ -3,7 +3,7 @@ ethernets: ens3: dhcp4: false addresses: - - "192.168.30.7/24" + - "${internal_ip}/24" routes: - to: 0.0.0.0/0 via: 192.168.30.1 diff --git a/variables.tf b/variables.tf index 6be2cc2..a603e43 100644 --- a/variables.tf +++ b/variables.tf @@ -11,3 +11,7 @@ variable "host_public_key" { type = string default = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOodpLr+FDRyKyHjucHizNLVFHZ5AQmE9GmxMnOsSoaw pimkunis@thinkpadpim" } + +variable "internal_ip" { + default = "192.168.30.7" +}