Terraform: Proposal: Control common command flags via .terraformrc

Created on 2 Oct 2018  路  4Comments  路  Source: hashicorp/terraform

Current Terraform Version

Terraform v0.11.8

Use-cases

Override default parallelism for plan, apply.

My colleagues and I typically adjust parallelism on these commands to speed things up on our fairly large blueprints. It's something I eventually end up forgetting, only to later realize things are slow again and have to re-add it to my commands.

Set -no-color to be default.

Just a quality of life default, for some.

Set -backup to non-default.

Another quality of life default.

Attempted Solutions

Basic shell aliases are non-viable since the flags must follow the subcommand. A custom shell function to wrap terraform and apply certain defaults technically works, but is far from elegant.

Proposal

I'd like to propose adding config options to .terraformrc to control some of these common flags either at a global scope (Option 1), or adding a more generalized command_flags section to change flag defaults per command (Option 2).

If this idea seems viable and an approach can be agreed upon, I'd be happy to code it myself and send a PR in.

Here's how things might look. Note that the identifiers I've used are just filler and can be changed to whatever makes sense.

Option 1, .terraformrc

parallelism = 50
no_color = true

Option 2, .terraformrc

command_settings "apply" {
   parallelism = 50
   backup = ".tfback"
}

command_settings "plan" {
   parallelism = 100
}

Open Questions

If Option 2 is chosen, should all flags be settable via .terraformrc, or only a select few? If the latter, what criteria determines what flags should and should not be configurable this way?

References

cli enhancement

Most helpful comment

Hi, @alienth @Preskton

This works fine for me.

$ export TF_CLI_ARGS_plan="--parallelism=50"
$ terraform plan

See: https://www.terraform.io/docs/configuration/environment-variables.html#tf_cli_args-and-tf_cli_args_name

All 4 comments

Thanks for the feature request, @alienth! I like your suggestions, and a PR would be great. We'll see if the rest of the core team has suggestions (I'm the new kid) but personally I favor tools that allow you to configure all global flags in a config file (option 1). I'm fuzzier on which command-specific flags are appropriate to add to a file; I'd say move forward with option 1 for global flags and we can discuss command-specific flags here or in the PR. This is open for discussion, however!

While I don't think there's going to be much conflict (if any), you may wish to wait until after terraform 0.12 is released. It includes many significant changes and the master branch of terraform is effectively frozen until we merge the 0.12-dev branch into master.

Is it possible to set paralellism or others via an environment variable, e.g. TF_PARALLELISM?

As an additional use case, I'm running into the opposite issue: I need to slow plans and applys down so that I stay under an API rate limit -- 30 calls/sec is easy to exceed when interacting with TFE APIs. On the default parallelism setting of 10, I can exceed 30 calls a second easily. Locally, I'll set parallelism to 2 and things work well.

I'd prefer option 1 as well, as you can split between plan and apply with different files.

Hi, @alienth @Preskton

This works fine for me.

$ export TF_CLI_ARGS_plan="--parallelism=50"
$ terraform plan

See: https://www.terraform.io/docs/configuration/environment-variables.html#tf_cli_args-and-tf_cli_args_name

Rock on - that's perfect and works for me as well. @alienth thoughts?

Was this page helpful?
0 / 5 - 0 ratings