Skip to content

tfswitch to enable querying current binary install location and list installed binaries #270

@krish7919

Description

@krish7919

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:

  1. list the current directory where .terraform.versions is created. I would propose tfswitch --local-binary-dir or something similar.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementRefactor existing code for better performance and quality

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions