jtopjian / terraform-provider-lxc

Terraform Provider Plugin for LXC
43 stars 6 forks source link

Some Error Log appreciated #4

Open changwuf31 opened 9 years ago

changwuf31 commented 9 years ago

Hi, I'm trying this provider on ubuntu 14.04, install lxc via ppa (v1.1.2)

Below is my config file

provider "lxc" {
  lxc_path = "/var/lib/lxc"
}
resource "lxc_container" "nat" {
  name = "nat"
  backend = "lvm"
  template_name = "ubuntu-cloud"
  template_release = "trusty"
  template_arch = "amd64"
  template_extra_args = ["--auth-key", "~/.ssh/lxc.pub"]
  options {
    fssize = "8G"
    fstype = "ext4"
    logfile = "/tmp/lxc.log"
    vgname = "vg-lxc"
    thinpool = "lv-lxc"
  }

  network_interface {
    type = "veth"
    options {
      link = "lxcbr0"
      flags = "up"
      hwaddr = "00:16:3e:xx:xx:xx"
    }
  }
}

which generates:

lxc_container.nat: Error: 1 error(s) occurred:

* creating the container failed
Error applying plan:

1 error(s) occurred:

* 1 error(s) occurred:

* 1 error(s) occurred:

* creating the container failed

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

When I try manually via lxc-create

lxc-create -t ubuntu-cloud -n nat -B lvm --fssize=8G --fstype=ext4 --vgname=vg-lxc --thinpool=lv-lxc -- -r trusty -a amd64

The container is created successfully.

Is there any way we can debug the error ? Any help appreciated.

Thanks

jtopjian commented 9 years ago

Thanks for letting me know about this.

Can you prefix TF_LOG=DEBUG to the start of the terraform command and copy the output to a gist? There's going to be a lot of output, so maybe redirect it to a file first.

changwuf31 commented 9 years ago

Here is the gist file https://gist.github.com/changwuf31/d34cb97b27beee3ee7ab

Thank you for sharing this :+1:

jtopjian commented 9 years ago

OK, so it looks like the failure happened here:

2015/06/27 16:15:16 terraform-provider-lxc: 2015/06/27 16:15:16 [INFO] Attempting to create container abc
2015/06/27 16:15:16 terraform-provider-lxc: lxc_container: lxccontainer.c: do_bdev_create: 838 Failed to create backing store type lvm
2015/06/27 16:15:16 terraform-provider-lxc: lxc_container: lxccontainer.c: lxcapi_create: 1320 Error creating backing store type lvm for abc

Something to try:

The keys in the options parameter must match valid keys that would go in an lxc configuration file. They are not one-to-one mappings to what would be on the command line. See man lxc.container.conf and man lxc.system.conf for more information.

If that doesn't work, I'll have to see how global/system-level options can be defined using the golang lxc binaries.

changwuf31 commented 9 years ago

Still got this error:

2015/06/28 15:04:17 terraform-provider-lxc: 2015/06/28 15:04:17 [INFO] Attempting to create container abc
2015/06/28 15:04:17 terraform-provider-lxc: lxc_container: lxccontainer.c: do_bdev_create: 838 Failed to create backing store type lvm
2015/06/28 15:04:17 terraform-provider-lxc: lxc_container: lxccontainer.c: lxcapi_create: 1320 Error creating backing store type lvm for abc

with this config file

resource "lxc_container" "abc" {
  name = "abc"
  backend = "lvm"
  template_name = "ubuntu-cloud"
  template_release = "trusty"
  template_arch = "amd64"
  template_extra_args = ["--auth-key", "~/.ssh/lxc.pub"]
  options {
    fssize = "8G"
    fstype = "ext4"
    lxc.bdev.lvm.vg = "vg-lxc"
    lxc.bdev.lvm.thin_pool = "lv-lxc"
  }
  network_interface {
    type = "veth"
    options {
      link = "lxcbr0"
      flags = "up"
      hwaddr = "00:16:3e:xx:xx:xx"
    }
  }
}

I don't find any configuration for

    fssize = "8G"
    fstype = "ext4"
jtopjian commented 9 years ago

OK, thanks for the notes. I'm going to look into this in more depth, but will take me a few days.

In the meantime, I think you can put the lxc.bdev options in the global lxc config file /etc/lxc/lxc.conf. With regard to the fssize and fstype, You may be able to set them with lxc.bdev.fssize and lxc.bdev.fstype:

https://github.com/lxc/lxc/blob/master/src/lxc/bdev.h#L87

But I could be wrong -- I'll need to test that.

Sorry for not having more of a definitive answer. Hopefully within the next few days. Thank you again for reporting this, though.

jtopjian commented 9 years ago

I dug into this and can confirm that bdev options are completely omitted from the LXC go bindings. You can see here, where the bdev specs are supposed to be passed, NULL is simply passed instead.

In order to fix this, I think a bdev_spec structure needs to be created in Go, based off of this. It then needs converted to the C equivalent to be passed into the Create function.

Unfortunately that's all well beyond my knowledge of Go at the moment.

I looked at the LXD source code and it looks like the bdev options are being handled natively in Go and circumventing the native C Create function. I could do the same in this provider, but I'd prefer this Terraform provider be a simple wrapper.

I'll leave this issue opened, though, as a reminder.

changwuf31 commented 9 years ago

Ah.. Superb.

Thanks a bunch for looking into this.

Will have to resort to ansible for now