9

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

Jordan
  • 3,998
  • 9
  • 45
  • 81
Niaz Hussain
  • 139
  • 1
  • 9
  • 1
    This snippet would only create a single node as you have no count or for_each, how are the other resources created? – Rumbles Jul 06 '22 at 10:22
  • Two things check that the destroy provisioner is supporter in v0.12. Second, the provisioner should come after the connection. – victor m Jul 17 '23 at 18:34

0 Answers0