Comments (20)
I just gave my current user owner on the /usr/local/bin folder and worked like magic.
sudo chown -R $USER /usr/local/bin
Might not be great from a security perspective, but works none the less.
from terraform-switcher.
For me the .tfswitch.toml
solution works perfectly on WSL2 without changing any permissions on /usr/local/bin
# Go to user home
cd
# Install tfswitch
curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | sudo bash
mkdir bin
export BIN_PATH=$(echo $PWD)/bin
# Create .tfswitch.toml
cat >> .tfswitch.toml << EOF
bin = "${BIN_PATH}/terraform"
EOF
# Install your first terraform version
tfswitch
# Put your new binary path to .zshrc or .bashrc
cat >> .zshrc << EOF
export PATH=${BIN_PATH}:\$PATH
EOF
# Restart your console. Done đ
terraform --version
from terraform-switcher.
I'd suggest having tfswitch just install the terraform binaries into the directory that you specify with -b. I keep mine in /home/$USER/bin and put that in my path. Be great if this worked with that. This is kind of broken on linux otherwise
from terraform-switcher.
Just create an alias in your bashrc called tfs
alias tfs="tfswitch -b /home/user/bin"
that way your custom directory alwats persists.
from terraform-switcher.
Guys I fixed here adding sudo after |
curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | sudo bash
But to use tfswitch and Terraform I needed continuous using SUDO
sudo tfswtich
sudo terraform
But works here
Ubuntu 18.04.3 LTS \n \l
from terraform-switcher.
I'm also having issues on Mac because (due to company rules ~/bin/terraform
instead of /usr/local/bin/terraform
. Better still if it could read its config from something like ~/.tfswitch.conf
so I could set the directory in there instead of passing a command line argument every time.
from terraform-switcher.
@evansj @ajjl
I released a pre-released version with the option to install tfswitch
to a user specifed directory.
You can download the pre-release version here (based on your OS): https://github.com/warrensbox/terraform-switcher/releases/tag/0.7.0
- Create bin path directory. Ex:
mkdir /Users/warrenveerasingam/bin
- Add custom bin path to PATH env:
export PATH=$PATH:/Users/warrenveerasingam/bin
- Test pre-release version
./tfswitch -b /Users/warrenveerasingam/bin/terraform
. Install any version. - Validate terraform version.
terraform -v
Otherwise, you can git pull
and compile from the source.
- To compile from the source, you must checkout the
feature/unprivilege-user
branch (https://github.com/warrensbox/terraform-switcher/tree/feature/unprivilege-user) dep ensure
orgo get -v -t -d ./...
go build -v -o tfswitch
- Create bin path directory. Ex:
mkdir /Users/warrenveerasingam/bin
- Add custom bin path to PATH env:
export PATH=$PATH:/Users/warrenveerasingam/bin
- Test pre-release version
./tfswitch -b /Users/warrenveerasingam/bin/terraform
. Install any version. - Validate terraform version.
terraform -v
I will merge feature/unprivilege-user
branch to the master
branch and release it once we can verify it's working as expected.
I will release an option with the ~/.tfswitch.conf
soon but not for this release.
Please feel free to contribute and comment. Thanks for helping me test it out.
from terraform-switcher.
Also seeing this on Mac High Sierra when installed via homebrew
â 0.11.7 Downloading https://releases.hashicorp.com/terraform/0.11.7/terraform_0.11.7_darwin_amd64.zip to terraform_0.11.7_darwin_amd64.zip Downloading ... 17754416 bytes downloaded. 2019/02/11 10:14:25 Unable to create symlink. You must have SUDO privileges
EDIT:
Turns out this was because I already had terraform installed in /usr/local/bin
which meant the symlink couldnt be created. Error message is very misleading and a check for Terraform installs should probably be added.
from terraform-switcher.
@warrensbox I've been using the pre-release version today and it works perfectly - thanks!
from terraform-switcher.
Released : 0.7.737
https://github.com/warrensbox/terraform-switcher/releases/tag/0.7.737
Features:
Option to use -b parameter to specify custom terraform installtion location:
tfswitch -b /Users/warrenveerasingam/bin/terraform 0.10.8
Option to use .tfswitch.toml
file. For example:
bin = "/Users/warrenveerasingam/bin/terraform"
version = "0.11.3"
After that, you can simply run tfswitch
and it should automatically update your terraform version according to the configuration provided.
Automatically switch with bash
Add the following to the end of your ~/.bashrc file: (Use either .tfswitchrc or .tfswitch.toml)
cdtfswitch(){
builtin cd "$@";
cdir=$PWD;
if [ -f "$cdir/.tfswitchrc" ]; then
tfswitch
fi
}
alias cd='cdtfswitch'
Automatically switch with zsh
Add the following to the end of your ~/.zshrc file:
load-tfswitch() {
local tfswitchrc_path=".tfswitch.toml"
if [ -f "$tfswitchrc_path" ]; then
tfswitch
fi
}
add-zsh-hook chpwd load-tfswitch
load-tfswitch
NOTE: if you see an error like this: command not found: add-zsh-hook, then you might be on an older version of zsh (see below), or you simply need to load add-zsh-hook by adding this to your .zshrc:
autoload -U add-zsh-hook
older version of zsh
cd(){
builtin cd "$@";
cdir=$PWD;
if [ -f "$cdir/.tfswitch.toml" ]; then
tfswitch
fi
}
To get the latest version of tfswitch
:
With Brew:
brew upgrade warrensbox/tap/tfswitch
Other upgrades:
curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | bash
Please open or comment on this issue if you see any bug!
from terraform-switcher.
@ajjl I will look at this
from terraform-switcher.
I have updated the symlink error message to be more intuitive. The previous error message was misleading. Merge request #38 :
log.Fatalf(`
Unable to create new symlink.
Maybe symlink already exist. Try removing existing symlink manually.
Try running "unlink %s" to remove existing symlink.
If error persist, you may not have the permission to create a symlink at %s.
Error: %s`, dir, dir, err)
@ajjl requested a feature to allow users without admin privilege to install tfswitch. This feature is still not supported at the moment. However, please feel free to contribute and open a merge request to add this feature.
from terraform-switcher.
@MichaelSmyth0184 that would work great. Unfortunately I can't do that, due to the aforementioned company rules...
from terraform-switcher.
@evansj Yeah I guess having sudo permissions is a luxery at some companies...
Have you tried downloading from source and modifying destination folder to something you have ownership over? Shouldn't be too difficult I would imagine.
from terraform-switcher.
@MichaelSmyth0184 I intend to do that, and hopefully create a PR
from terraform-switcher.
@evansj @ajjl
I released a pre-released version with the option to installtfswitch
to a user specifed directory.You can download the pre-release version here (based on your OS): https://github.com/warrensbox/terraform-switcher/releases/tag/0.7.0
- Create bin path directory. Ex:
mkdir /Users/warrenveerasingam/bin
- Add custom bin path to PATH env:
export PATH=$PATH:/Users/warrenveerasingam/bin
- Test pre-release version
./tfswitch -b /Users/warrenveerasingam/bin/terraform
. Install any version.- Validate terraform version.
terraform -v
Otherwise, you can
git pull
and compile from the source.
- To compile from the source, you must checkout the
feature/unprivilege-user
branch (https://github.com/warrensbox/terraform-switcher/tree/feature/unprivilege-user)dep ensure
orgo get -v -t -d ./...
go build -v -o tfswitch
- Create bin path directory. Ex:
mkdir /Users/warrenveerasingam/bin
- Add custom bin path to PATH env:
export PATH=$PATH:/Users/warrenveerasingam/bin
- Test pre-release version
./tfswitch -b /Users/warrenveerasingam/bin/terraform
. Install any version.- Validate terraform version.
terraform -v
I will merge
feature/unprivilege-user
branch to themaster
branch and release it once we can verify it's working as expected.I will release an option with the
~/.tfswitch.conf
soon but not for this release.Please feel free to contribute and comment. Thanks for helping me test it out.
Thanks, This works for mac!!
from terraform-switcher.
I just gave my current user owner on the /usr/local/bin folder and worked like magic.
sudo chown -R $USER /usr/local/bin
Might not be great from a security perspective, but works none the less.
This actually works well if you just want the solution for local wsl2 usage.
from terraform-switcher.
@warrensbox any chance you will be fixing this on WSL Ubuntu? I have tried everything above, even chown of /usr/local/bin and nothing works. Not sure why there is a need to put everything in /usr/local/bin why can't a user just install to their home directory. BTW it worked great a couple years ago on my MAC and its a great concept, but it leaves a lot of us users out if it does not work in WSL or WSL2
from terraform-switcher.
Seems I got it to work with using snap install. BUT all that said when I open another terminal I get the same issue I have to sudo to use it, if I stay in the terminal that I installed it on I do not have to use sudo... FYI snap on WSL would not work until I ran these commands.
sudo apt-get update && sudo apt-get install -yqq daemonize dbus-user-session fontconfig sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME
https://github.com/microsoft/WSL/issues/5126
from terraform-switcher.
For anyone coming to this thread in 2022...
This script;
- Works on WSL2 âī¸
- doesn't require
sudo
âī¸ - installs it only for the current user
Note: I chose ~/bin
for TFSWITCH_DIR
as that is also where tfswitch
installs the terraform binaries. And, I've confirmed that changing terraform versions will not result in the tfswitch
binary being removed.
# Location of where you'd like to save the binary
# This is not important to tfswitch, only important to this here script
TFSWITCH_DIR=~/bin
# go to home dir
cd ~
# download the install script
curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh >> install.sh
# ensure the directory for the `tfswitch` bin exists
mkdir -p $TFSWITCH_DIR
# run install script (with -b to indicate desired path to save binary)
sh install.sh -b $TFSWITCH_DIR
# remove the install script as it is no longer needed
rm install.sh
# add the TFSWITCH_DIR to your path so the binaries can be executed from anywhere
# NOTE: this may be ~/.bashrc, or ~/.zshrc, or others, but if you don't know, safest not to change it
echo 'export PATH="$PATH:'$TFSWITCH_DIR'"' >> ~/.bash_profile
If you cannot use tfswitch
after restarting your terminal session...
- check the
tfswitch
binary exists at the path you specified for$TFSWITCH_DIR
a. if it does exist, the last step is where things went wrong - it likely added theexport
to a
file that is not included in your bash profile - The "Where to put it" section in this may help you. - if you ran into issues at the installation step, try replacing
sh
withbash
from terraform-switcher.
Related Issues (20)
- Error in v1.10 parsing version HOT 3
- Any content in terragrunt.hcl other than "terraform_version_constraint" causes tfswitch to error HOT 7
- We are facing the issue with the latest version(v1.1.0) of tfswitcher HOT 2
- v1.1.0 does not parse tf version constraint correctly HOT 5
- install.sh does not support non v-prefixed tags HOT 3
- Terraform `1.8.2` ships additional file within tarball
- Reading automatically from ~/.tfswitch.toml is broken HOT 17
- `log-level` TOML config doesn't work HOT 1
- How do I turn off logging? HOT 8
- tfswitch ignored -b argument HOT 5
- v1.1.1 ignoring `required_version` HOT 1
- Install script issue HOT 3
- Move away from golang openpgp HOT 2
- Version: v1.1.1 no longer reads terraform required_version anymore HOT 29
- tfswitch -v should not apply anything - it should only print the tfswitch version HOT 4
- terraform file extraction does not work under windows
- Standardise logic for failing/warning when an error occurs during terraform version detection HOT 4
- [Feature request] Disable color logs when not a terminal HOT 3
- Add additional debug logs when determining version from various sources
- Re-add support for environment variable that is a default version
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ī¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-switcher.