-
Notifications
You must be signed in to change notification settings - Fork 143
Description
Recently, in our automated CI, when using a new hardened docker image to test things, I see the log:
[source] Executing: tfswitch 1.1.2
++++++ tfswitch 1.1.2
Creating directory for terraform binary at: /var/lib/postgresql/.terraform.versions
Unable to write to: /usr/local/bin/terraform
Creating bin directory at: /var/lib/postgresql/bin
Creating directory for terraform binary at: /var/lib/postgresql/bin
RUN `export PATH=$PATH:/var/lib/postgresql/bin` to append bin to $PATH
Downloading to: /var/lib/postgresql/.terraform.versions
18687805 bytes downloaded
Switched terraform to version "1.1.2"
Obviously, tfswitch is smart enough to know that it cannot write to /usr/local/bin/terraform and then falls back to using the logged in user's $HOME/bin directory to create the symlink to the Terraform version.
However, after that it expects a manual run of the command on the console like so RUN export PATH=$PATH:/var/lib/postgresql/bin to append bin to $PATH, and does indeed prompt the user to do so.
Describe the solution you'd like
Proposal
Add more sub-command options to tfswitch to:
- list the current directory where
.terraform.versionsis created. I would proposetfswitch --local-binary-diror something similar. - manipulate the PATH variable to run set
PATH=/var/lib/postgresql/bin:$PATHin case this permission denied error is hit. Note the binary/symlink PATH is prefixed to the PATH variable and not suffixed.
Describe alternatives you've considered
Currently, we have code to check the dir location manually and do all this in a dirty shell script, which frankly can be improved by a lot if the above proposal is accepted.