I am using terraform to setup a docker swarm cluster on OpenStack along with using Ansible for configuration on newly created VMs. I want to perform first docker swarm leave
on a VM which is going to be removed when I decrease the number of instances(VMs) and apply changes via terraform apply
. It works when I destroy instance one by one but when 2 instances at once then it gives an error.
Error: Cycle: module.swarm_cluster.openstack_compute_instance_v2.swarm-cluster-hosts[3] (destroy), module.swarm_cluster.openstack_compute_instance_v2.swarm-cluster-hosts[2] (destroy)
Here is script:
resource "openstack_compute_instance_v2" "my_cluster"{
provisioner "remote-exec" {
when = destroy
inline = [ "sudo docker swarm leave" ]
}
connection {
type = "ssh"
user = var.ansible_user
timeout = "3m"
private_key = var.private_ssh_key
host = self.access_ip_v4
}
}
terraform :0.12