Static IPv4 for instance for Terraform Incus provider

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?

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.

Thanks for your response :slight_smile:
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.

Maybe try “ipv4.address”, properties with a dot in them may need quoting.

Thank you it’s working now! :smiley: