Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to use default home directory #115

Merged
merged 52 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
e1413eb
added new configuration for website
warrensbox Aug 17, 2020
75c7afc
update cname
warrensbox Aug 17, 2020
ab901ba
updated name
warrensbox Aug 17, 2020
2bd8265
Edit how to contribute section
warrensbox Aug 17, 2020
a44329b
Merge pull request #91 from warrensbox/feature/new-website-with-docs
warrensbox Aug 17, 2020
6754e48
remove site
warrensbox Aug 17, 2020
3397927
Merge pull request #92 from warrensbox/feature/new-website-with-docs
warrensbox Aug 17, 2020
70a35fd
Fixed docs on how to contribute
warrensbox Aug 17, 2020
4211787
Merge pull request #93 from warrensbox/feature/new-website-with-docs
warrensbox Aug 17, 2020
91922e1
prune images
warrensbox Aug 17, 2020
cdae07e
Merge pull request #94 from warrensbox/feature/new-website-with-docs
warrensbox Aug 17, 2020
459b9f4
fix cached images
warrensbox Aug 17, 2020
59b63e0
expand trouble window
warrensbox Aug 17, 2020
89c5f4b
Merge pull request #95 from warrensbox/feature/new-website-with-docs
warrensbox Aug 17, 2020
a156873
added fragment
warrensbox Aug 17, 2020
4a40976
Merge pull request #97 from warrensbox/feature/new-website-with-docs
warrensbox Aug 17, 2020
5314352
added config
warrensbox Aug 17, 2020
741039c
clearing cache
warrensbox Aug 17, 2020
4eea48a
test yaml
warrensbox Aug 17, 2020
d65d06c
ignore pages
warrensbox Aug 17, 2020
aa5f40d
Merge pull request #98 from warrensbox/feature/new-website-with-docs
warrensbox Aug 17, 2020
73d73ad
added google analytic tracking
warrensbox Aug 17, 2020
3e2e213
remove link to ext site
warrensbox Aug 18, 2020
5bc18b7
Merge pull request #99 from warrensbox/feature/new-website-with-docs
warrensbox Aug 18, 2020
aca0033
Execute tfswitch after cd in fish shell
timkrueger Sep 11, 2020
ed1b4f1
added snapscraft file
warrensbox Sep 17, 2020
7aae449
Merge pull request #104 from warrensbox/feature/add-snapcraft-yml
warrensbox Sep 17, 2020
5868f86
rm additional arm64
warrensbox Sep 18, 2020
0b99697
added readme
warrensbox Sep 18, 2020
8e5d827
added custom bin option
warrensbox Sep 18, 2020
266b3be
fixed repo
warrensbox Sep 18, 2020
f993328
Merge pull request #105 from warrensbox/feature/add-snapcraft-yml
warrensbox Sep 18, 2020
cff6093
added more install option
warrensbox Sep 18, 2020
bba738d
Merge pull request #106 from warrensbox/feature/add-snapcraft-yml
warrensbox Sep 18, 2020
37f3bda
Merge pull request #100 from timkrueger/patch-1
warrensbox Sep 18, 2020
21a0093
option to switch with fish shell
warrensbox Sep 18, 2020
e56fa83
Merge pull request #107 from warrensbox/feature/add-snapcraft-yml
warrensbox Sep 18, 2020
2e45f28
Merge branch 'release'
warrensbox Nov 7, 2020
7c423ab
added switch stmt
warrensbox Nov 9, 2020
c623fdd
refactor config file logic
warrensbox Nov 11, 2020
efaf227
update comments
warrensbox Nov 11, 2020
ea1bb97
added home path option for toml file
warrensbox Nov 11, 2020
4ea84ff
added test cases
warrensbox Nov 12, 2020
5889268
added test data
warrensbox Nov 12, 2020
212f4c7
added more test data
warrensbox Nov 12, 2020
ee4b830
added readme update
warrensbox Nov 12, 2020
be1da1f
updated main file
warrensbox Nov 13, 2020
fda3ccc
Merge pull request #113 from warrensbox/develop
warrensbox Nov 13, 2020
1c82751
fixed read me
warrensbox Nov 13, 2020
4f29d79
update readme
warrensbox Nov 13, 2020
a907283
Merge branch 'master' of github.com:warrensbox/terraform-switcher
warrensbox Nov 13, 2020
543547d
Merge pull request #114 from warrensbox/develop
warrensbox Nov 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ jobs:
- checkout
- run:
command: |
set +e
set +e
echo "Building website"
sudo apt-get install python3
sudo apt-get install python3-pip
pip3 install mkdocs-material
cd www
mkdocs gh-deploy --force
cd ..

echo "Building application"
go get -v -t -d ./...
go vet -tests=false ./...
go test -v ./...
Expand Down Expand Up @@ -51,7 +60,11 @@ workflows:

