lxc / terraform-provider-incus

Incus provider for Terraform/OpenTofu
https://linuxcontainers.org/incus
Mozilla Public License 2.0
45 stars 10 forks source link

Enhancement: Ensure instance is up to date with the image #99

Closed cquike closed 1 month ago

cquike commented 1 month ago

We manage a number of incus instances in a cluster with OpenTofu and this incus plugin. The images those instances use are custom ones that are managed by a "cronjob" that in turn uses packer. We would like to have an option to automatically restart the container in case the image it was created from has been updated. By updated I mean that the alias now points to a new image. It would be great if the incus_instance resource would add add an argument to ensure that the container is using the image that the current image alias is now pointing at. If the image hash of the container is not the same as the hash of the image argument, then the container is destroyed and recreated (and started i the running argument is true). The hash of the image used to create the container can be obtained with incus config get my-container volatile.base_image.

I guess that a reasonable expectation is that if the image is specified as a hash then nothing would happen. Also, if image us an alias but it is no longer accessible from the provider remote then nothing happens either.

Thanks!

maveonair commented 1 month ago

So you mean something like image:latest as we know it from Docker? I think that's a bit dangerous, because what would happen is that the instance would be destroyed and recreated with the new image version.

cquike commented 1 month ago

Yes, kind of that. The container would be recreated if the image version is different from the one used to create the container. I agree that's dangerous, but it might be useful in some scenarios to make sure that the containers are up to date. Of course that argument (say synced_image for lack of a better name) would be false by default and only if it is explicitly set to true for a given container then that container is recreated.

maveonair commented 1 month ago

I will close this issue because I don't see this a fit for the Terraform provider. If you think Incus should be able to do this then I ask you to create a feature request for Incus itself.