OpenTofu/Terraform config equivalent of launch --network


I have a lxdbr0 network and a macvlan network set up on my LXD. I can launch a new instance and put it on the macvlan network with:

lxc launch ubuntu:22.04 [remote]:test --network macvlan`

and it shows if I look at:

lxc network show [remote]:macvlan

I am trying to find the equivalent configuration to use with OpenTofu/Terraform:

The only info in there I could see on configuring the network was:
which didn’t sound like my situation, but I tried anyway:

  config = {
    "user.access_interface" = "macvlan"

and it didn’t work. I suspect I could do it with a profile, but I didn’t want to do that at this stage if I could avoid it. Thanks!

Try using the section, and match it with the output of lxc config show <instance> --expanded for an instance connected to a macvlan network.

The type will be nic, then the device’s properties will need nictype: macvlan and parent: <parent interface> at least.

Haha, sorry Tom. I just made this work myself after finding that page and this and was coming here to update the answer for everyone.

Yes, it seems to work with a device block on the instance:

  device {
    name = "eth0"
    type = "nic"
    properties = {
      network = "macvlan"

Hopefully this makes it slightly quicker for the next person out there searching.

1 Like