I’m trying to import existing incus instances into Tofu (Terraform), but there is no “image” specification generated. When I add the image to the resource specification, tofu wants to repave everything. The same thing goes at least for IP addresses. What’s the way around here, manually mucking around with the terraform.tfstate file, or are there alternatives? Does an incus instance, or the system, “know” which image the instance was created from?
I’m not sure this is the right forum to ask, but could not think of a better one. Feel free to redirect as appropriate.
I’m using the 0.3.1 version of the Terraform provider together with OpenTofu v1.10.5.
import {
to = incus_instance.i-debian
id = "i-debian"
}
resource "incus_instance" "i-debian" {
name = "i-debian"
}
import {
to = incus_instance.i-test-vm
id = "i-test-vm"
}
resource "incus_instance" "i-test-vm" {
name = "i-test-vm"
type = "virtual-machine"
}
where i-debian is a container, and i-test-vm is a VM. Initially, I didn’t have the ‘type=”virtual-machine” parameter set in the resource, and then it said that it needed to destroy and re-create this to make the VM into a container. My original expectation was that the resource would be populated with all the attributes of the object in incus.
That’s not really what an import does, tofu import allows you to link an existing object to its definition. It won’t modify the .tf for you.
Basically it lets you fill in your entire infrastructure through .tf files, then lets you import what you already have so tofu plan doesn’t fail due to a bunch of stuff already existing in the target environment.
So normally you’d create a full populated incus_instance resource, then run tofu import and finally tofu plan to confirm that your local definition in .tf matches up with what’s on the target and that you’re all good.