The tfswitch command line tool lets you switch between different versions of terraform.
-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.
-
-
-
-
Installation
-
-
tfswitch is available for MacOS and Linux based operating systems.
Alternatively, you can install the binary from the source here
-
-
-
-
How to use:
-
Use dropdown menu to select version
-
-
-
-
You can switch between different versions of terraform by typing the command tfswitch on your terminal.
-
Select the version of terraform you require by using the up and down arrow.
-
Hit Enter to select the desired version.
-
-
-
The most recently selected versions are presented at the top of the dropdown.
-
-
Supply version on command line
-
-
-
-
You can also supply the desired version as an argument on the command line.
-
For example, tfswitch 0.10.5 for version 0.10.5 of terraform.
-
Hit Enter to switch.
-
-
-
See all versions including beta, alpha and release candidates(rc)
-
-
-
-
Display all versions including beta, alpha and release candidates(rc).
-
For example, tfswitch -l or tfswitch --list-all to see all versions.
-
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:
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
-
-
-
-
-
-
Create a custom binary path. Ex: mkdir /Users/warrenveerasingam/bin (replace warrenveerasingam with your username)
-
Add the path to your PATH. Ex: export PATH=$PATH:/Users/warrenveerasingam/bin (add this to your bash profile or zsh profile)
-
Pass -b or –bin parameter with your custom path to install terraform. Ex: tfswitch -b /Users/warrenveerasingam/bin/terraform 0.10.8
-
Optionally, you can create a .tfswitch.toml file in your terraform directory.
-
Your .tfswitch.toml file should look like this:
-
bin = "/Users/warrenveerasingam/bin/terraform"
-version = "0.11.3"
-
-
-
Run tfswitch and it should automatically install the required terraform version in the specified binary path
-
-
-
Use .tfswitchrc file
-
-
-
-
Create a .tfswitchrc file containing the desired version.
-
For example, echo "0.10.5" >> .tfswitchrc for version 0.10.5 of terraform.
-
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 and other tools which use it
-
-
Automatically switch with bash
-
-
Add the following to the end of your ~/.bashrc file:
-(Use either .tfswitchrc or .tfswitch.toml or .terraform-version)
-
-
cdtfswitch(){
- builtin cd "$@";
- cdir=$PWD;
- if [ -e "$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
-
-
-
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 [ -e "$cdir/.tfswitchrc" ]; then
- tfswitch
- fi
-}
-
-
-
-
-
\ No newline at end of file
diff --git a/docs/_site/index.md b/docs/_site/index.md
deleted file mode 100644
index 87cffb16..00000000
--- a/docs/_site/index.md
+++ /dev/null
@@ -1,172 +0,0 @@
-# Terraform Switcher
-
-The `tfswitch` command line tool lets you switch between different versions of [terraform](https://www.terraform.io/){:target="_blank"}.
-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.
-
-
-
-## Installation
-
-`tfswitch` is available for MacOS and Linux based operating systems.
-
-### Homebrew
-
-Installation for MacOS is the easiest with Homebrew. [If you do not have homebrew installed, click here](https://brew.sh/){:target="_blank"}.
-
-
-```ruby
-brew install warrensbox/tap/tfswitch
-```
-
-### Linux
-
-Installation for Linux operation systems.
-
-```sh
-curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | bash
-```
-
-### Install from source
-
-Alternatively, you can install the binary from the source [here](https://github.com/warrensbox/terraform-switcher/releases)
-
-
-
-## How to use:
-### Use dropdown menu to select version
-
-
-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.
-
-The most recently selected versions are presented at the top of the dropdown.
-
-### Supply version on command line
-
-
-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)
-
-
-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`:
-```
-terraform {
- required_version = ">= 0.12.9"
-
- required_providers {
- aws = ">= 2.52.0"
- kubernetes = ">= 1.11.1"
- }
-}
-```
-
-
-
-### 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
-
-
-
-
-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
-
-### 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`.
-
-*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**
-
-Add the following to the end of your `~/.bashrc` file:
-(Use either `.tfswitchrc` or `.tfswitch.toml` or `.terraform-version`)
-
-```
-cdtfswitch(){
- builtin cd "$@";
- cdir=$PWD;
- if [ -e "$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
-```
-> 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 [ -e "$cdir/.tfswitchrc" ]; then
- tfswitch
- fi
-}
-```
-
-### Jenkins setup
-
-
-```
-#!/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
-
-./bin-directory/tfswitch
-```
-
-
-
-## Issues
-
-Please open *issues* here: [New Issue](https://github.com/warrensbox/terraform-switcher/issues){:target="_blank"}
-
-
-
-See how to *upgrade*, *uninstall*, *troubleshoot* here:
-[Additional Info](additional)
diff --git a/docs/additional.md b/docs/additional.md
deleted file mode 100644
index 36174332..00000000
--- a/docs/additional.md
+++ /dev/null
@@ -1,51 +0,0 @@
-
-[Back to main](index)
-
-## Upgrade:
-
-### Homebrew
-
-```ruby
-brew upgrade warrensbox/tap/tfswitch
-```
-### Linux
-
-Rerun:
-
-```sh
-curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | bash
-```
-
-## Uninstall:
-
-### Homebrew
-
-```ruby
-brew uninstall warrensbox/tap/tfswitch
-```
-### Linux
-
-Rerun:
-
-```sh
-rm /usr/local/bin/tfswitch
-```
-
-## Troubleshoot:
-
-Common issues:
-```ruby
-install: can't change permissions of /usr/local/bin: Operation not permitted
-```
-
-```ruby
-"Unable to remove symlink. You must have SUDO privileges"
-```
-
-```ruby
-"Unable to create symlink. You must have SUDO privileges"
-```
-You probably need to have **sudo** privileges to install *tfswitch*.
-
-[Back to top](#upgrade)
-[Back to main](index)
\ No newline at end of file
diff --git a/go.mod b/go.mod
index 0709ef58..99932fc4 100644
--- a/go.mod
+++ b/go.mod
@@ -14,6 +14,7 @@ require (
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/mitchellh/go-homedir v1.1.0
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
diff --git a/go.sum b/go.sum
index 7d6fda6f..b7f5d836 100644
--- a/go.sum
+++ b/go.sum
@@ -98,6 +98,8 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
+github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
+github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4=
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
@@ -214,5 +216,6 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099 h1:XJP7lxbSxWLOMNdBE4B/STaqVy6L73o0knwj2vIlxnw=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0=
diff --git a/main.go b/main.go
index c8a63951..e12f487a 100644
--- a/main.go
+++ b/main.go
@@ -2,7 +2,7 @@ package main
/*
* Version 0.6.0
-* Compatible with Mac OS X ONLY
+* Compatible with Mac OS X AND other LINUX OS ONLY
*/
/*** OPERATION WORKFLOW ***/
@@ -25,11 +25,12 @@ import (
"sort"
"strings"
- "github.com/Masterminds/semver"
-
// original hashicorp upstream have broken dependencies, so using fork as workaround
// TODO: move back to upstream
+ "github.com/Masterminds/semver"
"github.com/kiranjthomas/terraform-config-inspect/tfconfig"
+ "github.com/mitchellh/go-homedir"
+
// "github.com/hashicorp/terraform-config-inspect/tfconfig"
"github.com/manifoldco/promptui"
@@ -47,7 +48,7 @@ const (
tomlFilename = ".tfswitch.toml"
)
-var version = "0.8.0\n"
+var version = "0.9.0\n"
func main() {
@@ -60,188 +61,204 @@ func main() {
getopt.Parse()
args := getopt.Args()
- dir, err := os.Getwd()
+ dir, err := os.Getwd() //get current directory
if err != nil {
log.Printf("Failed to get current directory %v\n", err)
os.Exit(1)
}
- tfvfile := dir + fmt.Sprintf("/%s", tfvFilename) //settings for .terraform-version file in current directory (tfenv compatible)
- rcfile := dir + fmt.Sprintf("/%s", rcFilename) //settings for .tfswitchrc file in current directory (backward compatible purpose)
- configfile := dir + fmt.Sprintf("/%s", tomlFilename) //settings for .tfswitch.toml file in current directory (option to specify bin directory)
+ homedir, errHome := homedir.Dir()
+ if errHome != nil {
+ log.Printf("Failed to get home directory %v\n", errHome)
+ os.Exit(1)
+ }
- if *versionFlag {
+ curr_tfvfile := dir + fmt.Sprintf("/%s", tfvFilename) //settings for .terraform-version file in current directory (tfenv compatible)
+ curr_rcfile := dir + fmt.Sprintf("/%s", rcFilename) //settings for .tfswitchrc file in current directory (backward compatible purpose)
+ curr_tomlconfigfile := dir + fmt.Sprintf("/%s", tomlFilename) //settings for .tfswitch.toml file in current directory (option to specify bin directory)
+ home_tomlconfigfile := homedir + fmt.Sprintf("/%s", tomlFilename) //settings for .tfswitch.toml file in home directory (option to specify bin directory)
+
+ switch {
+ case *versionFlag:
+ //if *versionFlag {
fmt.Printf("\nVersion: %v\n", version)
- } else if *helpFlag {
+ case *helpFlag:
+ //} else if *helpFlag {
usageMessage()
- } else {
- /* This block checks to see if the tfswitch toml file is provided in the current path.
- * If the .tfswitch.toml file exist, it has a higher precedence than the .tfswitchrc file
- * You can specify the custom binary path and the version you desire
- * If you provide a custom binary path with the -b option, this will override the bin value in the toml file
- * If you provide a version on the command line, this will override the version value in the toml file
- */
- if _, err := os.Stat(configfile); err == nil {
- fmt.Printf("Reading configuration from %s\n", tomlFilename)
- tfversion := ""
- binPath := *custBinPath //takes the default bin (defaultBin) if user does not specify bin path
- configfileName := lib.GetFileName(tomlFilename) //get the config file
- viper.SetConfigType("toml")
- viper.SetConfigName(configfileName)
- viper.AddConfigPath(dir)
-
- errs := viper.ReadInConfig() // Find and read the config file
- if errs != nil {
- fmt.Printf("Unable to read %s provided\n", tomlFilename) // Handle errors reading the config file
- fmt.Println(err)
- os.Exit(1) // exit immediately if config file provided but it is unable to read it
- }
-
- bin := viper.Get("bin") // read custom binary location
- if binPath == defaultBin && bin != nil { // if the bin path is the same as the default binary path and if the custom binary is provided in the toml file (use it)
- binPath = os.ExpandEnv(bin.(string))
- }
- version := viper.Get("version") //attempt to get the version if it's provided in the toml
-
- if len(args) == 1 { //if the version is passed in the command line
- requestedVersion := args[0]
- listAll := true //set list all true - all versions including beta and rc will be displayed
- tflist, _ := lib.GetTFList(hashiURL, listAll) //get list of versions
- exist := lib.VersionExist(requestedVersion, tflist) //check if version exist before downloading it
-
- if exist {
- tfversion = requestedVersion // set tfversion = the version needed
- }
- } else if version != nil { // if the required version in the toml file is provided (use it)
- tfversion = version.(string)
- }
-
- if *listAllFlag { //show all terraform version including betas and RCs
- listAll := true //set list all true - all versions including beta and rc will be displayed
- installOption(listAll, &binPath)
- } else if tfversion == "" { // if no version is provided, show a dropdown of available release versions
- listAll := false //set list all false - only official release will be displayed
- installOption(listAll, &binPath)
- } else {
- if lib.ValidVersionFormat(tfversion) { //check if version is correct
- lib.Install(tfversion, binPath)
- } else {
- fmt.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions")
- os.Exit(1)
- }
- }
- } else if module, _ := tfconfig.LoadModule(dir); len(module.RequiredCore) >= 1 && len(args) == 0 { //if there is a version.tf file, and no commmand line arguments
-
- tfversion := ""
- tfconstraint := module.RequiredCore[0] //we skip duplicated definitions and use only first one
- listAll := true //set list all true - all versions including beta and rc will be displayed
- tflist, _ := lib.GetTFList(hashiURL, listAll) //get list of versions
- fmt.Printf("Reading required version from terraform file, constraint: %s\n", tfconstraint)
-
- constrains, err := semver.NewConstraint(tfconstraint) //NewConstraint returns a Constraints instance that a Version instance can be checked against
- if err != nil {
- fmt.Printf("Error parsing constraint: %s\nPlease check constrain syntax on terraform file.\n", err)
- fmt.Println()
- os.Exit(1)
- }
- versions := make([]*semver.Version, len(tflist))
- for i, tfvals := range tflist {
- version, err := semver.NewVersion(tfvals) //NewVersion parses a given version and returns an instance of Version or an error if unable to parse the version.
- if err != nil {
- fmt.Printf("Error parsing version: %s", err)
- os.Exit(1)
- }
-
- versions[i] = version
- }
-
- sort.Sort(sort.Reverse(semver.Collection(versions)))
-
- for _, element := range versions {
+ /* Checks if the .tfswitch.toml file exist in home or current directory
+ * This block checks to see if the tfswitch toml file is provided in the current path.
+ * If the .tfswitch.toml file exist, it has a higher precedence than the .tfswitchrc file
+ * You can specify the custom binary path and the version you desire
+ * If you provide a custom binary path with the -b option, this will override the bin value in the toml file
+ * If you provide a version on the command line, this will override the version value in the toml file
+ */
+ case fileExists(curr_tomlconfigfile) || fileExists(home_tomlconfigfile):
+
+ version := ""
+ binPath := *custBinPath
+ if fileExists(curr_tomlconfigfile) { //read from toml from current directory
+ version, binPath = getParamsTOML(binPath, dir)
+ } else { // else read from toml from home directory
+ version, binPath = getParamsTOML(binPath, homedir)
+ }
- if constrains.Check(element) { // Validate a version against a constraint
- tfversion = element.String()
+ switch {
+ case checkTFModuleFileExist(dir):
+ installTFProvidedModule(dir, &binPath)
+ case len(args) == 1:
+ installVersion(args[0], &binPath)
+ case *listAllFlag:
+ listAll := true //set list all true - all versions including beta and rc will be displayed
+ installOption(listAll, &binPath)
+ case fileExists(curr_rcfile):
+ readingFileMsg(rcFilename)
+ tfversion := retrieveFileContents(curr_rcfile)
+ installVersion(tfversion, &binPath)
+ case fileExists(curr_tfvfile):
+ readingFileMsg(tfvFilename)
+ tfversion := retrieveFileContents(curr_tfvfile)
+ installVersion(tfversion, &binPath)
+ case version != "":
+ installVersion(version, &binPath)
+ default:
+ listAll := false //set list all false - only official release will be displayed
+ installOption(listAll, &binPath)
+ }
- fmt.Printf("Matched version: %s\n", tfversion)
- if lib.ValidVersionFormat(tfversion) { //check if version format is correct
- lib.Install(tfversion, *custBinPath)
- } else {
- fmt.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions")
- os.Exit(1)
- }
- }
- }
+ /* list all versions, //show all terraform version including betas and RCs*/
+ case *listAllFlag:
+ installWithListAll(custBinPath)
+
+ /* version provided on command line as arg */
+ case len(args) == 1:
+ installVersion(args[0], custBinPath)
+
+ /* provide an tfswitchrc file */
+ case fileExists(curr_rcfile) && len(args) == 0:
+ readingFileMsg(rcFilename)
+ tfversion := retrieveFileContents(curr_rcfile)
+ installVersion(tfversion, custBinPath)
+
+ /* if .terraform-version file found */
+ case fileExists(curr_tfvfile) && len(args) == 0:
+ readingFileMsg(tfvFilename)
+ tfversion := retrieveFileContents(curr_tfvfile)
+ installVersion(tfversion, custBinPath)
+
+ /* if versions.tf file found */
+ case checkTFModuleFileExist(dir) && len(args) == 0:
+ installTFProvidedModule(dir, custBinPath)
+
+ // if no arg is provided
+ default:
+ listAll := false //set list all false - only official release will be displayed
+ installOption(listAll, custBinPath)
+ }
+}
- fmt.Println("No version found to match constraint. Follow the README.md instructions for setup. https://github.com/warrensbox/terraform-switcher/blob/master/README.md")
- os.Exit(1)
+/* Helper functions */
- } else if _, err := os.Stat(rcfile); err == nil && len(args) == 0 { //if there is a .tfswitchrc file, and no commmand line arguments
- fmt.Printf("Reading required terraform version %s \n", rcFilename)
+// install with all possible versions, including beta and rc
+func installWithListAll(custBinPath *string) {
+ listAll := true //set list all true - all versions including beta and rc will be displayed
+ installOption(listAll, custBinPath)
+}
- fileContents, err := ioutil.ReadFile(rcfile)
- if err != nil {
- fmt.Printf("Failed to read %s file. Follow the README.md instructions for setup. https://github.com/warrensbox/terraform-switcher/blob/master/README.md\n", rcFilename)
- fmt.Printf("Error: %s\n", err)
- os.Exit(1)
- }
- tfversion := strings.TrimSuffix(string(fileContents), "\n")
+// install with provided version as argument
+func installVersion(arg string, custBinPath *string) {
+ if lib.ValidVersionFormat(arg) {
+ requestedVersion := arg
+ listAll := true //set list all true - all versions including beta and rc will be displayed
+ tflist, _ := lib.GetTFList(hashiURL, listAll) //get list of versions
+ exist := lib.VersionExist(requestedVersion, tflist) //check if version exist before downloading it
- if lib.ValidVersionFormat(tfversion) { //check if version is correct
- lib.Install(string(tfversion), *custBinPath)
- } else {
- fmt.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions")
- os.Exit(1)
- }
- } else if _, err := os.Stat(tfvfile); err == nil && len(args) == 0 { //if there is a .terraform-version file, and no command line arguments
- fmt.Printf("Reading required terraform version %s \n", tfvFilename)
+ if exist {
+ lib.Install(requestedVersion, *custBinPath)
+ } else {
+ fmt.Println("The provided terraform version does not exist. Try `tfswitch -l` to see all available versions.")
+ }
- fileContents, err := ioutil.ReadFile(tfvfile)
- if err != nil {
- fmt.Printf("Failed to read %s file. Follow the README.md instructions for setup. https://github.com/warrensbox/terraform-switcher/blob/master/README.md\n", tfvFilename)
- fmt.Printf("Error: %s\n", err)
- os.Exit(1)
- }
- tfversion := strings.TrimSuffix(string(fileContents), "\n")
+ } else {
+ printInvalidTFVersion()
+ fmt.Println("Args must be a valid terraform version")
+ usageMessage()
+ }
+}
- if lib.ValidVersionFormat(tfversion) { //check if version is correct
- lib.Install(string(tfversion), *custBinPath)
- } else {
- fmt.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions")
- os.Exit(1)
- }
- } else if len(args) == 1 { //if tf version is provided in command line
- if lib.ValidVersionFormat(args[0]) {
+// Print invalid TF version
+func printInvalidTFVersion() {
+ fmt.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions")
+}
- requestedVersion := args[0]
- listAll := true //set list all true - all versions including beta and rc will be displayed
- tflist, _ := lib.GetTFList(hashiURL, listAll) //get list of versions
- exist := lib.VersionExist(requestedVersion, tflist) //check if version exist before downloading it
+//retrive file content of regular file
+func retrieveFileContents(file string) string {
+ fileContents, err := ioutil.ReadFile(file)
+ if err != nil {
+ fmt.Printf("Failed to read %s file. Follow the README.md instructions for setup. https://github.com/warrensbox/terraform-switcher/blob/master/README.md\n", tfvFilename)
+ fmt.Printf("Error: %s\n", err)
+ os.Exit(1)
+ }
+ tfversion := strings.TrimSuffix(string(fileContents), "\n")
+ return tfversion
+}
- if exist {
- lib.Install(requestedVersion, *custBinPath)
- } else {
- fmt.Println("The provided terraform version does not exist. Try `tfswitch -l` to see all available versions.")
- }
+// Print message reading file content of :
+func readingFileMsg(filename string) {
+ fmt.Printf("Reading file %s \n", filename)
+}
- } else {
- fmt.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions")
- fmt.Println("Args must be a valid terraform version")
- usageMessage()
- }
+// fileExists checks if a file exists and is not a directory before we try using it to prevent further errors.
+func fileExists(filename string) bool {
+ info, err := os.Stat(filename)
+ if os.IsNotExist(err) {
+ return false
+ }
+ return !info.IsDir()
+}
- } else if *listAllFlag {
- listAll := true //set list all true - all versions including beta and rc will be displayed
- installOption(listAll, custBinPath)
+// fileExists checks if a file exists and is not a directory before we
+// try using it to prevent further errors.
+func checkTFModuleFileExist(dir string) bool {
- } else if len(args) == 0 { //if there are no commmand line arguments
+ module, _ := tfconfig.LoadModule(dir)
+ if len(module.RequiredCore) >= 1 {
+ return true
+ }
+ return false
+}
- listAll := false //set list all false - only official release will be displayed
- installOption(listAll, custBinPath)
+/* parses everything in the toml file, return required version and bin path */
+func getParamsTOML(binPath string, dir string) (string, string) {
+ path, _ := homedir.Dir()
+ if dir == path {
+ path = "home directory"
+ } else {
+ path = "current directory"
+ }
+ fmt.Printf("Reading configuration from %s\n", path+" for "+tomlFilename) //takes the default bin (defaultBin) if user does not specify bin path
+ configfileName := lib.GetFileName(tomlFilename) //get the config file
+ viper.SetConfigType("toml")
+ viper.SetConfigName(configfileName)
+ viper.AddConfigPath(dir)
+
+ errs := viper.ReadInConfig() // Find and read the config file
+ if errs != nil {
+ fmt.Printf("Unable to read %s provided\n", tomlFilename) // Handle errors reading the config file
+ fmt.Println(errs)
+ os.Exit(1) // exit immediately if config file provided but it is unable to read it
+ }
- } else {
- usageMessage()
- }
+ bin := viper.Get("bin") // read custom binary location
+ if binPath == defaultBin && bin != nil { // if the bin path is the same as the default binary path and if the custom binary is provided in the toml file (use it)
+ binPath = os.ExpandEnv(bin.(string))
}
+ //fmt.Println(binPath) //uncomment this to debug
+ version := viper.Get("version") //attempt to get the version if it's provided in the toml
+ if version == nil {
+ version = ""
+ }
+
+ return version.(string), binPath
}
func usageMessage() {
@@ -277,3 +294,48 @@ func installOption(listAll bool, custBinPath *string) {
lib.Install(tfversion, *custBinPath)
os.Exit(0)
}
+
+// installation when
+func installTFProvidedModule(dir string, custBinPath *string) {
+ tfversion := ""
+ module, _ := tfconfig.LoadModule(dir)
+ tfconstraint := module.RequiredCore[0] //we skip duplicated definitions and use only first one
+ listAll := true //set list all true - all versions including beta and rc will be displayed
+ tflist, _ := lib.GetTFList(hashiURL, listAll) //get list of versions
+ fmt.Printf("Reading required version from terraform file, constraint: %s\n", tfconstraint)
+
+ constrains, err := semver.NewConstraint(tfconstraint) //NewConstraint returns a Constraints instance that a Version instance can be checked against
+ if err != nil {
+ fmt.Printf("Error parsing constraint: %s\nPlease check constrain syntax on terraform file.\n", err)
+ fmt.Println()
+ os.Exit(1)
+ }
+ versions := make([]*semver.Version, len(tflist))
+ for i, tfvals := range tflist {
+ version, err := semver.NewVersion(tfvals) //NewVersion parses a given version and returns an instance of Version or an error if unable to parse the version.
+ if err != nil {
+ fmt.Printf("Error parsing version: %s", err)
+ os.Exit(1)
+ }
+
+ versions[i] = version
+ }
+
+ sort.Sort(sort.Reverse(semver.Collection(versions)))
+
+ for _, element := range versions {
+ if constrains.Check(element) { // Validate a version against a constraint
+ tfversion = element.String()
+ fmt.Printf("Matched version: %s\n", tfversion)
+ if lib.ValidVersionFormat(tfversion) { //check if version format is correct
+ lib.Install(tfversion, *custBinPath)
+ } else {
+ printInvalidTFVersion()
+ os.Exit(1)
+ }
+ }
+ }
+
+ fmt.Println("No version found to match constraint. Follow the README.md instructions for setup. https://github.com/warrensbox/terraform-switcher/blob/master/README.md")
+ os.Exit(1)
+}
diff --git a/snapcraft.yaml b/snapcraft.yaml
new file mode 100644
index 00000000..024ee486
--- /dev/null
+++ b/snapcraft.yaml
@@ -0,0 +1,35 @@
+name: tfswitch
+version: git
+summary: A command line tool to switch between different versions of terraform
+description: |
+ 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.
+architectures:
+ - build-on: arm64
+assumes: [snapd2.45]
+base: core18
+
+grade: stable
+confinement: strict
+
+apps:
+ tfswitch:
+ command: bin/tfswitch
+ plugs:
+ - home
+ - network
+ - network-bind
+
+parts:
+ tfswitch:
+ source: .
+ plugin: go
+ go-importpath: github.com/warrensbox/terraform-switcher
+ build-packages:
+ - gcc-multilib
+ go-buildtags:
+ - tfswitch
+ override-build:
+ go build -o ../install/bin/tfswitch
\ No newline at end of file
diff --git a/test-data/test_terraform-version/.terraform-version b/test-data/test_terraform-version/.terraform-version
new file mode 100644
index 00000000..d9df1bbc
--- /dev/null
+++ b/test-data/test_terraform-version/.terraform-version
@@ -0,0 +1 @@
+0.11.0
diff --git a/test-data/test_tfswitchrc/.tfswitchrc b/test-data/test_tfswitchrc/.tfswitchrc
new file mode 100644
index 00000000..9028ec63
--- /dev/null
+++ b/test-data/test_tfswitchrc/.tfswitchrc
@@ -0,0 +1 @@
+0.10.5
diff --git a/test-data/test_tfswitchtoml/.tfswitch.toml b/test-data/test_tfswitchtoml/.tfswitch.toml
new file mode 100644
index 00000000..63df82e7
--- /dev/null
+++ b/test-data/test_tfswitchtoml/.tfswitch.toml
@@ -0,0 +1,2 @@
+bin = "/Users/uveerum/bin/terraform"
+version = "0.11.3"
diff --git a/test-data/test_versiontf/version.tf b/test-data/test_versiontf/version.tf
new file mode 100644
index 00000000..998dc471
--- /dev/null
+++ b/test-data/test_versiontf/version.tf
@@ -0,0 +1,8 @@
+terraform {
+ required_version = ">= 0.12.9"
+
+ required_providers {
+ aws = ">= 2.52.0"
+ kubernetes = ">= 1.11.1"
+ }
+}
\ No newline at end of file
diff --git a/version b/version
index 524a135d..512833fc 100644
--- a/version
+++ b/version
@@ -1 +1 @@
-RELEASE_VERSION=0.8
\ No newline at end of file
+RELEASE_VERSION=0.9
\ No newline at end of file
diff --git a/www/docs/CNAME b/www/docs/CNAME
new file mode 100644
index 00000000..7f85881a
--- /dev/null
+++ b/www/docs/CNAME
@@ -0,0 +1 @@
+tfswitch.warrensbox.com
\ No newline at end of file
diff --git a/www/docs/Continuous-Integration.md b/www/docs/Continuous-Integration.md
new file mode 100644
index 00000000..62a4939e
--- /dev/null
+++ b/www/docs/Continuous-Integration.md
@@ -0,0 +1,62 @@
+### Jenkins setup
+
+
+```sh
+#!/bin/bash
+
+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
+```
+
+### Circle CI setup
+
+
+
+
+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
+```
\ No newline at end of file
diff --git a/www/docs/How-to-Contribute.md b/www/docs/How-to-Contribute.md
new file mode 100644
index 00000000..9c1cc5a6
--- /dev/null
+++ b/www/docs/How-to-Contribute.md
@@ -0,0 +1,80 @@
+## Step by step instructions
+
+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!
+
+## Required version
+```sh
+go version 1.13
+```
+
+### Step 1 - Create workspace
+*Skip this step if you already have a github go workspace*
+Create a github workspace.
+
+
+### Step 2 - Set GOPATH
+*Skip this step if you already have a github go workspace*
+Export your GOPATH environment variable in your `go` directory.
+```sh
+export GOPATH=`pwd`
+```
+
+
+### Step 3 - Clone repository
+Git clone this repository.
+```sh
+git clone git@github.com:warrensbox/terraform-switcher.git
+```
+
+
+### Step 4 - Get dependencies
+Go get all the dependencies.
+
+```sh
+go mod download
+```
+```sh
+go get -v -t -d ./...
+```
+Test the code (optional).
+```sh
+go vet -tests=false ./...
+```
+```sh
+go test -v ./...
+```
+
+
+### Step 5 - Build executable
+Create a new branch.
+```sh
+git checkout -b feature/put-your-branch-name-here
+```
+Refactor and add new features to the code.
+Go build the code.
+```sh
+go build -o test-tfswitch
+```
+Test the code and create a new pull request!
+
+
+
+### Contributors
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/www/docs/Install.md b/www/docs/Install.md
new file mode 100644
index 00000000..c9f6bb08
--- /dev/null
+++ b/www/docs/Install.md
@@ -0,0 +1,33 @@
+## Installation
+
+`tfswitch` is available for MacOS and Linux based operating systems.
+
+### Homebrew
+
+Installation for MacOS is the easiest with Homebrew. If you do not have homebrew installed, click here.
+
+```ruby
+brew install warrensbox/tap/tfswitch
+```
+
+### Linux
+
+Installation for 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 the source here.
+
+[Having trouble installing](https://tfswitch.warrensbox.com/Troubleshoot/).
+
+
diff --git a/docs/index.md b/www/docs/Quick-Start.md
similarity index 60%
rename from docs/index.md
rename to www/docs/Quick-Start.md
index 87cffb16..3669fd00 100644
--- a/docs/index.md
+++ b/www/docs/Quick-Start.md
@@ -1,65 +1,30 @@
-# Terraform Switcher
-
-The `tfswitch` command line tool lets you switch between different versions of [terraform](https://www.terraform.io/){:target="_blank"}.
-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.
-
-
-
-## Installation
-
-`tfswitch` is available for MacOS and Linux based operating systems.
-
-### Homebrew
-
-Installation for MacOS is the easiest with Homebrew. [If you do not have homebrew installed, click here](https://brew.sh/){:target="_blank"}.
-
-
-```ruby
-brew install warrensbox/tap/tfswitch
-```
-
-### Linux
-
-Installation for Linux operation systems.
-
-```sh
-curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | bash
-```
-
-### Install from source
-
-Alternatively, you can install the binary from the source [here](https://github.com/warrensbox/terraform-switcher/releases)
-
-
## How to use:
### Use dropdown menu to select version
-
+
-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.
The most recently selected versions are presented at the top of the dropdown.
### Supply version on command line
-
+
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)
-
+
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:
```
terraform {
required_version = ">= 0.12.9"
@@ -70,41 +35,40 @@ terraform {
}
}
```
-
-
+
### 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
-
-
+
+
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
-
+
-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`.
+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`
*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**
-Add the following to the end of your `~/.bashrc` file:
+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;
@@ -119,7 +83,7 @@ alias cd='cdtfswitch'
Add the following to the end of your `~/.zshrc` file:
-```
+```sh
load-tfswitch() {
local tfswitchrc_path=".tfswitchrc"
@@ -136,7 +100,7 @@ load-tfswitch
> ```
*older version of zsh*
-```
+```sh
cd(){
builtin cd "$@";
cdir=$PWD;
@@ -145,28 +109,25 @@ cd(){
fi
}
```
+**Automatically switch with fish shell**
-### Jenkins setup
-
+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
```
-#!/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
-
-./bin-directory/tfswitch
-```
-
-
-
-## Issues
-
-Please open *issues* here: [New Issue](https://github.com/warrensbox/terraform-switcher/issues){:target="_blank"}
-
-
-
-See how to *upgrade*, *uninstall*, *troubleshoot* here:
-[Additional Info](additional)
diff --git a/www/docs/Troubleshoot.md b/www/docs/Troubleshoot.md
new file mode 100644
index 00000000..b646068d
--- /dev/null
+++ b/www/docs/Troubleshoot.md
@@ -0,0 +1,48 @@
+
+Problem:
+```sh
+install: can't change permissions of /usr/local/bin: Operation not permitted
+```
+
+```sh
+"Unable to remove symlink. You must have SUDO privileges"
+```
+
+```sh
+"Unable to create symlink. You must have SUDO privileges"
+```
+
+```sh
+install: cannot create regular file '/usr/local/bin/tfswitch': Permission denied
+```
+
+Solution: You probably need to have privileges to install *tfswitch* at /usr/local/bin.
+
+Try the following:
+
+```sh
+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 $HOME/.bin #Install tfswitch in a location you have permission:
+
+$HOME/.bin/tfswitch #test
+
+export PATH=$PATH:$HOME/.bin #Export your .bin into your path
+
+#You should probably add step 4 in your `.bash_profile` in your $HOME directory.
+
+#Next, try:
+`tfswitch -b $HOME/.bin/terraform 0.11.7`
+
+#or simply
+
+`tfswitch -b $HOME/.bin/terraform`
+
+
+```
+
+See the custom directory option `-b`:
+
+
diff --git a/www/docs/Upgrade-or-Uninstall.md b/www/docs/Upgrade-or-Uninstall.md
new file mode 100644
index 00000000..10dc0088
--- /dev/null
+++ b/www/docs/Upgrade-or-Uninstall.md
@@ -0,0 +1,29 @@
+## Upgrade:
+
+### Homebrew
+
+```ruby
+brew upgrade warrensbox/tap/tfswitch
+```
+### Linux
+
+Rerun:
+
+```sh
+curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | bash
+```
+
+## Uninstall:
+
+### Homebrew
+
+```ruby
+brew uninstall warrensbox/tap/tfswitch
+```
+### Linux
+
+Run:
+
+```sh
+rm /usr/local/bin/tfswitch
+```
\ No newline at end of file
diff --git a/www/docs/index.md b/www/docs/index.md
new file mode 100644
index 00000000..646bcb7c
--- /dev/null
+++ b/www/docs/index.md
@@ -0,0 +1,9 @@
+# Introduction to tfswitch
+
+
+
+The `tfswitch` command line tool lets you switch between different versions of terraform.
+If you do not have a particular version of terraform installed, `tfswitch` lets you 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.
+
diff --git a/www/docs/static/favicon_tfswitch_16.png b/www/docs/static/favicon_tfswitch_16.png
new file mode 100644
index 00000000..7951adc4
Binary files /dev/null and b/www/docs/static/favicon_tfswitch_16.png differ
diff --git a/www/docs/static/favicon_tfswitch_48.png b/www/docs/static/favicon_tfswitch_48.png
new file mode 100644
index 00000000..8d5fb3bf
Binary files /dev/null and b/www/docs/static/favicon_tfswitch_48.png differ
diff --git a/www/docs/static/logo.png b/www/docs/static/logo.png
new file mode 100644
index 00000000..835e0748
Binary files /dev/null and b/www/docs/static/logo.png differ
diff --git a/www/mkdocs.yml b/www/mkdocs.yml
new file mode 100644
index 00000000..d611190f
--- /dev/null
+++ b/www/mkdocs.yml
@@ -0,0 +1,27 @@
+site_name: TFSwitch
+site_description: A command line tool to switch between different versions of terraform (install with homebrew and more)
+copyright: This project is maintained by warrensbox
+repo_name: warrensbox/terraform-switcher
+repo_url: https://github.com/warrensbox/terraform-switcher
+site_url: https://tfswitch.warrensbox.com
+
+theme:
+ name: material
+ palette:
+ primary: indigo
+ favicon: static/favicon_tfswitch_16.png
+ logo: static/logo.png
+
+nav:
+ - index.md
+ - Install.md
+ - Quick-Start.md
+ - Continuous-Integration.md
+ - Upgrade-or-Uninstall.md
+ - How-to-Contribute.md
+ - Troubleshoot.md
+
+google_analytics:
+ - UA-120055973-1
+ - auto
+
\ No newline at end of file