lxc / terraform-provider-incus

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

Replace `incus_image_publish` with an extended `source` field on `incus_image` #89

Closed stgraber closed 1 month ago

stgraber commented 3 months ago

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.

stgraber commented 3 months ago

Currently, incus_image quite confusingly has a few top-level arguments:

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.

maveonair commented 3 months ago

@stgraber How would the resource definition then look like with the extended source field on incus_image?

stgraber commented 2 months ago

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.

stgraber commented 2 months ago

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.