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

better wrap and pass through terraform args #172

Merged
merged 1 commit into from
Dec 26, 2021
Merged

better wrap and pass through terraform args #172

merged 1 commit into from
Dec 26, 2021

Conversation

tongueroo
Copy link
Contributor

  • pass through unmanaged options to terraform command
  • options can be passed with single or double dash
  • reconstruct_hash_args when needed for key value based args

This is a 🐞 bug fix.
This is a πŸ™‹β€β™‚οΈ feature or enhancement.
This is a 🧐 documentation change.

  • I've added tests (if it's a bug, feature or enhancement)
  • I've adjusted the documentation (if it's a feature or enhancement)
  • The test suite passes (run bundle exec rspec to verify this)

Summary

Improve passing of cli args from terraspace to terraform. Taking a generalized pass-through approach now. There are 3 types of args passing from terraspace to terraform.

  1. custom - from https://terraspace.cloud/docs/config/args/
  2. terraspace/thor cli options - specific cli options from terraspace and can be handled specially by terraspace before passing onto the underlying terraform command
  3. pass-through cli options - pass-through options get passed from terraspace to terraform. In this case, terraspace acts as wrapper to terraform. There's some smarter handling though. Details below.

Pass-Through CLI Options Smarter Handling

Both -- and - args work from the terraspace cli interface. Examples:

terraspace plan demo -refresh=false
terraspace plan demo --refresh=false
terraspace plan demo -refresh=false -no-color
terraspace plan demo -refresh=false --no-color

The final terraform commands will use the single dash (-) option.

Additionally, the underlying terraform command -h is called to see that the cli option is valid for that particular install of terraform. The args are only added if it's supported. Otherwise, it will be discarded. This allows terraspace cli commands which call multiple terraform commands like terraform init and terraform apply in one-go to be passed both cli options and terraspace will figure it out.

Context

Folks have asked to be able to use underlying args before. Was able to figure it out this go-around.

How to Test

Tested a lot of commands. Here are examples:

Plan:

terraspace plan demo -refresh=false
terraspace plan demo -refresh=false --no-color --destroy --foo --var foo=bar
terraspace plan demo -refresh=false --no-color --destroy --foo --var foo=bar --lock-timeout=0s
terraspace plan demo -refresh=false --no-color --destroy --foo -var foo=bar --lock-timeout=0s
terraspace plan demo -refresh=false -no-color
terraspace plan demo -refresh=false -no-color --destroy
terraspace plan demo -refresh=false -no-color --destroy --foo
terraspace plan demo -refresh=false -no-color --destroy --foo --var foo=bar
terraspace plan demo -refresh=false -no-color --destroy --foo -var foo=bar --lock-timeout=0s
terraspace plan demo -refresh=false -no-color --destroy -foo
terraspace plan demo -refresh=false -no-color --out=foo.plan
terraspace plan demo -refresh=false -no-color --parallelism=5
terraspace plan demo -refresh=false -no-color --whatever=true
terraspace plan demo -refresh=false -no-color -destroy
terraspace plan demo -refresh=false -no-color -destroy --foo -var foo=bar --lock-timeout=0s
terraspace plan demo -refresh=false -no-color -destroy -foo
terraspace plan demo -refresh=false -no-color -var 'foo=bar'
terraspace plan demo -refresh=false -no-color -var 'foo=bar' -var 'foo2=bar2'
terraspace plan demo -refresh=false -var 'foo=bar'
terraspace plan demo -refresh=false -var 'foo=bar' -destroy

Init:

terraspace init demo -upgrade
terraspace init demo --upgrade
terraspace init demo -reconfigure
terraspace init demo --reconfigure

Force unlock:

terraspace force_unlock
terraspace force_unlock demo 1637885224763097

Output:

terraspace output demo --format json
terraspace output demo --json
terraspace output demo -json

Show:

terraspace show demo --json
terraspace show demo --json | jq
terraspace show demo -json
terraspace show demo -json | jq

Init:

terraspace init demo --reconfigure --get=false
terraspace init demo --reconfigure -get=false

Validate:

terraspace validate demo
terraspace validate demo -json
terraspace validate demo -json | jq
terraspace validate demo -json -no-color
terraspace validate demo -json -no-color | jq

Down:

terraspace down demo -y

State:

terraspace state -h
terraspace state list demo
terraspace state list demo --id bucket-concrete-lemming

Up:

terraspace up demo -compact-warnings
terraspace up demo -compact-warnings -y

Version Changes

Minor

* pass through unmanaged options to terraform command
* options can be passed with single or double dash
* reconstruct_hash_args when needed for key value based args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant