Skip to content

Commit

Permalink
Merge pull request #38 from warrensbox/master
Browse files Browse the repository at this point in the history
New feature
-Option to automatically switch to desired Terraform version by reading .tfswitchrc file. Similar idea to nvm. (by @MarcusNoble ) .  
-Unit test for validating correct terraform version .  
-Update symlink error message to be more intuitive
  • Loading branch information
warrensbox authored Apr 8, 2019
2 parents ee53c7b + d4385dd commit c7ef74a
Show file tree
Hide file tree
Showing 14 changed files with 362 additions and 63 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ docs/vendor/**

docs/.bundle/**

.sass-cache
.sass-cache

.tfswitchrc

tfswitch
28 changes: 24 additions & 4 deletions Gopkg.lock

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

62 changes: 55 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/warrensbox/terraform-switcher)](https://goreportcard.com/report/github.com/warrensbox/terraform-switcher)
[![CircleCI](https://circleci.com/gh/warrensbox/terraform-switcher/tree/master.svg?style=shield&circle-token=55ddceec95ff67eb38269152282f8a7d761c79a5)](https://circleci.com/gh/warrensbox/terraform-switcher)

# Terraform Switcher
# Terraform Switcher

<img style="text-allign:center" src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/smallerlogo.png" alt="drawing" width="120" height="130"/>

<!-- ![gopher](https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/logo.png =100x20) -->

The `tfswitch` command line tool lets you switch between different versions of [terraform](https://www.terraform.io/).
The `tfswitch` command line tool lets you switch between different versions of [terraform](https://www.terraform.io/).
If you do not have a particular version of terraform installed, `tfswitch` will download the version you desire.
The installation is minimal and easy.
Once installed, simply select the version you require from the dropdown and start using terraform.
The installation is minimal and easy.
Once installed, simply select the version you require from the dropdown and start using terraform.

See installation guide here: [tfswitch installation](https://warrensbox.github.io/terraform-switcher/)

Expand All @@ -21,7 +21,7 @@ See installation guide here: [tfswitch installation](https://warrensbox.github.i

### Homebrew

Installation for MacOS is the easiest with Homebrew. [If you do not have homebrew installed, click here](https://brew.sh/).
Installation for MacOS is the easiest with Homebrew. [If you do not have homebrew installed, click here](https://brew.sh/).


```ruby
Expand All @@ -38,13 +38,13 @@ curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/

### Install from source

Alternatively, you can install the binary from source [here](https://github.com/warrensbox/terraform-switcher/releases)
Alternatively, you can install the binary from source [here](https://github.com/warrensbox/terraform-switcher/releases)

## How to use:
### Use dropdown menu to select version
<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/tfswitch.gif" alt="drawing" style="width: 180px;"/>

1. You can switch between different versions of terraform by typing the command `tfswitch` on your terminal.
1. You can switch between different versions of terraform by typing the command `tfswitch` on your terminal.
2. Select the version of terraform you require by using the up and down arrow.
3. Hit **Enter** to select the desired version.

Expand All @@ -57,6 +57,54 @@ The most recently selected versions are presented at the top of the dropdown.
2. For example, `tfswitch 0.10.5` for version 0.10.5 of terraform.
3. Hit **Enter** to switch.

### Use .tfswitchrc file

1. Create a `.tfswitchrc` file containing the desired version
2. For example, `echo "0.10.5" >> .tfswitchrc` for version 0.10.5 of terraform
3. Run the command `tfswitch` in the same directory as your `.tfswitchrc`


**Automatically switch with bash**

Add the following to the end of your `~/.bashrc` file:
```
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=".tfswitchrc"
if [ -f "$tfswitchrc_path" ]; then
tfswitch
fi
}
add-zsh-hook chpwd load-tfswitch
load-tfswitch
```

*older version of zsh*
```
cd(){
builtin cd "$@";
cdir=$PWD;
if [ -f "$cdir/.tfswitchrc" ]; then
tfswitch
fi
}
```

## Additional Info

See how to *upgrade*, *uninstall*, *troubleshoot* here:[More info](https://warrensbox.github.io/terraform-switcher/additional)
Expand Down
4 changes: 2 additions & 2 deletions docs/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@

{{ content }}
{% if site.github.is_project_page %}
<p><small>VERSION: {{ site.github.releases[0].tag_name }}. This project is maintained by <a href="{{ site.github.owner_url }}">{{ site.github.owner_name }}</a></small></p>
<p><small>This project is maintained by <a href="{{ site.github.owner_url }}">{{ site.github.owner_name }}</a></small></p>
{% endif %}
</section>
<footer>
<!-- <p><small>View other products &mdash; by <a href="http://warren.veerasingam.com/#about_me" target="_blank">Warren Veerasingam</a></small></p> -->
<p><small>VERSION: {{ site.github.releases[0].tag_name }}. This project is maintained by <a href="{{ site.github.owner_url }}">{{ site.github.owner_name }}</a></small></p>
<p><small>This project is maintained by <a href="{{ site.github.owner_url }}">{{ site.github.owner_name }}</a></small></p>
</footer>
</div>
<script src="{{ "/assets/js/scale.fix.js" | relative_url }}"></script>
Expand Down
18 changes: 10 additions & 8 deletions docs/_site/additional.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
<meta property="og:locale" content="en_US" />
<meta name="description" content="Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform" />
<meta property="og:description" content="Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform" />
<link rel="canonical" href="http://localhost:4000/additional.html" />
<meta property="og:url" content="http://localhost:4000/additional.html" />
<meta property="og:site_name" content="tfswitch" />
<script type="application/ld+json">
{"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>
{"description":"Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform","@type":"WebPage","url":"http://localhost:4000/additional.html","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"http://localhost:4000/assets/img/logo.png"}},"headline":"tfswitch","@context":"http://schema.org"}</script>
<!-- End Jekyll SEO tag -->

<link rel="stylesheet" href="/assets/css/style.css?v=3113bfa1fc6d5c3ee7ee24ef78c5e90c3232615c">
<link rel="stylesheet" href="/assets/css/style.css?v=1ead8e0ef849a39a64a66a55ecab86069398dcfd">
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
<![endif]-->
Expand All @@ -41,8 +43,8 @@
<body>
<div class="wrapper">
<header>
<!-- <h1 style="font-size:25px;"><a href="/">tfswitch</a></h1> -->
<!-- <h1 style="font-size:25px; text-align: center"><a href="/">tfswitch</a></h1> -->
<!-- <h1 style="font-size:25px;"><a href="http://localhost:4000/">tfswitch</a></h1> -->
<!-- <h1 style="font-size:25px; text-align: center"><a href="http://localhost:4000/">tfswitch</a></h1> -->

<p align="center">
<img align="middle" src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/logo.png" alt="Logo" />
Expand All @@ -57,8 +59,8 @@


<ul>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.4.595/terraform-switcher_0.4.595_darwin_amd64.tar.gz">Download <strong>MacOS</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.4.595/terraform-switcher_0.4.595_linux_amd64.tar.gz">Download <strong>Linux</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.4.611/terraform-switcher_0.4.611_darwin_amd64.tar.gz">Download <strong>MacOS</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.4.611/terraform-switcher_0.4.611_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 @@ -111,12 +113,12 @@ <h2 id="troubleshoot">Troubleshoot:</h2>
<a href="index">Back to main</a></p>


<p><small>VERSION: 0.4.595. This project is maintained by <a href="http://github.com/warrensbox">warrensbox</a></small></p>
<p><small>This project is maintained by <a href="http://github.com/warrensbox">warrensbox</a></small></p>

</section>
<footer>
<!-- <p><small>View other products &mdash; by <a href="http://warren.veerasingam.com/#about_me" target="_blank">Warren Veerasingam</a></small></p> -->
<p><small>VERSION: 0.4.595. This project is maintained by <a href="http://github.com/warrensbox">warrensbox</a></small></p>
<p><small>This project is maintained by <a href="http://github.com/warrensbox">warrensbox</a></small></p>
</footer>
</div>
<script src="/assets/js/scale.fix.js"></script>
Expand Down
64 changes: 56 additions & 8 deletions docs/_site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
<meta property="og:locale" content="en_US" />
<meta name="description" content="Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform" />
<meta property="og:description" content="Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform" />
<link rel="canonical" href="http://localhost:4000/" />
<meta property="og:url" content="http://localhost:4000/" />
<meta property="og:site_name" content="tfswitch" />
<script type="application/ld+json">
{"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>
{"name":"tfswitch","description":"Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform","@type":"WebSite","url":"http://localhost:4000/","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"http://localhost:4000/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=3113bfa1fc6d5c3ee7ee24ef78c5e90c3232615c">
<link rel="stylesheet" href="/assets/css/style.css?v=1ead8e0ef849a39a64a66a55ecab86069398dcfd">
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
<![endif]-->
Expand All @@ -41,8 +43,8 @@
<body>
<div class="wrapper">
<header>
<!-- <h1 style="font-size:25px;"><a href="/">tfswitch</a></h1> -->
<!-- <h1 style="font-size:25px; text-align: center"><a href="/">tfswitch</a></h1> -->
<!-- <h1 style="font-size:25px;"><a href="http://localhost:4000/">tfswitch</a></h1> -->
<!-- <h1 style="font-size:25px; text-align: center"><a href="http://localhost:4000/">tfswitch</a></h1> -->

<p align="center">
<img align="middle" src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/logo.png" alt="Logo" />
Expand All @@ -57,8 +59,8 @@


<ul>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.4.595/terraform-switcher_0.4.595_darwin_amd64.tar.gz">Download <strong>MacOS</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.4.595/terraform-switcher_0.4.595_linux_amd64.tar.gz">Download <strong>Linux</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.4.611/terraform-switcher_0.4.611_darwin_amd64.tar.gz">Download <strong>MacOS</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.4.611/terraform-switcher_0.4.611_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 @@ -119,6 +121,52 @@ <h3 id="supply-version-on-command-line">Supply version on command line</h3>
<li>Hit <strong>Enter</strong> to switch.</li>
</ol>

<h3 id="use-tfswitchrc-file">Use .tfswitchrc file</h3>

<ol>
<li>Create a <code class="highlighter-rouge">.tfswitchrc</code> file containing the desired version</li>
<li>For example, <code class="highlighter-rouge">echo "0.10.5" &gt;&gt; .tfswitchrc</code> for version 0.10.5 of terraform</li>
<li>Run the command <code class="highlighter-rouge">tfswitch</code> in the same directory as your <code class="highlighter-rouge">.tfswitchrc</code></li>
</ol>

<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/.tfswitchrc" ]; 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=".tfswitchrc"

if [ -f "$tfswitchrc_path" ]; then
tfswitch
fi
}
add-zsh-hook chpwd load-tfswitch
load-tfswitch
</code></pre></div></div>

<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>

<hr />

<h2 id="issues">Issues</h2>
Expand All @@ -131,12 +179,12 @@ <h2 id="issues">Issues</h2>
<a href="additional">Additional Info</a></p>


<p><small>VERSION: 0.4.595. This project is maintained by <a href="http://github.com/warrensbox">warrensbox</a></small></p>
<p><small>This project is maintained by <a href="http://github.com/warrensbox">warrensbox</a></small></p>

</section>
<footer>
<!-- <p><small>View other products &mdash; by <a href="http://warren.veerasingam.com/#about_me" target="_blank">Warren Veerasingam</a></small></p> -->
<p><small>VERSION: 0.4.595. This project is maintained by <a href="http://github.com/warrensbox">warrensbox</a></small></p>
<p><small>This project is maintained by <a href="http://github.com/warrensbox">warrensbox</a></small></p>
</footer>
</div>
<script src="/assets/js/scale.fix.js"></script>
Expand Down
Loading

0 comments on commit c7ef74a

Please sign in to comment.