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

Failing when supplying empty block storage for zfs

Open jseravalli opened this issue 1 year ago • 1 comments

Hi! :) I'm setting up a local lxd with a storage pool off a secondary drive in /dev/sbd1 but when I'm trying to create the pool I get the following error:

lxd_storage_pool.data1: Creating...
lxd_storage_pool.data1: Still creating... [10s elapsed]
lxd_storage_pool.data1: Still creating... [20s elapsed]
lxd_storage_pool.data1: Still creating... [30s elapsed]
lxd_storage_pool.data1: Still creating... [40s elapsed]
lxd_storage_pool.data1: Still creating... [50s elapsed]
lxd_storage_pool.data1: Still creating... [1m0s elapsed]
lxd_storage_pool.data1: Still creating... [1m10s elapsed]
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to lxd_storage_pool.data1, provider
│ "provider[\"registry.terraform.io/terraform-lxd/lxd\"]" produced an
│ unexpected new value: .config["source"]: was cty.StringVal("/dev/sdb1"),
│ but now cty.StringVal("data1").
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.
╵
make: *** [apply] Error 1

My terraform looks like:

resource "lxd_storage_pool" "data1" {
  name   = "data1"
  driver = "zfs"

  config = {
    "source" = "/dev/sdb1" 
  }
}

It kinda makes sense since the lxd pool is created like so:

$ lxc storage list
+-------+--------+--------+-------------+---------+---------+
| NAME  | DRIVER | SOURCE | DESCRIPTION | USED BY |  STATE  |
+-------+--------+--------+-------------+---------+---------+
| data1 | zfs    | data1  |             | 3       | CREATED |
+-------+--------+--------+-------------+---------+---------+

my workaround is that I untaint the resource and then I modify the config to match lxc:

resource "lxd_storage_pool" "data1" {
  name   = "data1"
  driver = "zfs"

  config = {
    "source" = "data1" 
  }
}

And it works, but I figure a report wouldn't hurt

jseravalli avatar Feb 17 '24 20:02 jseravalli

Hi, thanks for reporting this issue (and sorry for late response).

From the above error we can see that Terraform is applying the correct value (/dev/sdb1), but LXD changes it to the zpool name (data1) which produces an inconsistent result (the result does not equal the initial plan). Seems that we will have to add some exceptions when parsing pool's source.

MusicDin avatar Feb 26 '24 18:02 MusicDin

No worries, actually sorry for my late response too 😅

point me in the right direction and I think I should be able to throw a PR fixing it

jseravalli avatar Mar 08 '24 20:03 jseravalli