Hi, is it possible to pass additional flags that works with terraform
to terraspace
?
For example terraform plan -refresh=false
?
When I do terraspace plan eks -refresh=false
I get error:
ERROR: "terraspace plan" was called with arguments ["eks", "-refresh=false"]
Usage: "terraspace plan STACK"
Also another such requirement:
If I want to get value of a specific output I can do:
terraform output <outpuput_name>
When I tried the same with terraspace
it didn’t work. Got a similar error as above.
tung
May 3, 2022, 4:18am
2
Maybe you’re running an older version? Tested and options get passed through.
$ terraspace plan demo -refresh=false
Building .terraspace-cache/us-west-2/dev/stacks/demo
Built in .terraspace-cache/us-west-2/dev/stacks/demo
Current directory: .terraspace-cache/us-west-2/dev/stacks/demo
=> terraform init -get -input=false >> /tmp/terraspace/log/init/demo.log
=> terraform plan -refresh=false -input=false
Notice: “terraform plan -refresh=false -input=false”
This specific feature was covered in Terraspace v1 Release | BoltOps Learn
FWIW, running versions
$ terraform --version
Terraform v1.1.7
$ terraspace version
1.1.7
$
Also tested several cases in the PR
boltops-tools:master
← boltops-tools:pass-args
opened 11:28PM - 26 Dec 21 UTC
* pass through unmanaged options to terraform command
* options can be passed w… ith 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.
<!--
Before you submit this pull request, make sure to have a look at the following checklist. To mark a checkbox done, replace [ ] with [x]. Or after you create the issue you can click the checkbox.
If you don't know how to do some of these, that's fine! Submit your pull request and we will help you out on the way.
-->
- [x] I've added tests (if it's a bug, feature or enhancement)
- [x] I've adjusted the documentation (if it's a feature or enhancement)
- [x] 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
Note, an output name is not currently pass through though. Will consider PRs. Of course. No sweat either way