dmacvicar’s libvirt provider is already in the official registry. Yet, I indend to contribute functionalities, which I would like to use in my homelab. This post is the progressive summary of the process.
Development setup#
- Set the environment:
| 1
2
 | mkdir -p ~/GitRepos
mkdir -p ~/terraform.d/plugins/local-registry/cbugk/libvirt/0.7.0/linux_amd64
 | 
 
- For installing terrraform and the initial provider test Fabian Lee’s introduction was followed.
His main.tffile:
|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
 | terraform {
  required_version = ">= 1.0.1"
  required_providers {
    libvirt = {
      source = "dmacvicar/libvirt"
      version = "0.6.10"
    }
  }
}
provider "libvirt" {
  uri = "qemu:///system"
}
resource "libvirt_domain" "terraform_test" {
  name = "terraform_test"
}
 | 
 
- Compilation from source, which can be done by simply runing make.terraform-provider-libvirtbinary will be output in repository’s root. For more info checkout provider’s Github repository, version0.7.0was used.
| 1
2
3
4
5
6
7
8
 | # Clone repository
$ mkdir -p ~/GitRepos
$ git clone https://github.com/dmacvicar/terraform-provider-libvirt.git
$ cd terraform-provider-libvirt
# Compile
$ make
# Move provider binary to registry
$mv terraform-provider-libvirt ~/.terraform.d/plugins/local-registry/cbugk/libvirt/0.7.0/linux_amd64/
 | 
 
- For using a local copy of provider filesystem_mirrorproperty was set under~/.terraformrc(file was not present). Sources: Sam Debruyn’s blog post, tnom’s SO answer, terraform docs.
| 1
2
 | $ ls -la ~/.terraform.d/plugins/local-registry/cbugk/libvirt/0.7.0/linux_amd64/terraform-provider-libvirt
-rwxr-xr-x. 1 cbugk cbugk 24139069 Nov 13 09:41 /home/cbugk/.terraform.d/plugins/local-registry/cbugk/libvirt/0.7.0/linux_amd64/terraform-provider-libvirt
 | 
 
Note that due to location ~/.terraform.d/plugins being a default implicit override directory, creating rc file is not required. However, here is the respective configuration.
~/.terraformrc modified:
|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
 | provider_installation {
        filesystem_mirror {
                path = "/home/cbugk/.terraform.d/plugins"
                include = ["local-registry/cbugk/libvirt"]
        }
        direct {
                exclude = ["local-registry/cbugk/libvirt"]
        }
}
 | 
 
- For SSH’ing into my home server on the LAN, I used mallardduck’s suggestion. Previously on 0.6.10, the &sshauth=privkeypart was not necessary. Hopefully someday ssh_config support will arrive, until then below config should serve well. Make sure to accept keys beforehand, or add&no_verify=1(not suggested).
|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
 | terraform {
  required_version = ">= 1.3.4"
  required_providers {
    libvirt = {
      source  = "local-registry/cbugk/libvirt"
      version = "0.7.0"
    }
  }
}
provider "libvirt" {
  uri = "qemu+ssh://cbugk@192.168.172.1/system?keyfile=/home/cbugk/.ssh/cbk_net_tr&sshauth=privkey"
}
resource "libvirt_domain" "custom_provider_test" {
  name = "custom_provider_test"
}
 | 
 
To test that configuration works:
| 1
2
3
 | terraform init
terraform plan
terraform apply
 | 
 
TODO#