dmacvicar / terraform-provider-libvirt

Terraform provider to provision infrastructure with Linux's KVM using libvirt
Apache License 2.0
1.6k stars 460 forks source link

strange validation on local machine for local libvirt-sock #1089

Open liyihuang opened 4 months ago

liyihuang commented 4 months ago

System Information

Mac or Linux as the client

Linux distribution

Ubuntu 22.04

Terraform version

terraform version
Terraform v1.9.3-dev
on linux_amd64
+ provider registry.terraform.io/dmacvicar/libvirt v0.7.6
+ provider registry.terraform.io/equinix/equinix v2.3.0
+ provider registry.terraform.io/hashicorp/local v2.5.1
+ provider registry.terraform.io/hashicorp/null v3.2.2
+ provider registry.terraform.io/hashicorp/tls v4.0.5
+ provider registry.terraform.io/tenstad/remote v0.1.2

Description of Issue/Question

Setup

 module "infra" {                                                                                                          
   source           = "git::https://github.com/isovalent/terraform-equinix-infra"                                          
   api_key          = var.api_key                                                                                          
   infra_name       = var.infra_name                                                                                       
   k8s_cluster_name = "liyi-ocp"                                                                                           
 }    

Steps to Reproduce Issue

I wrote a module called terraform-equinix-infra(https://github.com/isovalent/terraform-equinix-infra/tree/main). the module is pretty straightforward. It will spin up a baremetal server at https://deploy.equinix.com/, install qemu and a few VM on top of it. However, I found when I run the terraform apply on the laptop that doesn't have the libvirt on it, it will throw out the error saying

dial unix /var/run/libvirt/libvirt-sock: connect: no such file or directory                   
│                                                                                                                          
│   with module.infra.provider["registry.terraform.io/dmacvicar/libvirt"],                                                 
│   on .terraform/modules/infra/providers.tf line 5, in provider "libvirt":                                                
│  

My question is why the provider wants to validate if there is a local unix socket at all? I have to install some packages like to get it working.

apt --yes install --no-install-recommends libguestfs-tools libvirt-daemon-system qemu-system

I'm trying to understand if I missed anything or I didn't configure it correctly

scabala commented 2 months ago

It is not clear from description but I think what you want to do is to connect to remote libvirt instance. In that case, you do not need anything libvirt installed on your laptop. There are plenty of ways to communicate with remote libvirt daemon. Look here and here.

liyihuang commented 2 months ago

@scabala thanks for replying and I was on vacation in last 2 weeks. I'm using the ssh as this code shows. https://github.com/isovalent/terraform-equinix-infra/blob/main/providers.tf but it will validate my local libvirt

scabala commented 2 months ago

There might be some conflict when using code directly and when using it from a module. I cannot find the exact issue - there's one already in issue tracker - but long story short, you need to specify exactly the same uri in module and outside of it.