Skip to content

Commit

Permalink
Merge pull request #49 from warrensbox/master
Browse files Browse the repository at this point in the history
New feature - option to install terraform in a custom location
  • Loading branch information
warrensbox authored Jun 10, 2019
2 parents ab38804 + 7e579a6 commit 6789a3f
Show file tree
Hide file tree
Showing 246 changed files with 73,028 additions and 55 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ docs/.bundle/**

.tfswitchrc

tfswitch
tfswitch*

build-script.sh

.tfswitch.toml
118 changes: 118 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 67 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,69 @@ The most recently selected versions are presented at the top of the dropdown.
3. Hit **Enter** to select the desired version.


### Use .tfswitch.toml file (For uprivilege users/ non-admin - users with limited privilege on their computer)
This is similiar to using a .tfswitchrc file, but you can specify a custom binary path for your terraform installation

<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/tfswitch-v8.gif" alt="drawing" style="width: 170px;"/>

1. Create a custom binary path. Ex: `mkdir /Users/warrenveerasingam/bin` (replace warrenveerasingam with your username)
2. Add the path to your PATH. Ex: `export PATH=$PATH:/Users/warrenveerasingam/bin` (add this to your bash profile or zsh profile)
3. Pass -b or --bin parameter with your custom path to install terraform. Ex: `tfswitch -b /Users/warrenveerasingam/bin/terraform 0.10.8 `
4. Optionally, you can create a `.tfswitch.toml` file in your terraform directory.
5. Your `.tfswitch.toml` file should look like this:
```
bin = "/Users/warrenveerasingam/bin/terraform"
version = "0.11.3"
```
4. Run `tfswitch` and it should automatically install the required terraform version in the specified binary path

<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/tfswitch-v7.gif" alt="drawing" style="width: 170px;"/>

**Automatically switch with bash**

Add the following to the end of your `~/.bashrc` file:
```
cdtfswitch(){
builtin cd "$@";
cdir=$PWD;
if [ -f "$cdir/.tfswitch.toml" ]; 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/.tfswitchrc" ]; then
tfswitch
fi
}
```

### Use .tfswitchrc file
<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/tfswitch-v6.gif" alt="drawing" style="width: 170px;"/>

Expand Down Expand Up @@ -102,6 +165,10 @@ load-tfswitch() {
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*
```
Expand All @@ -122,10 +189,3 @@ See how to *upgrade*, *uninstall*, *troubleshoot* here:[More info](https://warre
## Issues

Please open *issues* here: [New Issue](https://github.com/warrensbox/terraform-switcher/issues)







6 changes: 3 additions & 3 deletions docs/_site/additional.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{"description":"Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform","@type":"WebPage","url":"/additional.html","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"/assets/img/logo.png"}},"headline":"tfswitch","@context":"http://schema.org"}</script>
<!-- End Jekyll SEO tag -->

<link rel="stylesheet" href="/assets/css/style.css?v=53c4a658dbed6fd2f05b5ffb643fb2bd96cbbf88">
<link rel="stylesheet" href="/assets/css/style.css?v=6d07d7f358b39ef797c837ef812a979456d32f5f">
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
<![endif]-->
Expand Down Expand Up @@ -57,8 +57,8 @@


<ul>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.5.642/terraform-switcher_0.5.642_darwin_amd64.tar.gz">Download <strong>MacOS</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.5.642/terraform-switcher_0.5.642_linux_amd64.tar.gz">Download <strong>Linux</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.7.0/terraform-switcher_0.7.0_darwin_amd64.tar.gz">Download <strong>MacOS</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.7.0/terraform-switcher_0.7.0_linux_amd64.tar.gz">Download <strong>Linux</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases">Releases On <strong>GitHub</strong></a></li>
</ul>

Expand Down
74 changes: 71 additions & 3 deletions docs/_site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{"name":"tfswitch","description":"Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform","@type":"WebSite","url":"/","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"/assets/img/logo.png"}},"headline":"Terraform Switcher","@context":"http://schema.org"}</script>
<!-- End Jekyll SEO tag -->

<link rel="stylesheet" href="/assets/css/style.css?v=53c4a658dbed6fd2f05b5ffb643fb2bd96cbbf88">
<link rel="stylesheet" href="/assets/css/style.css?v=6d07d7f358b39ef797c837ef812a979456d32f5f">
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
<![endif]-->
Expand Down Expand Up @@ -57,8 +57,8 @@


<ul>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.5.642/terraform-switcher_0.5.642_darwin_amd64.tar.gz">Download <strong>MacOS</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.5.642/terraform-switcher_0.5.642_linux_amd64.tar.gz">Download <strong>Linux</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.7.0/terraform-switcher_0.7.0_darwin_amd64.tar.gz">Download <strong>MacOS</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.7.0/terraform-switcher_0.7.0_linux_amd64.tar.gz">Download <strong>Linux</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases">Releases On <strong>GitHub</strong></a></li>
</ul>

Expand Down Expand Up @@ -128,6 +128,69 @@ <h3 id="see-all-versions-including-beta-alpha-and-release-candidatesrc">See all
<li>Hit <strong>Enter</strong> to select the desired version.</li>
</ol>

<h3 id="use-tfswitchtoml-file--for-uprivilege-users-non-admin---users-with-limited-privilege-on-their-computer">Use .tfswitch.toml file (For uprivilege users/ non-admin - users with limited privilege on their computer)</h3>
<p>This is similiar to using a .tfswitchrc file, but you can specify a custom binary path for your terraform installation</p>

<p><img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/tfswitch-v8.gif" alt="drawing" style="width: 170px;" /></p>

<ol>
<li>Create a custom binary path. Ex: <code class="highlighter-rouge">mkdir /Users/warrenveerasingam/bin</code> (replace warrenveerasingam with your username)</li>
<li>Add the path to your PATH. Ex: <code class="highlighter-rouge">export PATH=$PATH:/Users/warrenveerasingam/bin</code> (add this to your bash profile or zsh profile)</li>
<li>Pass -b or –bin parameter with your custom path to install terraform. Ex: <code class="highlighter-rouge">tfswitch -b /Users/warrenveerasingam/bin/terraform 0.10.8 </code></li>
<li>Optionally, you can create a <code class="highlighter-rouge">.tfswitch.toml</code> file in your terraform directory.</li>
<li>Your <code class="highlighter-rouge">.tfswitch.toml</code> file should look like this:
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bin = "/Users/warrenveerasingam/bin/terraform"
version = "0.11.3"
</code></pre></div> </div>
</li>
<li>Run <code class="highlighter-rouge">tfswitch</code> and it should automatically install the required terraform version in the specified binary path</li>
</ol>

<p><img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/tfswitch-v7.gif" alt="drawing" style="width: 170px;" /></p>

<p><strong>Automatically switch with bash</strong></p>

<p>Add the following to the end of your <code class="highlighter-rouge">~/.bashrc</code> file:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cdtfswitch(){
builtin cd "$@";
cdir=$PWD;
if [ -f "$cdir/.tfswitch.toml" ]; then
tfswitch
fi
}
alias cd='cdtfswitch'
</code></pre></div></div>

<p><strong>Automatically switch with zsh</strong></p>

<p>Add the following to the end of your <code class="highlighter-rouge">~/.zshrc</code> file:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>load-tfswitch() {
local tfswitchrc_path=".tfswitch.toml"

if [ -f "$tfswitchrc_path" ]; then
tfswitch
fi
}
add-zsh-hook chpwd load-tfswitch
load-tfswitch
</code></pre></div></div>
<blockquote>
<p>NOTE: if you see an error like this: <code class="highlighter-rouge">command not found: add-zsh-hook</code>, then you might be on an older version of zsh (see below), or you simply need to load <code class="highlighter-rouge">add-zsh-hook</code> by adding this to your <code class="highlighter-rouge">.zshrc</code>:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code> autoload -U add-zsh-hook
</code></pre></div> </div>
</blockquote>

<p><em>older version of zsh</em></p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cd(){
builtin cd "$@";
cdir=$PWD;
if [ -f "$cdir/.tfswitchrc" ]; then
tfswitch
fi
}
</code></pre></div></div>

<h3 id="use-tfswitchrc-file">Use .tfswitchrc file</h3>
<p><img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/tfswitch-v6.gif" alt="drawing" style="width: 490px;" /></p>

Expand Down Expand Up @@ -164,6 +227,11 @@ <h3 id="use-tfswitchrc-file">Use .tfswitchrc file</h3>
add-zsh-hook chpwd load-tfswitch
load-tfswitch
</code></pre></div></div>
<blockquote>
<p>NOTE: if you see an error like this: <code class="highlighter-rouge">command not found: add-zsh-hook</code>, then you might be on an older version of zsh (see below), or you simply need to load <code class="highlighter-rouge">add-zsh-hook</code> by adding this to your <code class="highlighter-rouge">.zshrc</code>:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code> autoload -U add-zsh-hook
</code></pre></div> </div>
</blockquote>

<p><em>older version of zsh</em></p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cd(){
Expand Down
Loading

0 comments on commit 6789a3f

Please sign in to comment.