← Back to context

Comment by embedding-shape

6 hours ago

> Terraform has modules which are an elaborate method of doing function calls

... What? How is modules a function call? It's just a hierarchy, everything about/with modules is still declarative.

> HCL 2 has loops and conditionals. It is most definitely imperative.

So what? Just because there is loops and conditionals doesn't mean it's suddenly imperative.

How exactly you do loops in HCL? Last time I used it, you still used declarative configuration for that, and use `for_each` as an declared option, you don't "call for_each which returns config", all that happens inside of HCL/TF, because it is declarative.

Did something change like yesterday or are people even here on HN so ignorant about what declarative vs imperative actually means?

You "call" a module with arguments. You can call them multiple times. In every way that matters they are just like a function call.

I don't understand why there is a distinction between for each in a standard language vs for_each in HCL2. They are both do something by iterating over something else at runtime. The syntax isn't what matters here.

I think maybe you are mistaken in your own distinction between declarative and imperative.

  • Imperative: Tell the computer how to do something, by instructing it what to do.

    Declarative: Tell the computer what you want the result to be like, and the computer figures out how to do it.

    for_each in Terraform is very much declarative, just like modules. Compare how you'd do the same thing with JS or any other (imperative) language you know, and I think it must be clear what the difference between the two is.

    • Those boundaries are pretty fuzzy. The complexity of the logic with conditionals and loops in a module means that you have pretty much stopped describing what it should like and instead described how to make it look the way you want it.

      I have read terraform modules where I had to execute the logic to know what got produced which moves it from your imperative description to the declarative description as far as I'm concerned.