How to deploy container using terraform from remote host? facing authentication issue

Hi Everyone, Good Day!

I am trying to create a container on LXD environment which is deployed over a linux ubuntu 20.04 using terraform which is installed on my local laptop and I am trying to connect my terraform host to LXD server, can any one please let me know how do I run the terraform code remotely to LXD server.

I am following this offical link to Docs overview | terraform-lxd/lxd | Terraform Registry make connection b/w terraform host to LXD server.

Thankyou in advance!

Abhishek Bist

FYI, there is a bug with the terraform-lxd provider (that I have yet to report) where it tries to look for your credentials only in ~/.config/lxc. If you are using the snap, that location won’t exist or have the needed bits so you need to workaround it with this symlink:

ln -s ~/snap/lxd/common/config/ ~/.config/lxc

This way, your existing client.key, client.crt and all your remotes and their crt will be found by terraform without needing to specify them.

Here’s my that’s using a LXD remote named xeon:

$ cat 
terraform {
  required_providers {
    lxd = {
      source = "terraform-lxd/lxd"

resource "lxd_container" "apt" {
  name   = "apt"
  image  = "images:ubuntu/22.04"
  remote = "xeon"

The LXD remote:

$ lxc remote ls | grep xeon
| xeon                          |               | lxd           | tls         | NO     | NO     | NO     |

As you can see that you don’t even need to define a lxd_remote in terraform; it’s smart enough to understand those already configured.

Thank you for the response @sdeziel, let me clarify the whole scenario.

LXD Server installed on Ubuntu, and I am trying to push the code from my local windows system to LXD Server to create a container. Could you please guide me how do I create and where to create “client.crt and client.key” for remote connection, as I am little bit confused, should I need to install lxc client on my windows machine and then create a symlink respect of “ln -s ~/snap/lxd/common/config/ ~/.config/lxc” this.

If I am directly running the terraform code from LXD Server everything works smooth and container, profile etc are created successfully.

Abhishek Bist

Sorry, I assumed a linux client running the snap. Obviously I was wrong so please disregard my suggestion. As for how to do what you want from a Windows client, I’m afraid I don’t know how, sorry.

Maybe @stgraber would know some more about lxc on Windows?

No worries @sdeziel ,

But thank you for your responses, really appreciated.