build_and_test:
jobs:
- build
- build:
filters:
branches:
ignore:
- gh-pages
- release:
requires:
- build
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ docs/.bundle/**

.sass-cache

.tfswitchrc

tfswitch*

build-script.sh

.tfswitch.toml
131 changes: 108 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ If you do not have a particular version of terraform installed, `tfswitch` will
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/)

## Installation

`tfswitch` is available for MacOS and Linux based operating systems.
Expand All @@ -28,21 +26,29 @@ Installation for MacOS is the easiest with Homebrew. [If you do not have homebre
brew install warrensbox/tap/tfswitch
```

### Linux
### General Linux

Installation for other linux operation systems.

```sh
curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | bash
```

### Snapcraft for CentOS, Ubuntu, Linux Mint, RHEL, Debian, Fedora

```sh
sudo snap install tfswitch
```

### Install from source

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

[Having trouble installing](https://tfswitch.warrensbox.com/Troubleshoot/).

## 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;"/>
<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/tfswitch.gif#1" alt="drawing" style="width: 370px;"/>

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.
Expand All @@ -51,22 +57,22 @@ Alternatively, you can install the binary from source [here](https://github.com/
The most recently selected versions are presented at the top of the dropdown.

### Supply version on command line
<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/tfswitch-v4.gif" alt="drawing" style="width: 170px;"/>
<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/tfswitch-v4.gif#1" alt="drawing" style="width: 370px;"/>

1. You can also supply the desired version as an argument on the command line.
2. For example, `tfswitch 0.10.5` for version 0.10.5 of terraform.
3. Hit **Enter** to switch.

### See all versions including beta, alpha and release candidates(rc)
<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/tfswitch-v5.gif" alt="drawing" style="width: 170px;"/>
<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/tfswitch-v5.gif#1" alt="drawing" style="width: 370px;"/>

1. Display all versions including beta, alpha and release candidates(rc).
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`:
```
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 the lastest version:
```ruby
terraform {
required_version = ">= 0.12.9"

Expand All @@ -76,28 +82,29 @@ terraform {
}
}
```
<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/versiontf.gif" alt="drawing" style="width: 170px;"/>
<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/versiontf.gif#1" alt="drawing" style="width: 370px;"/>


### 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-v8.gif" alt="drawing" style="width: 170px;"/>
<img src="https://s3.us-east-2.amazonaws.com/kepler-images/warrensbox/tfswitch/tfswitch-v7.gif#1" alt="drawing" style="width: 370px;"/>

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

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.
4. Optionally, you can create a `.tfswitch.toml` file in your terraform directory(current directory) OR in your home directory(~/.tfswitch.toml). The toml file in the current directory has a higher precedence than toml file in the home directory
5. Your `.tfswitch.toml` file should look like this:
```
```ruby
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

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

1. Create a `.tfswitchrc` file containing the desired version
2. For example, `echo "0.10.5" >> .tfswitchrc` for version 0.10.5 of terraform
Expand All @@ -110,7 +117,7 @@ version = "0.11.3"
Add the following to the end of your `~/.bashrc` file:
(Use either `.tfswitchrc` or `.tfswitch.toml` or `.terraform-version`)

```
```sh
cdtfswitch(){
builtin cd "$@";
cdir=$PWD;
Expand All @@ -125,7 +132,7 @@ alias cd='cdtfswitch'

Add the following to the end of your `~/.zshrc` file:

```
```sh
load-tfswitch() {
local tfswitchrc_path=".tfswitchrc"

Expand All @@ -142,7 +149,7 @@ load-tfswitch
> ```

*older version of zsh*
```
```sh
cd(){
builtin cd "$@";
cdir=$PWD;
Expand All @@ -152,23 +159,101 @@ cd(){
}
```

**Automatically switch with fish shell**

Add the following to the end of your `~/.config/fish/config.fish` file:

```sh
function switch_terraform --on-event fish_postexec
string match --regex '^cd\s' "$argv" > /dev/null
set --local is_command_cd $status

if test $is_command_cd -eq 0
if count *.tf > /dev/null

grep -c "required_version" *.tf > /dev/null
set --local tf_contains_version $status

if test $tf_contains_version -eq 0
command tfswitch
end
end
end
end
```

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

```
```sh
#!/bin/bash

echo "Installing tfswitch locally"
wget https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh
chmod 755 install.sh
./install.sh -b bin-directory
wget https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh #Get the installer on to your machine

chmod 755 install.sh #Make installer executable

./install.sh -b `pwd`/.bin #Install tfswitch in a location you have permission

CUSTOMBIN=`pwd`/.bin #set custom bin path

export PATH=$PATH:$CUSTOMBIN #Add custom bin path to PATH environment

$CUSTOMBIN/tfswitch -b $CUSTOMBIN/terraform 0.11.7 #or simply tfswitch -b $CUSTOMBIN/terraform 0.11.7

./bin-directory/tfswitch
terraform -v #testing version
```

### Circle CI setup

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


Example config yaml
```yaml
version: 2
jobs:
build:
docker:
- image: ubuntu

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

steps:
- checkout
- run:
command: |
set +e
apt-get update
apt-get install -y wget
rm -rf /var/lib/apt/lists/*

echo "Installing tfswitch locally"

wget https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh #Get the installer on to your machine

chmod 755 install.sh #Make installer executable

./install.sh -b `pwd`/.bin #Install tfswitch in a location you have permission

CUSTOMBIN=`pwd`/.bin #set custom bin path

export PATH=$PATH:$CUSTOMBIN #Add custom bin path to PATH environment

$CUSTOMBIN/tfswitch -b $CUSTOMBIN/terraform 0.11.7 #or simply tfswitch -b $CUSTOMBIN/terraform 0.11.7

terraform -v #testing version
```

## How to contribute
An open source project becomes meaningful when people collaborate to improve the code.
Feel free to look at the code, critique and make suggestions. Lets make `tfswitch` better!

See step-by-step instructions on how to contribute here: [Contribute](https://tfswitch.warrensbox.com/How-to-Contribute/)

## Additional Info

See how to *upgrade*, *uninstall*, *troubleshoot* here: [More info](https://warrensbox.github.io/terraform-switcher/additional)
See how to *upgrade*, *uninstall*, *troubleshoot* here: [More info](https://tfswitch.warrensbox.com/Upgrade-or-Uninstall/)


## Issues
Expand Down
10 changes: 0 additions & 10 deletions docs/Gemfile

This file was deleted.

Loading