Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Unable to pass mapping to module #1336
I'm working with AWS VPCs and I created a module for each region to set up a VPC. In the variables to the module I define a mapping of subnet addresses to availability zones, like so
I then go ahead and reference this mapping, no problem, to set up the VPC. However, if I try to override this mapping in a file referencing this, I get an error, saying a value in the mapping is not set. Here is an example (a full example is on this gist)
The error I get is
Maybe I'm missing something, I'm just not sure what
Same problem here, trying to use the consul module, which only has ami:s defined for us regions. I'm providing an overide mapping like this
and I get a very similar error:
Ok, I see in the documentation that this is currently not supported. However, this is very limiting!
What I did to overcome this was to fork the entire consul project, patch the modul variable configuration, and source this forked repository in mu module instantiation.
Please tell me if there is an easier way of working around this problem until map variables are supported in modules.
This is currently allowed for lists using syntax like:
What if another function were added to load maps from, say, JSON strings:
Our use case for this is we want to have a module that wraps bringing up chef instances to keep our code DRY. For this, we need to be able to specify attributes to that chef instance, which is a map. There's no way currently to pass this as a variable, so this is impossible and we have to copy a bunch of code.
The way it works is it uses the index function (not explicitly needed, we faked the index function using 'replace's regex capabilites, but index makes it much, much nicer which is why we made the PR).
The keys and values for the map are serialized into CSV strings that constitute parallel arrays. You find the index of your key using the 'index' function we wrote, and take that integer index against the values.
It's crude, and only supports flat maps, but it gets the job done.
Hope this helps!
referenced this issue
Jul 14, 2015
referenced this issue
Jan 24, 2016
2 similar comments
Turns out im not alone in this, made Gist demonstrating this:
For now i think instead of the complex list, a symlink would work for now