[terraform] Use for_each instead of count

Right now, we have instances identified by their index, which is not optimal in some situations (e.g. you want to delete a specific worker node from the beginning/middle of the list). Imagine this set-up in config.toml:

[terraform]
workers = 2
worker_flavors = ["L", "M"]
worker_azs = ["AZ1", "AZ2"]

What happens if you want to remove the "L" worker? You remove "L" and "AZ1" from the list and decrement workers variable like this:

[terraform]
workers = 1
worker_flavors = ["M"]
worker_azs = ["AZ2"]

You expect that terraform destroys "L" worker. It's true. You will end up with one "M" worker, but terraform process behind is different. Because it is based on index, terraform destroys openstack_compute_instance_v2.worker[1], and replaces worker[0] (replace means destroy("L", "AZ1") + create("M", "AZ2")). So your workers will not be 2 --> 1 but 2 --> 0 --> 1, which is not desirable.

See When to Use for_each Instead of count.

The whole count logic needs to be replaced with for_each logic. The affected lines are for example in terraform/40-worker-nodes.tf but affected is also 30-master-nodes.tf or 20-gateway.tf, because the same problem arises for master and gateway nodes.

For worker nodes identification we can use for example worker_names variable. If this variable is not defined, we can use indexes as before.

Edited by Roman Hros