asteris-llc / converge

A powerful and easy-to-use configuration management system.
Apache License 2.0
250 stars 31 forks source link

Module name template variable #600

Open BrianHicks opened 7 years ago

BrianHicks commented 7 years ago

When we call a module, it looks like this:

module "x.hcl" "foo" {}

We refer to this subgraph as module.foo. This works! But there's more we could do with this name parameter (foo here.)

I'm working on moving my dotfiles to Converge, and I get this pattern all over the place:

module "../homebrew/install.hcl" "zsh" {
    params = {
        package = "zsh"
    }
}

This is a bit silly. I'm having to use 5 lines in the file when one would clearly do. Repeat this across the three invocations I need to install ZSH dependencies and whatnot, and I have a pretty busy file.

What I would like to write is this:

module "../homebrew/install.hcl" "zsh" {}
module "../homebrew/install.hcl" "zsh-syntax-highlighting" {}
module "../homebrew/install.hcl" "zsh-compltions" {}

One line per install. Much better!

I'd like to accomplish this by threading the module name down into a template variable. For the purposes of discussion, let's call it {{module.name}}.

My current code has a parameter, package, that controls which package will be installed. This is a required variable. But if we added this as a template variable, I could instead define package as:

param "package" {
    default = "{{module.name}}"
}

At that point if I specified a "package" in a module call it would be used. If it is not specified, the three-installs-in-three-lines calls above will kick in.

stevendborrelli commented 7 years ago

I like this idea.