clemuscle
(Clemuscle)
October 22, 2024, 9:50am
1
Hello,
I was wondering if there was a way to apply a static address to an instance by using the provider Incus in Terraform.
I know that the command works:
incus config device set <instance_name> <nic_name> ipv4.address=<ipv4_address>
Followed by a restart of the instance.
But is there a prettier way to do it?
stgraber
(Stéphane Graber)
October 22, 2024, 6:29pm
2
If you define your instance through Terraform, then simply define its network interface in the devices list and set ipv4.address
to the value you want.
clemuscle
(Clemuscle)
October 23, 2024, 6:28pm
3
Thanks for your response
So i tried to simply set the ipv4 address but here’s the output:
$ cat main.tf
terraform {
required_providers {
incus = {
source = "lxc/incus"
}
}
}
provider "incus" {
}
resource "incus_network" "test_network" {
name = "test_network"
description = "Réseau de test"
config = {
"ipv4.address" = "10.10.100.1/24"
"ipv4.nat" = "true"
"ipv6.address" = "none"
}
}
resource "incus_instance" "test" {
name = "test"
image = "images:debian/12/cloud"
ephemeral = false
type = "virtual-machine"
device {
name = "eth0"
type = "nic"
properties = {
nictype = "bridged"
parent = incus_network.test_network.name
ipv4.address = "10.10.100.50"
}
}
}
$ tofu apply
╷
│ Error: Reference to undeclared resource
│
│ on main.tf line 36, in resource "incus_instance" "test":
│ 36: ipv4.address = "10.10.100.50"
│
│ A managed resource "ipv4" "address" has not been declared in the root module.
╵
So I use OpenTofu but it’s clearly the same to Terraform.
Maybe I misunderstand the way to use the provider correctly.
stgraber
(Stéphane Graber)
October 23, 2024, 9:00pm
4
Maybe try “ipv4.address”, properties with a dot in them may need quoting.
clemuscle
(Clemuscle)
October 25, 2024, 8:24am
5
Thank you it’s working now!