Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module name template variable #600

Open
BrianHicks opened this issue Feb 22, 2017 · 1 comment
Open

Module name template variable #600

BrianHicks opened this issue Feb 22, 2017 · 1 comment

Comments

@BrianHicks
Copy link
Contributor

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
Copy link
Member

I like this idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants