terraform-provider-lxd icon indicating copy to clipboard operation
terraform-provider-lxd copied to clipboard

Bug: terraform-provider-lxd provider fails to create the instance in the project not equal to "default" if image fingerprint assigned to `image` attribute instead of `image name

Open tregubovav-dev opened this issue 7 months ago • 3 comments

Issue

terraform-provider-lxd provider fails to create the instance in the project not equal to "default" if image fingerprint assigned to image attribute instead of image name. Instance creation fails in this case with message like below:

lxd_instance.test: Creating...
╷
│ Error: Failed to retrieve image info for instance "test"
│
│   with lxd_instance.test,
│   on install_via_image.tf line 17, in resource "lxd_instance" "test":
│   17: resource "lxd_instance" "test" {
│
│ Image not found

Steps to reproduce

  1. create project test with default options using command lxc project create test
  2. deploy infrastructure using terraform or open-tofu using configurations below

Failed configuration

terraform {
  required_providers {
    lxd = {
      source = "terraform-lxd/lxd"
      version = "2.1.0"
    }
  }
}

resource "lxd_cached_image" "alpine" {
    source_remote       = "images"
    source_image        = "alpine/3.18"
    aliases             = ["alpine-3.18"]
    project             = "test"
}

resource "lxd_instance" "test" {
    name        = "test"
    image       = lxd_cached_image.alpine.fingerprint
    project     = "test"
}

Working configurations

terraform {
  required_providers {
    lxd = {
      source = "terraform-lxd/lxd"
      version = "2.1.0"
    }
  }
}

resource "lxd_cached_image" "alpine" {
    source_remote       = "images"
    source_image        = "alpine/3.18"
    aliases             = ["alpine-3.18"]
    project             = "default"
}

resource "lxd_instance" "test" {
    name        = "test"
    image       = lxd_cached_image.alpine.fingerprint
    project     = "default"
}

OR

terraform {
  required_providers {
    lxd = {
      source = "terraform-lxd/lxd"
      version = "2.1.0"
    }
  }
}

resource "lxd_cached_image" "alpine" {
    source_remote       = "images"
    source_image        = "alpine/3.18"
    aliases             = ["alpine-3.18"]
}

resource "lxd_instance" "test" {
    name        = "test"
    image       = lxd_cached_image.alpine.fingerprint
}

lxd_cached_image resource documentation shows how to use 'lxd_instance' with 'lxd_cached_image` resource. However it does not work with non-"default" project.

I also tried to assign short or long hardcoded 'fingerprint' value of existing image getting by command lxc image list --project test with the same result.

[terraform-provider-incus) has the same issue.

tregubovav-dev avatar Jul 02 '24 19:07 tregubovav-dev