Support switching version for the current shell instead of globally
Opened this issue · 3 comments
Use case:
I work with multiple teams that update their terraform version on their own cadence. We cover the entire spectrum of 0.12.x to 0.15.x.
When working across these repos, I will often flick back and forth between them in different shells. I have to constantly re-run tfswitch because using 0.13.1 in shell A will not work with 0.14.2 in shell B.
Suggestion:
Not really sure about the details, but if tfswitch could work with environment variables as opposed to symlinks (I think?) then we changing versions in one shell would not affect the other.
Consideration:
This might be a pretty substantial change, I don't know if users currently rely on the global behavior, so I'm OK if this issue is closed ✌️
@yermulnik @felipesere
I use different terraform versions for each project as well. This is what I did.
- On your .bashrc (or .bash_profile or .zsh or whatever shell you are using).
terraform(){
tfswitch -b ${PWD}/.bin/terraform 0.12.23
${PWD}/.bin/terraform "$@"
}
or
terraform(){
tfswitch -b ${PWD}/.bin/terraform #if you don't specify a version, you can use a .tfswitchrc/terragrunt.hcl/.terraform-version/version.tf file to specify the version
${PWD}/.bin/terraform "$@"
}
- Save your changes. Source the file:
source .bashrc
(or .bash_profile or .zsh or whatever shell you are using) - In your terraform project folder, create a
.bin
directory :mkdir .bin
- Next, run
terraform -v
to verify if this works
Let me know if this works for now.
@warrensbox Thanks for the pointer. TBH I'm not very keen to wrap terraform
into another shell function for my use case though.
Also (for the example above) I'm not really sure what's the purpose of having per-project bin-dir. Seems like having something like terarform(){ tfswitch && terraform "$@"; } ; export -f terraform
should do the same thing along with not populating terraform binaries into multiple locations.