dmacvicar / terraform-provider-libvirt

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

Create data sources for pre-existing libvirt network, pool, etc resources #985

Open jbeisser opened 1 year ago

jbeisser commented 1 year ago

System Information

Linux distribution

Ubuntu..

Terraform version

Terraform v1.3.5
on darwin_amd64

Provider and libvirt versions

./terraform-provider-libvirt_v0.7.0 -version
./terraform-provider-libvirt_v0.7.0 0.7.0

Libvirt 6.0.0 (Ubuntu 20.04.5 LTS)


Description of Issue/Question

The ability to pull in existing resources via import exists. This is useful and good, until you have to destroy a component, or need to terminate a VM without destroying other resources that are managed elsewhere.

Ideally, I should be able to create a data source in the project:

For example, a volume...

data "libvirt_volume" "backing-volume" {
  pool = "images"
  name = "ubuntu-20.04-server.img"
}

The risk faced in importing the resources is that a careless terraform destroy can wipe out a shared resource like a network or pool. I may have multiple systems relying on the same backing image, which are not all handled by the same terraform plan. Or, I may have another project in TF that manages available images on the source system directly, and want to reference the named versions directly instead of downloading them to the KVM host.

jbeisser commented 1 year ago

Draft PR is up.

https://github.com/dmacvicar/terraform-provider-libvirt/pull/987