Skip to content

Commit

Permalink
Merge pull request #78 from warrensbox/master
Browse files Browse the repository at this point in the history
Add new feature to read version from terraform file (version.tf)
  • Loading branch information
warrensbox authored Apr 16, 2020
2 parents ba54688 + cbe50fb commit 69e9d24
Show file tree
Hide file tree
Showing 12 changed files with 381 additions and 40 deletions.
5 changes: 2 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/golang:1.10
- image: circleci/golang:1.13

working_directory: /go/src/github.com/warrensbox/terraform-switcher

Expand All @@ -22,7 +22,7 @@ jobs:
release:
docker:
- image: circleci/golang:1.11
- image: circleci/golang:1.13

working_directory: /go/src/github.com/warrensbox/terraform-switcher

Expand All @@ -37,7 +37,6 @@ jobs:
export RELEASE_VERSION;
echo $RELEASE_VERSION
mkdir -p /home/circleci/bin
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
export PATH="/home/warrensbox/bin:${PATH}"
rm -rf dist
git config user.email "warren.veerasingam@gmail.com"
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: go
install: true

go:
- "1.10.1"
- "1.13.4"

script:
- make test
Expand Down
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ PATH := build:$(PATH)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)

$(EXE): Gopkg.lock *.go lib/*.go
$(EXE): go.mod *.go lib/*.go
go build -v -ldflags "-X main.version=$(VER)" -o $@ $(PKG)

Gopkg.lock: Gopkg.toml
dep ensure

.PHONY: release
release: $(EXE) darwin linux

Expand All @@ -27,11 +24,6 @@ test: $(EXE)
mv $(EXE) build
go test -v ./...


.PHONEY: dep
dep:
dep ensure

.PHONY: docs
docs:
cd docs; bundle install --path vendor/bundler; bundle exec jekyll build -c _config.yml; cd ..
Expand Down
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,25 @@ The most recently selected versions are presented at the top of the dropdown.
2. For example, `tfswitch -l` or `tfswitch --list-all` to see all versions.
3. Hit **Enter** to select the desired version.

### Use version.tf file
If a .tf file with the terraform constrain is included in the current directory, it should automatically download or switch to that terraform version. For example, the following should automatically switch terraform to version `0.12.24`:
```
terraform {
required_version = ">= 0.12.9"
required_providers {
aws = ">= 2.52.0"
kubernetes = ">= 1.11.1"
}
}
```
<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/versiontf.gif" alt="drawing" style="width: 170px;"/>


### Use .tfswitch.toml file (For non-admin - users with limited privilege on their computers)
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-v7.gif" alt="drawing" style="width: 170px;"/>
<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/tfswitch-v7.gif" alt="drawing" style="width: 170px;"/>
<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)
Expand All @@ -89,7 +103,7 @@ version = "0.11.3"
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`

*Instead of a `.tfswitchrc` file, a `.terraform-version` file may be used for compatibility with [`tfenv`](https://github.com/tfutils/tfenv#terraform-version-file) and other tools which use it*
#### *Instead of a `.tfswitchrc` file, a `.terraform-version` file may be used for compatibility with [`tfenv`](https://github.com/tfutils/tfenv#terraform-version-file) and other tools which use it*

**Automatically switch with bash**

Expand All @@ -100,7 +114,7 @@ Add the following to the end of your `~/.bashrc` file:
cdtfswitch(){
builtin cd "$@";
cdir=$PWD;
if [ -f "$cdir/.tfswitchrc" ]; then
if [ -e "$cdir/.tfswitchrc" ]; then
tfswitch
fi
}
Expand Down Expand Up @@ -132,7 +146,7 @@ load-tfswitch
cd(){
builtin cd "$@";
cdir=$PWD;
if [ -f "$cdir/.tfswitchrc" ]; then
if [ -e "$cdir/.tfswitchrc" ]; then
tfswitch
fi
}
Expand Down
16 changes: 8 additions & 8 deletions docs/_site/additional.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
<link rel="icon" type="image/png" href="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/favicon_tfswitch_48.png" sizes="48x48">

<!-- Begin Jekyll SEO tag v2.5.0 -->
<title>tfswitch | Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform</title>
<title>tfswitch | A command line tool to switch between different versions of terraform (with homebrew and more)</title>
<meta name="generator" content="Jekyll v3.7.4" />
<meta property="og:title" content="tfswitch" />
<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" />
<meta name="description" content="A command line tool to switch between different versions of terraform (with homebrew and more)" />
<meta property="og:description" content="A command line tool to switch between different versions of terraform (with homebrew and more)" />
<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":"A command line tool to switch between different versions of terraform (with homebrew and more)","@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=0b7be9932efc2fc12b75f7de015e535bb13fda26">
<link rel="stylesheet" href="/assets/css/style.css?v=f5e109f991b60d7b366dd9892814bbf35c247763">
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
<![endif]-->
Expand Down Expand Up @@ -51,7 +51,7 @@
<img align="middle" src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/logo.png" alt="Logo" />
</p>

<p style="text-align: center">Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform</p>
<p style="text-align: center">A command line tool to switch between different versions of terraform (with homebrew and more)</p>
<!-- <p>Written in go</p> -->
<img src="https://travis-ci.org/warrensbox/terraform-switcher.svg?branch=master" alt="Travis" />
<img src="https://goreportcard.com/badge/github.com/warrensbox/terraform-switcher" alt="Go Report" />
Expand All @@ -60,8 +60,8 @@


<ul>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.7.737/terraform-switcher_0.7.737_darwin_amd64.tar.gz">Download <strong>MacOS</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.7.737/terraform-switcher_0.7.737_linux_amd64.tar.gz">Download <strong>Linux</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.7.817/terraform-switcher_0.7.817_darwin_amd64.tar.gz">Download <strong>MacOS</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.7.817/terraform-switcher_0.7.817_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
31 changes: 22 additions & 9 deletions docs/_site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
<meta name="generator" content="Jekyll v3.7.4" />
<meta property="og:title" content="Terraform Switcher" />
<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" />
<meta name="description" content="A command line tool to switch between different versions of terraform (with homebrew and more)" />
<meta property="og:description" content="A command line tool to switch between different versions of terraform (with homebrew and more)" />
<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":"A command line tool to switch between different versions of terraform (with homebrew and more)","@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=0b7be9932efc2fc12b75f7de015e535bb13fda26">
<link rel="stylesheet" href="/assets/css/style.css?v=f5e109f991b60d7b366dd9892814bbf35c247763">
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
<![endif]-->
Expand Down Expand Up @@ -51,7 +51,7 @@
<img align="middle" src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/logo.png" alt="Logo" />
</p>

<p style="text-align: center">Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform</p>
<p style="text-align: center">A command line tool to switch between different versions of terraform (with homebrew and more)</p>
<!-- <p>Written in go</p> -->
<img src="https://travis-ci.org/warrensbox/terraform-switcher.svg?branch=master" alt="Travis" />
<img src="https://goreportcard.com/badge/github.com/warrensbox/terraform-switcher" alt="Go Report" />
Expand All @@ -60,8 +60,8 @@


<ul>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.7.737/terraform-switcher_0.7.737_darwin_amd64.tar.gz">Download <strong>MacOS</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.7.737/terraform-switcher_0.7.737_linux_amd64.tar.gz">Download <strong>Linux</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.7.817/terraform-switcher_0.7.817_darwin_amd64.tar.gz">Download <strong>MacOS</strong></a></li>
<li><a href="https://github.com/warrensbox/terraform-switcher/releases/download/0.7.817/terraform-switcher_0.7.817_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 @@ -134,6 +134,19 @@ <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-versiontf-file">Use version.tf file</h3>
<p>If a .tf file with the terraform constrain is included in the current directory, it should automatically download or switch to that terraform version. For example, the following should automatically switch terraform to version <code class="highlighter-rouge">0.12.24</code>:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>terraform {
required_version = "&gt;= 0.12.9"

required_providers {
aws = "&gt;= 2.52.0"
kubernetes = "&gt;= 1.11.1"
}
}
</code></pre></div></div>
<p><img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/versiontf.gif" alt="drawing" style="width: 490px;" /></p>

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

Expand Down Expand Up @@ -172,7 +185,7 @@ <h3 id="use-tfswitchrc-file">Use .tfswitchrc file</h3>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cdtfswitch(){
builtin cd "$@";
cdir=$PWD;
if [ -f "$cdir/.tfswitchrc" ]; then
if [ -e "$cdir/.tfswitchrc" ]; then
tfswitch
fi
}
Expand Down Expand Up @@ -203,7 +216,7 @@ <h3 id="use-tfswitchrc-file">Use .tfswitchrc file</h3>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cd(){
builtin cd "$@";
cdir=$PWD;
if [ -f "$cdir/.tfswitchrc" ]; then
if [ -e "$cdir/.tfswitchrc" ]; then
tfswitch
fi
}
Expand Down
19 changes: 17 additions & 2 deletions docs/_site/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ The most recently selected versions are presented at the top of the dropdown.
2. For example, `tfswitch -l` or `tfswitch --list-all` to see all versions.
3. Hit **Enter** to select the desired version.

### Use version.tf file
If a .tf file with the terraform constrain is included in the current directory, it should automatically download or switch to that terraform version. For example, the following should automatically switch terraform to version `0.12.24`:
```
terraform {
required_version = ">= 0.12.9"
required_providers {
aws = ">= 2.52.0"
kubernetes = ">= 1.11.1"
}
}
```
<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/versiontf.gif" alt="drawing" style="width: 490px;"/>


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

Expand Down Expand Up @@ -93,7 +108,7 @@ Add the following to the end of your `~/.bashrc` file:
cdtfswitch(){
builtin cd "$@";
cdir=$PWD;
if [ -f "$cdir/.tfswitchrc" ]; then
if [ -e "$cdir/.tfswitchrc" ]; then
tfswitch
fi
}
Expand Down Expand Up @@ -125,7 +140,7 @@ load-tfswitch
cd(){
builtin cd "$@";
cdir=$PWD;
if [ -f "$cdir/.tfswitchrc" ]; then
if [ -e "$cdir/.tfswitchrc" ]; then
tfswitch
fi
}
Expand Down
19 changes: 17 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ The most recently selected versions are presented at the top of the dropdown.
2. For example, `tfswitch -l` or `tfswitch --list-all` to see all versions.
3. Hit **Enter** to select the desired version.

### Use version.tf file
If a .tf file with the terraform constrain is included in the current directory, it should automatically download or switch to that terraform version. For example, the following should automatically switch terraform to version `0.12.24`:
```
terraform {
required_version = ">= 0.12.9"
required_providers {
aws = ">= 2.52.0"
kubernetes = ">= 1.11.1"
}
}
```
<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/versiontf.gif" alt="drawing" style="width: 490px;"/>


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

Expand Down Expand Up @@ -93,7 +108,7 @@ Add the following to the end of your `~/.bashrc` file:
cdtfswitch(){
builtin cd "$@";
cdir=$PWD;
if [ -f "$cdir/.tfswitchrc" ]; then
if [ -e "$cdir/.tfswitchrc" ]; then
tfswitch
fi
}
Expand Down Expand Up @@ -125,7 +140,7 @@ load-tfswitch
cd(){
builtin cd "$@";
cdir=$PWD;
if [ -f "$cdir/.tfswitchrc" ]; then
if [ -e "$cdir/.tfswitchrc" ]; then
tfswitch
fi
}
Expand Down
22 changes: 22 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module github.com/warrensbox/terraform-switcher

go 1.13

require (
github.com/Masterminds/semver v1.5.0
github.com/chzyer/logex v1.1.10 // indirect
github.com/chzyer/readline v0.0.0-20171208011716-f6d7a1f6fbf3 // indirect
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a // indirect
github.com/kiranjthomas/terraform-config-inspect v0.0.0-20191120205521-a1d709eb2824
github.com/lunixbochs/vtclean v0.0.0-20170504063817-d14193dfc626 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/manifoldco/promptui v0.2.2-0.20180308161052-c0c0d3afc6a0
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.3 // indirect
github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30
github.com/pelletier/go-toml v1.4.0 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.4.0
)
Loading

0 comments on commit 69e9d24

Please sign in to comment.