MusicDin / kubitect

Kubitect provides a simple way to set up a highly available Kubernetes cluster across multiple hosts.

Home Page:https://kubitect.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

provider.libvirt.uri problem

6aKa opened this issue · comments

commented

virsh what you using for create network don't known about entered libvirt uri.

variants to fix this issue:

  1. set LIBVIRT_DEFAULT_URI - this variable use by libvirt provider and virsh
    LIBVIRT_DEFAULT_URI=qemu:///system terraform plan
  2. rewrite all network module for use libvirt_network resource.
  3. change all virsh to virsh --connect ${var.provider_libvirt_uri}, but before this need find way how get and populate this variable

Thanks for pointing that out. I will try all provided solutions, but I think that libvirt_network resource seems to be appropriate solution.

Hi,

I made some investigation and I don't see any problems with network configuration.

Before terraform v0.13 the URI had to be provided in the following form (it can be also seen in libvirt_k8s.tf file in terraform-0.12 branch):

provider "libvirt" {
  uri = "qemu:///system"
}

But with the release of v0.13 version, the provider has to be set in versions.tf file.

If provider is not contained in the list of terraform providers, it has to be manually installed on a system as it is explained in migrate to terraform v13 section in libvirt provider's docs.

Please let me now if I have misunderstood this issue.

commented

This is example for reproduce issue

provider "libvirt" {
  uri = "qemu:///system"
}

resource "null_resource" "network" {
  provisioner "local-exec" {
    command     = "virsh uri > out1.txt && virsh net-list >> out1.txt"
    interpreter = ["/bin/bash", "-c"]
  }

  provisioner "local-exec" {
    command     = "virsh --connect qemu:///system uri > out2.txt && virsh --connect qemu:///system net-list >> out2.txt"
    interpreter = ["/bin/bash", "-c"]
  }
}

and you need run not from root.

if you run rm -f out*.txt terraform.tfstate && terraform apply you get differ out files. files differ because virsh don't known about provider.libvirt.uri.

if you run rm -f out*.txt terraform.tfstate && LIBVIRT_DEFAULT_URI=qemu:///system terraform apply you get similar out files.

for example, when you use uri = "qemu+ssh://root@example.com/system", all resources setup remotely, but network locally because virsh don't known about this uri.

Thanks for provided example, now I understand the situation.

So, basically there are 3 solutions (which you have also pointed out in the first place).

I don't use libvirt_network resource because I had some problems with assigning static IPs but I will probably migrate to it sooner or later.

Other solution that worked for me is to export libvirt's default URI (export LIBVIRT_DEFAULT_URI=qemu+ssh://test@192.168.116.1/system). In that case provider "libvirt" resource and virsh --connect command can overwrite this value. What I don't like about env variables is that it has to be always set before applying the script and if you relay on them in other configurations it may be annoying to constantly change it.

In my opinion the best solution is to add terraform variable and to use it to set libvirt provider's uri in resource and also to use it in virsh commands like you said before.

Example:

variable "libvirt_provider_uri" {
  type        = string
  description = "Libvirt provider URI"
  default     = "qemu:///system"
}

provider "libvirt" {
  # Uses provided URI
  uri = var.libvirt_provider_uri
}

resource "null_resource" "network" {
  provisioner "local-exec" {
    # Uses default virsh URI 
    command     = "virsh uri > out1.txt && virsh net-list >> out1.txt"
    interpreter = ["/bin/bash", "-c"]
    on_failure=continue
  }

  provisioner "local-exec" {
    # Forced to use provided URI
    command     = "virsh --connect ${var.libvirt_provider_uri} uri > out2.txt && virsh --connect ${var.libvirt_provider_uri} net-list >> out2.txt"
    interpreter = ["/bin/bash", "-c"]
    on_failure=continue
  }
}

resource "libvirt_volume" "kernel" {
  source = "http://download.opensuse.org/tumbleweed/repo/oss/boot/x86_64/loader/linux"
  name   = "kernel"
  pool   = "default"
  format = "raw"
}

resource "libvirt_domain" "domain-suse" {
  name   = "suse"
  memory = "1024"
  vcpu   = 1

  kernel = libvirt_volume.kernel.id
}

I'm going to implement the solution during the day.

If I've forgotten about something or if you have a better solution, please let me know.