hi @apparentlymart
If you associate an existing resource with a different provider configuration then on the next plan Terraform will ask the new provider confirmation to “refresh” the resource instances. If the new provider configuration reports that the object exists then Terraform should just plan changes against it as normal, without proposing to replace it.
Not sure if I understand correctly, but your talking about switching provider instance in Terraform configuration, right ? What I was talking about isn’t quite that.
I wish to be able to provision a VM on a cluster (which is, in the case of libvirt, modeled as a set of different instances of the same provider because there is no cluster management in this provider). And in the cluster lifetime, it happens sometimes that VM distributions are (automatically or not) re-balanced, for example for an hypervisor maintenance, and that without Terraform. I wish that Terraform don’t care about that (except maybe if specific instruction is given in the ressource configuration) and let that untouched on next apply, not even with a change, it should appear as untouched.
I think this feature could be useful to any provider that do not manage clusters/multi-zones.
I think a bit of practical demonstration should help. Let’s say I have 2 hypervisors:
provider "libvirt" {
alias = "host-1"
uri = "qemu+ssh://host-1.dns/system"
}
provider "libvirt" {
alias = "host-2"
uri = "qemu+ssh://host-2.dns/system"
}
As far as I know, with that configuration you have to attach VMs to one of those providers, for instance host-1:
resource "libvirt_domain" "myvm" {
provider = libvirt.host-1
...
}
Let’s say myvm is later re-distributed (hot migrated) to host-2 because of load balancing of some sort. After all, functionally, myvm has no need to be specially on one host or the other.
Then next time I will run Terraform, of course myvm will disappear on host-2 to be recreated on host-1.
The behaviour I’m looking for is that terraform will let that untouched. That’s why I’m looking for an equivalent to that imaginary syntax:
provider "libvirt" {
alias = "host-1"
uri = "qemu+ssh://host-1.dns/system"
}
provider "libvirt" {
alias = "host-2"
uri = "qemu+ssh://host-2.dns/system"
}
provider_group "libvirt_cluster" {
members = [ libvirt.host-1, libvirt.host-2 ]
# Let's say we can choose how new resources are distributed
creation_distribution = "round-robin"
...
}
resource "libvirt_domain" "myvm" {
provider = libvirt_cluster
# if we want the resource to be specifically attached to a special host:
provider_attached = libvirt.host-1
...
}