Terraform symlink path
Closed this issue · 12 comments
tfswitch -v
Version: 0.13.1288
Hello is there a way to change the default symlink to terraform ?
I install tfswitch globally for multiple users. But tfswitch create the symlink in the home user, i would like to set the symlink path with variable or parameter.
I'm not quite sure I do understand the use case, though is this what you're looking for?
https://github.com/warrensbox/terraform-switcher#use-tfswitchtoml-file--for-non-admin---users-with-limited-privilege-on-their-computers
Hi @yermulnik ,
I already use the -b option: tfswitch -b /usr/local/env/bin/terraform
in user home dir i have a symlink : ~/.terraform.versions -> /usr/local/env/bin/.terraform.versions
i set chmod 02770 on /usr/local/env/bin/.terraform.versions
It's working but when i use tfswitch the symlink is link to homedir and not to /usr/local/env/bin/.terraform.versions
ex: terraform -> /home/user/.terraform.versions/terraform_0.14.5
I would like terraform -> /usr/local/env/bin/.terraform.versions/terraform_0.14.5
Best regards
Have you considered adding .tfswitch.toml
with bin
parameter pointing to /usr/local/env/bin/terraform
into user's home dir as described at https://github.com/warrensbox/terraform-switcher#use-tfswitchtoml-file--for-non-admin---users-with-limited-privilege-on-their-computers ?
Yes i test the .tfswitch.toml, same problem.
This change only the bin path and not the link path. It seems the symlink path is hardcoded to the home user dir.
> cat ~/.tfswitch.toml
bin = "$HOME/bin/terraform"
> ls -gG $HOME/bin/terraform
lrwxrwxrwx 1 53 Sep 19 14:55 /home/giermulnik/bin/terraform -> /home/giermulnik/.terraform.versions/terraform_1.0.11
bin
parameter is where symlink is stored.
Also bear in mind that using system-wide location will switch Terraform version for all users who use this location to lookup terraform
in the PATH.
❯ more .tfswitch.toml
bin = "/usr/local/env/bin/terraform"
tfswitch -b /usr/local/env/bin/terraform 0.14.5
Reading configuration from home directory for .tfswitch.toml
Switched terraform to version "0.14.5"
ls -lart /usr/local/env/bin
terraform -> /home/user/.terraform.versions/terraform_0.14.5
so it's not taking the bin path as symlink path
Do I get it right that you want system-wide "cache" of downloaded Terraform binaries?
If yes, then the destination is hardcoded to be users's home dir: https://github.com/warrensbox/terraform-switcher/blob/master/lib/install.go#L59-L76
If you indeed want this to be some system-wide path, then either PR is needed to add such an option, or you may try and symlink /home/<USERNAME>/.terraform.versions/
into such a system-wide dir for all users.
Though I'm still unsure about viability of such approach.
Hello yes i want a global dir for multiple users.
I already try to symlink in user home but it's not ok between multiple user. I think a Variable to set the symlink is a good way to fix. I will check for the PR, thanks.
Just in case: this is a slippery slope as shared dir for binaries would require thorough management of e.g. overlapping file locking in cases of simultaneous downloads of missing TF versions + management of downloaded file permissions and ownership, an so on.
Hum yes you are right if multiple people change the link :/ it's not will be good. In that case juste the download dir must be system wide and the terraform symlink in user home. I will try that. For the download dir a 02770 is ok.
It's not actually about changing the symlink per se. Though changing symlink target by someone in between TF run done by another user would probably be the cause of unexpected weirdness and mess. So just add it to the list of cons of this approach.
Should we be fine to close this issue at the moment?
Thanks @yermulnik