File tree Expand file tree Collapse file tree 5 files changed +25
-16
lines changed
examples/terraform-libvirt-instance
modules/terraform-libvirt-instance Expand file tree Collapse file tree 5 files changed +25
-16
lines changed Original file line number Diff line number Diff line change @@ -113,14 +113,16 @@ module "instance_provisioning" {
113113 {
114114 interface_network_name = "default"
115115 interface_mac_address = "52:54:00:12:34:56"
116- interface_addresses = ["192.168.1.2"]
116+ interface_address = "192.168.1.2"
117+ interface_prefix = 24
117118 interface_hostname = "eth0-host"
118119 interface_wait_for_lease = true
119120 },
120121 {
121122 interface_network_name = "default"
122123 interface_mac_address = "52:54:00:65:78:9A"
123- interface_addresses = ["192.168.2.2"]
124+ interface_address = "192.168.2.2"
125+ interface_prefix = 16
124126 interface_hostname = "eth1-host"
125127 interface_wait_for_lease = false
126128 },
Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ module "instance_provisioning" {
1717 sshkey = " ssh-rsa AAAAB3NzaC1yc2EAAA...your-ssh-key-here"
1818 }
1919
20- instance_libvirt_network = " default"
2120 instance_libvirt_pool = " default"
2221 instance_uefi_enabled = true
2322 instance_firmware = " /usr/share/edk2/ovmf/OVMF_CODE.fd"
@@ -26,14 +25,16 @@ module "instance_provisioning" {
2625 {
2726 interface_network_name = " default"
2827 interface_mac_address = " 52:54:00:12:34:56"
29- interface_addresses = [" 192.168.1.2" ]
28+ interface_address = " 192.168.1.2"
29+ interface_prefix = 24
3030 interface_hostname = " eth0-host"
3131 interface_wait_for_lease = true
3232 },
3333 {
3434 interface_network_name = " default"
3535 interface_mac_address = " 52:54:00:65:78:9A"
36- interface_addresses = [" 192.168.2.2" ]
36+ interface_address = " 192.168.2.2"
37+ interface_prefix = 16
3738 interface_hostname = " eth1-host"
3839 interface_wait_for_lease = false
3940 },
Original file line number Diff line number Diff line change @@ -39,7 +39,8 @@ This Terraform module provisions virtual instances with customizable configurati
3939| ---------------------------- | -------------------------------------------------- | -------- | ------------- |
4040| ` interface_network ` | Name of the network to attach the interface to | ✔️ | |
4141| ` interface_mac_address ` | MAC address of the network interface | ❌ | |
42- | ` interface_addresses ` | List of IP addresses for the network interface | ❌ | ` [] ` (empty list) |
42+ | ` interface_address ` | List of IP addresses for the network interface | ❌ | `` (empty list) |
43+ | ` interface_prefix ` | Prefix of the interface address for the network interface | ❌ | 24 |
4344| ` interface_hostname ` | Hostname for the network interface | ❌ | |
4445| ` interface_wait_for_lease ` | Whether to wait for DHCP lease on the interface | ❌ | ` false ` |
4546
@@ -74,14 +75,16 @@ module "instance_provisioning" {
7475 {
7576 interface_network_name = "default"
7677 interface_mac_address = "52:54:00:12:34:56"
77- interface_addresses = ["192.168.1.2"]
78+ interface_address = "192.168.1.2"
79+ interface_prefix = 24
7880 interface_hostname = "eth0-host"
7981 interface_wait_for_lease = true
8082 },
8183 {
8284 interface_network_name = "default"
8385 interface_mac_address = "52:54:00:65:78:9A"
84- interface_addresses = ["192.168.2.2"]
86+ interface_address = "192.168.2.2"
87+ interface_prefix = 16
8588 interface_hostname = "eth1-host"
8689 interface_wait_for_lease = false
8790 },
Original file line number Diff line number Diff line change @@ -139,6 +139,12 @@ resource "libvirt_domain" "libvirt-vm" {
139139 source = { network = { network = iface.interface_network } }
140140 model = { type = " virtio" }
141141 mac = iface.interface_mac_address != null ? { address = iface.interface_mac_address } : null
142+
143+ # Only configure static IP if user specified one, otherwise use DHCP
144+ ip = iface.interface_address != null ? [{
145+ address = iface.interface_address
146+ prefix = iface.interface_prefix
147+ }] : null
142148 }]
143149
144150 graphics = [
Original file line number Diff line number Diff line change @@ -109,16 +109,13 @@ variable "instance_firmware" {
109109
110110variable "instance_network_interfaces" {
111111 type = list (object ({
112- interface_network = string
113- interface_mac_address = optional (string )
114- # Note: The following attributes are not directly supported in v0.9+ devices.interfaces
115- # They would need to be configured via network DHCP or handled differently
116- interface_addresses = optional (list (string ), [])
117- interface_hostname = optional (string )
118- interface_wait_for_lease = optional (bool , true )
112+ interface_network = string
113+ interface_mac_address = optional (string )
114+ interface_address = optional (string )
115+ interface_prefix = optional (number , 24 )
119116 }))
120117 default = [{
121118 interface_network = " default"
122119 }]
123- description = " A list of network interfaces to add to the instance"
120+ description = " A list of network interfaces to add to the instance. Uses DHCP by default, or specify interface_address for static IP assignment. interface_prefix defaults to 24. "
124121}
You can’t perform that action at this time.
0 commit comments