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

Add ERB template support to the command helpers #111

Closed
gwvandesteeg opened this issue May 7, 2021 · 5 comments
Closed

Add ERB template support to the command helpers #111

gwvandesteeg opened this issue May 7, 2021 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@gwvandesteeg
Copy link

Summary

Add the ability to do ERB template resolution on the fields (in particular the args field) passed to the command definition in the config/args/terraform.rb file.

Motivation

I'm hoping to be able to generate suitable output Terraform plan files when using terraspace all plan with an individual plan name for each stack/instance to review the changes and to feed the suitable plans in to the apply/up commands.

Guide-level explanation

In particular i'd be interested in doing the below so that I can add the "plan" files to my MR/PR's via the CI/CD process (GitLab).

command("plan",
  args: ["-lock-timeout=22m", '-out=<%= expansion(":ENV-:ACCOUNT-:REGION-:MOD_NAME-:INSTANCE") %>.tfplan.json'],
)
@tongueroo
Copy link
Contributor

tongueroo commented May 7, 2021

Args files are just ruby, so it wouldn't be ERB. Instead, it would be something like this:

config/args/terraform.rb

command("plan",
  args: ["-lock-timeout=22m", "-out=#{expansion(":ENV-:ACCOUNT-:REGION-:MOD_NAME-:INSTANCE")}.tfplan.json"],
)

Unfortunately, it's not simple as including the helper methods to the args builder. The reason is that helpers are currently designed for tfvars file where the dependency graph is calculated. Terraspace actually evaluates the tfvars files twice and caches the calculated results of the helpers methods for performance reasons. The dependency graph processing logic would needed to be altered so the first pass would not be a regular ruby eval but possibly a parser. This avoids the the helpers actually being invoked in the first pass. Then helpers would be more easily be included elsewhere. Think the original reason took the ruby eval twice approach was because it's faster than writing a decent parser.

So it's a bit complex right now 🧐 Will take a decent amount of time. Will consider PRs. Of course no sweat either way 👍

@gwvandesteeg
Copy link
Author

The main reason is that i'm trying to get hold of an uniquely named plan file for each stack being spun up when using terraspace all plan, I've got a project with 13 stacks and growing that i'd like to get artefacts for during the plan stage to validate and integrate with my CI/CD platform (GitLab.com).

@tongueroo
Copy link
Contributor

Thinking will add an option to handle plans. Perhaps:

terraspace all plan --outs

Maybe the default conventional saves the plan to an expanded path. But you can also provide specify pattern the command

terraspace all plan --outs ":ENV-:ACCOUNT-:REGION-:MOD_NAME-:INSTANCE"

Unsure when will get to this, probably not for a while. Would like to provide this ability though. Happy to consider PRs. No sweat either way of course. 👍 Thanks!

@tongueroo tongueroo added enhancement New feature or request help wanted Extra attention is needed labels Jun 1, 2021
@tongueroo tongueroo reopened this Jun 1, 2021
@gwvandesteeg
Copy link
Author

That'd work fine, as long as each plan output file has a unique name and/or path it'll be workable.

@tongueroo
Copy link
Contributor

Closed in favor of #156

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants