All Projects → warrensbox → Terraform Switcher

warrensbox / Terraform Switcher

Licence: mit
A command line tool to switch between different versions of terraform (install with homebrew and more)

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Terraform Switcher

Tads Boilerplate
Terraform + Ansible + Docker Swarm boilerplate = DevOps on 🔥🔥🔥 | Infrastructure as Code
Stars: ✭ 424 (-24.29%)
Mutual labels:  terraform
K2tf
Kubernetes YAML to Terraform HCL converter
Stars: ✭ 477 (-14.82%)
Mutual labels:  terraform
Bedrock
Automation for Production Kubernetes Clusters with a GitOps Workflow
Stars: ✭ 528 (-5.71%)
Mutual labels:  terraform
Terraform Provider Kubernetes Alpha
A Terraform provider for Kubernetes that uses dynamic resource types and server-side apply. Supports all Kubernetes resources.
Stars: ✭ 438 (-21.79%)
Mutual labels:  terraform
Terragoat
TerraGoat is Bridgecrew's "Vulnerable by Design" Terraform repository. TerraGoat is a learning and training project that demonstrates how common configuration errors can find their way into production cloud environments.
Stars: ✭ 461 (-17.68%)
Mutual labels:  terraform
Aws
A collection of bash shell scripts for automating various tasks with Amazon Web Services using the AWS CLI and jq.
Stars: ✭ 493 (-11.96%)
Mutual labels:  terraform
Terraform Cost Estimation
Anonymized, secure, and free Terraform cost estimation based on Terraform plan (0.12+) or Terraform state (any version)
Stars: ✭ 409 (-26.96%)
Mutual labels:  terraform
Guide
Kubernetes clusters for the hobbyist.
Stars: ✭ 5,150 (+819.64%)
Mutual labels:  terraform
Terraform Lsp
Language Server Protocol for Terraform
Stars: ✭ 469 (-16.25%)
Mutual labels:  terraform
Terraform Provisioner Ansible
Ansible with Terraform 0.13.x
Stars: ✭ 520 (-7.14%)
Mutual labels:  terraform
Vault On Gke
Run @HashiCorp Vault on Google Kubernetes Engine (GKE) with Terraform
Stars: ✭ 453 (-19.11%)
Mutual labels:  terraform
Terraformer
CLI tool to generate terraform files from existing infrastructure (reverse Terraform). Infrastructure to Code
Stars: ✭ 6,316 (+1027.86%)
Mutual labels:  terraform
Awsls
A list command for AWS resources
Stars: ✭ 511 (-8.75%)
Mutual labels:  terraform
Inframap
Read your tfstate or HCL to generate a graph specific for each provider, showing only the resources that are most important/relevant.
Stars: ✭ 430 (-23.21%)
Mutual labels:  terraform
Terragrunt
Terragrunt is a thin wrapper for Terraform that provides extra tools for working with multiple Terraform modules.
Stars: ✭ 5,446 (+872.5%)
Mutual labels:  terraform
Terraforming
Export existing AWS resources to Terraform style (tf, tfstate) / No longer actively maintained
Stars: ✭ 4,232 (+655.71%)
Mutual labels:  terraform
Rattlesnakeos Stack
Build your own privacy and security focused Android OS in the cloud.
Stars: ✭ 490 (-12.5%)
Mutual labels:  terraform
Terratest
Terratest is a Go library that makes it easier to write automated tests for your infrastructure code.
Stars: ✭ 5,797 (+935.18%)
Mutual labels:  terraform
Intro To Terraform
Sample code for the blog post series "A Comprehensive Guide to Terraform."
Stars: ✭ 550 (-1.79%)
Mutual labels:  terraform
Infrastructure As Code Talk
Sample code for the talk "Infrastructure-as-code: running microservices on AWS with Docker, ECS, and Terraform"
Stars: ✭ 520 (-7.14%)
Mutual labels:  terraform

Build Status Go Report Card CircleCI

Terraform Switcher

drawing

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.

Homebrew

Installation for MacOS is the easiest with Homebrew. If you do not have homebrew installed, click here.

brew install warrensbox/tap/tfswitch

General Linux

Installation for other linux operation systems.

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

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

sudo snap install tfswitch

Arch User Repository (AUR) packages for Arch Linux

# compiled from source
yay tfswitch
# precompiled
yay tfswitch-bin

Install from source

Alternatively, you can install the binary from source here

Having trouble installing.

How to use:

Use dropdown menu to select version

drawing
  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

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

drawing
  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 environment variable

You can also set the TF_VERSION environment variable to your desired terraform version. For example:

export TF_VERSION=0.14.4
tfswitch #will automatically switch to terraform version 0.14.4

Install latest version only

  1. Install the latest stable version only.
  2. Run tfswitch -u or tfswitch --latest.
  3. Hit Enter to install.

Install latest implicit version for stable releases

  1. Install the latest implicit stable version.
  2. Ex: tfswitch -s 0.13 or tfswitch --latest-stable 0.13 downloads 0.13.6 (latest) version.
  3. Hit Enter to install.

Install latest implicit version for beta, alpha and release candidates(rc)

  1. Install the latest implicit pre-release version.
  2. Ex: tfswitch -p 0.13 or tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 (latest) version.
  3. Hit Enter to install.

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 the lastest version:

terraform {
  required_version = ">= 0.12.9"

  required_providers {
    aws        = ">= 2.52.0"
    kubernetes = ">= 1.11.1"
  }
}
drawing

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

drawing drawing
  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(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:
bin = "/Users/warrenveerasingam/bin/terraform"
version = "0.11.3"
  1. Run tfswitch and it should automatically install the required terraform version in the specified binary path

Use .tfswitchrc file

drawing
  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 and other tools which use it

Automation

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 "[email protected]";
  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 "[email protected]";
  cdir=$PWD;
  if [ -e "$cdir/.tfswitchrc" ]; then
    tfswitch
  fi
}

Automatically switch with fish shell

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

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

drawing
#!/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

drawing

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

Order of precedence

Order Method
1 .tfswitch.toml
2 .tfswitchrc
3 .terraform-version
4 Environment variable

With 1 being the highest precedence and 4 the lowest
(If you disagree with this order of precedence, please open an issue)

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

Additional Info

See how to upgrade, uninstall, troubleshoot here: More info

Issues

Please open issues here: New Issue

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].