top | item 44322010

(no title)

dochne | 8 months ago

My main beef with HCL is a hatred for how it implemented for loops.

Absolutely loathsome syntax IMO

discuss

order

mdaniel|8 months ago

It was mentioned pretty deep in another thread, but this is just straight up user hostile

  variable "my_list" { default = ["a", "b"] }
  resource whatever something {
    for_each = var.my_list
  }

  The given "for_each" argument value is unsuitable: the "for_each" argument must be a map, or set of strings, and you have provided a value of type tuple.

Spivak|8 months ago

This is what you get if you want a declarative syntax. HCL doesn't have any concept of a for loop, and can't have any concept of a for loop— it's a data serialization format. Terraform can be transformed to and from JSON losslessly. The looping feature is implemented in Terraform.

Ansible's with_items: and loop: do the exact same thing with YAML.

SOLAR_FIELDS|8 months ago

I just tell people to avoid writing loops in Terraform if it could be at all avoided. And if you iterate make sure it’s a keyed dictionary instead of array/list like data structure