terraform-switcher
terraform-switcher copied to clipboard
snap package cannot use "~/.terraform.version" and "/usr/local/bin"
I've installed package from snap and running tfswitch -b $HOME/bin
, it gives me
Error while creating /home/user/.terraform.versions/terraform_0.13.5_linux_amd64.zip - open /home/user/.terraform.versions/terraform_0.13.5_linux_amd64.zip: permission denied
Running just tfswitch --latest
complains about /usr/local/bin
directory . Both places are not available from usual snap packages.
- Are you running
tfswitch -b $HOME/bin/terraform
ortfswitch -b $HOME/bin
? - Do you have permission to write to the
$HOME/bin
directory (what do you see when you runls -l
on $HOME?
- both give same result
- I am owner of $HOME/bin:
whoami
tim
ls -la $HOME | grep ' bin'
drwxrwxr-x 3 tim tim 4096 Dez 14 16:50 bin
Note:
I've uninstalled tfswitch installed using Troubleshooting guilde and installed snap package again to reproduce it again
From what I see here https://snapcraft.io/docs/home-interface https://forum.snapcraft.io/t/access-to-specific-hidden-file-path-in-users-home/6948 it looks like
- problem is in ~/.terraform.versions
- snap does not allow to use hidden (dot-prefixed) dirs in home
So either tfswitch in snap package should automatically use different folder (maybe ~/snap/tfswitch ? I see this folder has been created by snap) or at least allow to customize it.
@strowk perhaps I can allow users to customize it. Thank you for bringing this up. I will find some time to do this before the end of the year. Hopefully, I can release this fix in January. In the source code: -
getInstallLocation() //only downloads the terraform bins into the home directory in .terraform.versions
.
.
.
installLocation = usr.HomeDir + installPath //where installPath = "/.terraform.versions/"
I can make this getInstallLocation()
customizable where users can provide a location for all terraform binaries. Again, I can only get to this by the end of the year. If you know go
and would like to contribute, I would be happy to review and merge your code as well.
I will let you know once I have implemented this. Thank you for bringing this up.
Just want to add one note here - I see it would go better if either there would be note in installation doc and in description here https://snapcraft.io/tfswitch , that snap package requires additional configuration, or binary should somehow understand that it's running as a snap package and change path automatically. Otherwise everyone who install snap package would found themselves in this issue :)
I suspect that detection run from snap should not be very hard. Probably checking any of these env vars would do - https://snapcraft.io/docs/environment-variables
For example SNAP_USER_COMMON
seems very convenient for this task -
Directory for user data that is common across revisions of a snap.
Basically it seems that following algo would work nicely -
- if custom location is set - use it
- else check if SNAP_USER_COMMON is set. If set - use it plus /.terraform.versions/
- else use usr.HomeDir plus /.terraform.versions/
I can try to do it, does not look very hard
Is there any progress on this? I would actually like to use a snap version of tfswitch :+1:
I am requesting snapcraft for access to user home: https://forum.snapcraft.io/t/request-interface-personal-files-read-write/25277/3
If you all can upvote the issue, it would be great!
Hi, just wanted to leave my 2ct here:
Using Gitlab for ci/cd.
Gitlab allows specifying a cache from the build-dir (has to be withing the build-dir!).
It would be very helpful if there was a cli-parameter to allow changing ~/.terraform.versions/
to e.g. $PWD/.terraform.versions
.
This way the executables could be cached via Gitlabs mechanism, and there is no/less need to download these from external ressources in every pipeline.
In gitlab-ci.yml this would look sth like this;
.plan:
stage: plan
allow_failure: false
cache:
key: "${CI_COMMIT_REF_SLUG}"
paths:
- ${CI_PROJECT_PATH}/.terraform.versions
script:
- tfswitch -cache=$CI_PROJECT_PATH/.terraform.versions
- terraform init
- terraform validate
...
I also have a need to be able to set a custom the location for the .terraform.versions
directory not related to snap.
any progress on this one?