You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.versions is created. I would propose tfswitch --local-binary-dir or something similar.
manipulate the PATH variable to run set PATH=/var/lib/postgresql/bin:$PATH in 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.
The text was updated successfully, but these errors were encountered:
From my understanding, you're wanting to run tfswitch, which ends up placing a binary in directory that is not part of PATH and then want the PATH environment variable of the shell to be updated?
If so, as far as my understanding goes, this isn't possible.
When you execute a command on linux, it performs a "fork" , which spawns a sub-process that copies (among other things) the environment variables from the parent process.
However, any changes to the environment variable are not persisted to the parent process.
This can be shown in this example:
$ cat main.go
package main
import "os"
func main() {
os.Setenv("TEST", "HI")
}
$ env | grep -i test
$ go run ./main.go
$ env | grep -i test
The easiest way to achieve this, I think, would be to:
create your own directory first (e.g. ~/.bin),
run tfswitch with the --bin flag ^1,
set PATH environment variable with your chosen directory
e.g.
# Define and create bin directory for Terraform
TERRAFORM_BIN_DIR=/tmp/terraform_bin
mkdir $TERRAFORM_BIN_DIR
# Run tfswitch specifying the bin directory
tfswitch --bin=$TERRAFORM_BIN_DIR
# Set environment variable to allow execution of 'terraform'
export PATH=$PATH:$TERRAFORM_BIN_DIR
terraform --version
Recently, in our automated CI, when using a new hardened docker image to test things, I see the log:
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/binto 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:.terraform.versions
is created. I would proposetfswitch --local-binary-dir
or something similar.PATH=/var/lib/postgresql/bin:$PATH
in 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.
The text was updated successfully, but these errors were encountered: