terraform-provider-incus
terraform-provider-incus copied to clipboard
Replace `incus_image_publish` with an extended `source` field on `incus_image`
We shouldn't be abusing resources for isolated one-time actions.
incus_image already supports copying an image from a remote server, so it would make sense to have it grow the ability to make an image from an instance or instance snapshot.
This would line it up with #80 too.
Currently, incus_image quite confusingly has a few top-level arguments:
- source_image
- source_remote
- copy_aliases
Which all refer to the copy of an image from a remote server when there are in fact other ways to get an image. The user could be directly uploading a local image (currently unsupported by the provider) or could create an image from an existing instance or snapshot.
I think it'd make sense to have a more structured source argument which we can then use to either point to an existing image or to an instance/snapshot.
@stgraber How would the resource definition then look like with the extended source field on incus_image?
We currently have:
resource "incus_image" "noble" {
remote = "my-server"
project = "my-project"
aliases = ["foo", "bar"]
source_remote = "images"
source_image = "ubuntu/24.04/amd64"
copy_aliases = False
type = "container"
}
I think the above would turn into:
resource "incus_image" "noble" {
remote = "my-server"
project = "my-project"
aliases = ["foo", "bar"]
source_image = {
remote = "images"
name = "ubuntu/24.04/amd64"
type = "container"
copy_aliases = False
}
}
or
resource "incus_image" "my-image" {
remote = "my-server"
project = "my-project"
aliases = ["foo", "bar"]
source_instance = {
name = "bar"
snapshot = "snap0"
}
}
And we'd make it so you need either source_instance or source_image to be set but having both set together would be invalid.
The source_instance here basically mirrors the one proposed in #80 but minus the project field as I don't believe we can create an image from an instance in a different project.