starhawking / python-terrascript

Create Terraform files using Python scripts.
BSD 2-Clause "Simplified" License
515 stars 76 forks source link

Adds 'Locals values' feature #71

Closed nielsonsantana closed 5 years ago

nielsonsantana commented 5 years ago

Adds the locals values feature.

A local value assigns a name to an expression, allowing it to be used multiple times within a module without repeating it.

Comparing modules to functions in a traditional programming language: if input variables are analogous to function arguments and outputs values are analogous to function return values, then local values are comparable to a function's local temporary symbols. https://www.terraform.io/docs/configuration/locals.html

Example:

from terrascript import locals

locals(
    yb_master_public_ips=','.join([x.ipv4_address for x in yb_master]),
    yb_server_public_ips=','.join([x.ipv4_address for x in yb_server]),
)
nielsonsantana commented 5 years ago

I just realized that terraform locals conflits with python locals. One possibility is change to locals to Locals or even to tslocals.

mjuenema commented 5 years ago

Hi @nielsonsantana , can you please update CHANGELOG.md with your recent change(s). After Josh Smift recently asked me to create release 0.6.1 (#70) I realised that I always forget to ensure that pull requests update that file - as well as CONTRIBUTORS.md if applicable.

nielsonsantana commented 5 years ago

Hi @mjuenema, do you have any suggestion to this feature? What would be the name for locals in python? Locals, tslocals, locals2? I would like include this feature in the next release.

jbscare commented 5 years ago

localses? :^)

mjuenema commented 5 years ago

I tend towards Locals as this would comply with PEP-8 although that's not so important here as I am violating PEP-8 all over the place to make names match with Terraform. Any thoughts?

nielsonsantana commented 5 years ago

I think that Locals is a good option however don't match with lowercase pattern in terraform. Also, it's close to the terraform nomeclature. Any other term is very different from terraform.

nielsonsantana commented 5 years ago

@mjuenema, I updated CHANGELOG.md and CONTRIBUTORS.md with the recent changes to be released as 0.6.1.

nielsonsantana commented 5 years ago

localses? :^)

@jbscare thanks for the contribution.

nielsonsantana commented 5 years ago

@mjuenema, I think that the release would be version 0.7 instead of 0.6.1 because there a lot of changes in the source code.

mjuenema commented 5 years ago

@mjuenema, I think that the release would be version 0.7 instead of 0.6.1 because there a lot of changes in the source code. I can do that. @jbscare is very keen on a new release :-)

mjuenema commented 5 years ago

There is even documentation 🥇

nielsonsantana commented 5 years ago

@mjuenema, I made a small mistake. I put a wrong path to locals.md doc. I sent another MR to fix that.