Skip to content

Replace count with for_each in terraform

Roman Hros requested to merge terraform-count-for-each into devel

Replace count with for_each in terraform. It is possible to delete a specific worker/master node from the beginning/middle of the list using the worker/master_names variable as a unique identification. Gateways are also modified in a similar way.

Imagine this set-up in config.toml:

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

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

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

You expect that terraform destroys "L" worker. It's true. You will end up with one "M" worker, because terraform destroys openstack_compute_instance_v2.worker["managed-k8s-worker-one"], and keeps worker["managed-k8s-worker-two"].

Closes: #458 (closed)


Merge Prerequisites

  • Description and title are descriptive
  • Code is readable and syntactically correct
  • Code is understandable
  • Tests added (if needed)
  • Docs updated
  • Commit messages look good

As a developer: please do not tick these boxes yourself. As a reviewer: please get yourself a hot beverage.

Edited by Roman Hros

Merge request reports

Loading