Giter Site home page Giter Site logo

warrensbox / terraform-switcher Goto Github PK

View Code? Open in Web Editor NEW
1.3K 1.3K 131.0 42.84 MB

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

Home Page: https://tfswitch.warrensbox.com

License: MIT License

Go 88.35% Makefile 0.84% Shell 8.80% HCL 0.65% Roff 1.36%
go golang terraform

terraform-switcher's Introduction

Build Status Go Report Card GitHub Release GitHub go.mod Go version

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 and verify 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.

Documentation

Click here for our extended documentation.

NOTE

Going forward we will change the version identifier of tfswitch to align with the common go package versioning.
Please be advised to change any automated implementation you might have that is relying on the tfswitch version string.
Old version string: 0.1.2412
New version string: v1.0.0 Note the v that is preceding all version numbers.

Installation

tfswitch is available as a binary and on various package managers (eg. Homebrew).

Windows

Download and extract the Windows version of tfswitch that is compatible with your system.
We are building binaries for 386, amd64, arm6 and arm7 CPU structure.
See the release page for your download.

Homebrew

For macOS or various Linux distributions, Homebrew offers the simplest installation process. If you do not have homebrew installed, click here.

brew install warrensbox/tap/tfswitch

Linux

Installation for Linux operating systems.

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

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 the source here.

See our installation documentation for more details.

Important

The version identifier of tfswitch has changed to align with the common go package versioning.

Version numbers will now be prefixed with a v - eg. v1.0.3.

Please change any automated implementations relying on the tfswitch version string.

Old version string: 0.1.2412 New version string: v1.0.3

Having trouble installing

Quick Start

Dropdown Menu

Execute tfswitch and select the desired Terraform version via the dropdown menu.

Version on command line

Use tfswitch 1.7.0 to install Terraform version 1.7.0. Replace the version number as required.

More usage guide here

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. Let's make tfswitch better!

See step-by-step instructions on how to contribute here: Contribute

Additional Info

See how to upgrade and uninstall or troubleshoot

Issues

Please open issues here: New Issue

terraform-switcher's People

Contributors

afreyermuth98 avatar ajjl avatar bobdoah avatar chrispruitt avatar crablab avatar d33psky avatar dependabot[bot] avatar erikdw avatar gmcoringa avatar grimm26 avatar hlepesant avatar hugueslepesant avatar jaydoubleu avatar jukie avatar kim0 avatar kpucynski avatar kunzese avatar matrixcrawler avatar micahflattbuilt avatar moutons avatar pertsevroman avatar rblumen-desk avatar ruedigerblock avatar shuliyey avatar sivaramsajeev avatar sukolla avatar timkrueger avatar tusv avatar warrensbox avatar yermulnik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-switcher's Issues

Add support for reading global configuration files

Currently, .tfswitch.toml (and the backwards-compatible .tfswitchrc) is read only from the current working directory. This is useless for most practical applications.

To resolve this, the application should read options from ~/.tfswitch.toml when those options are not present in a .tfswitch.toml file in the current directory.

Add flag to download latest terraform version

It would be great if I could pass --latest to just download the latest terraform version.

I'm using this in a docker container so having a handy flag would be great, right now I've gotta do an external github lookup to terraform to get the latest version number then pass that into tfswitch.

tfswitch list is very intrusive... Shouldn't trigger download of latest

tfswitch triggers download

  • I just wanted to list all the versions currently installed without any downloads
  • The switch verified that there's a new version and automatically downloaded without me asking
$ tfswitch -l
Reading required version from terraform file, constraint: >= 0.12
Matched version: 0.13.5
Downloading https://releases.hashicorp.com/terraform/0.13.5/terraform_0.13.5_darwin_amd64.zip to terraform_0.13.5_darwin_amd64.zip
Downloading ...
^C
terraform_ps1:4: command not found: terraform

Feature Request

  • WIthout knowing the versions can break, I think this could avoid switching to new versions until asked
$ tfswitch -l 
  • Maybe use a fetch
$tfswitch --fetch
  • I know I can change restrictions on my terraform file, but I think that's a bit intrusive to just switch automatically

Supporting latest implicit version

Context:

My team develops Terraform modules, and we want to test against certain major versions of Terraform (e.g., 0.12, 0.13, 0.14).

We've been using tfswitch to help automatically install the right version of Terraform for deployments, etc., but it's been more challenging to use it for things like 0.12.latest, or 0.13.latest.

Request:

If would be handy to be able to support implicit versions, semantic versioning-like.

For example:

# latest supported (implicit)
tfswitch

# download 0.13.0 (explicit)
tfswitch 0.13.0

# download 0.13.5 (explicit)
tfswitch 0.13.5

# download 0.13.5 (implicit; latest)
tfswitch 0.13

Or maybe use a flag instead:

# download 0.13.5 (latest)
tfswitch --latest 0.13

# error! no such version!
tfswitch 0.13

One thing that would have been helpful during the 0.14 pre-releases would have been something to give me the latest pre-release for a version before the final release was out. I could hook this up to Travis-CI or Circle-CI or whatever, and ignore failures, but it would give me a sense about forward compatibility.

# download 0.14-rc1 before 0.14.0 was out
tfswitch --latest-pre 0.14

Take explicit version given to CLI as highest priority

If I run tfswitch in a directory with a versions.tf file in it, tfswitch ignores the argument that I give it and only cares about the info in the versions.tf file.

11:07:00 ❯ cat versions.tf
terraform {
  required_version = ">= 0.12"
}

11:11:13 ❯ tfswitch 0.13.5
Reading configuration from home directory for .tfswitch.toml
Reading required version from terraform file, constraint: >= 0.12
Matched version: 0.14.2
Switched terraform to version "0.14.2"

This seems to only be the case when you have a ~/.tfswitch.toml

why are there files going into my homedir?

from the code, there are comments that say:

* 1- Create /usr/local/terraform directory if does not exist
* 2- Download zip file from url to /usr/local/terraform
* 3- Unzip the file to /usr/local/terraform
* 4- Rename the file from `terraform` to `terraform_version`

but the files are ending up in /root/.terraform.versions because I need to use sudo ./terraform-switcher, because my /usr/local/bin is not writeable by my user - and it should not be writeable by any user...

(I'm asking to find out if there was a good reason, or if a PR is warranted)

tfswitch slow when switching terraform version

I am running WSL 2 on a debian distro and tfswitch seems to be slower than any normal linux OS. No doubt it's something to do with WSL but can you shed some light on what is happening here?

Cheers

Mick.

No new versions of terraform - Stuck at 0.12.8

I'm trying to update to a newer version of Terraform but I'm unable to get an updated list.
I have tried to reinstall, removed and made a cleanup still I can only access 0.12.8 as newes version.
Same result with tfswitch -l

tfswitch
Use the arrow keys to navigate: ↓ ↑ → ← 
? Select Terraform version: 
  ▸ 0.12.8 *recent
    0.12.6 *recent
    0.11.14 *recent
    0.12.16
↓   0.12.15

Versions:

OS: MacOS Catalina 10.15.1 (19B88) 
Homebrew 2.1.16
Homebrew/homebrew-core (git revision 2a800; last commit 2019-11-20)
Homebrew/homebrew-cask (git revision 598ff; last commit 2019-11-20)

Default terraform path

Hello!
thank you for this awesome tool!

I struggled a bit with the default terraform path. I don't want to place it in /usr/local/bin/terraform and I don't want to add -b or --path for each call. My first try was .tfswitch.toml which solved this problem. But I also want to use version.tf. I don't want to use both version.tf and .tfswitch.toml to avoid changing the current version in two places.

Here's my current workaround. I use version.tf and in addition I created the following alias:
alias tfswitch='tfswitch -b ~/bin/tf '

Maybe you can get the terraform path from an environment variable or from a default config as described in issue #71.

Thank you!

Brew Upgrade issue on MacOS 11

Please help to investigate. I got this issue after OS upgrade to Big Sur.

==> Installing tfswitch from warrensbox/tap
==> Downloading https://github.com/warrensbox/terraform-switcher/releases/download/0.9.934/terraform-switcher_0.9.934_darwin_amd64
Already downloaded: /Users/bigchoo/Library/Caches/Homebrew/downloads/baa4aaef23f8e67006190b4c36a304c00cb079027c9f39e0ae83454a7f8c3154--terraform-switcher_0.9.934_darwin_amd64.tar.gz
Error: Your CLT does not support macOS 11.0.
It is either outdated or was modified.
Please update your CLT or delete it if no updates are available.

snap package cannot use "~/.terraform.version" and "/usr/local/bin"

I've installed package from snap and running tfswitch -b $HOME/bin , it gives me

Error while creating /home/user/.terraform.versions/terraform_0.13.5_linux_amd64.zip - open /home/user/.terraform.versions/terraform_0.13.5_linux_amd64.zip: permission denied

Running just tfswitch --latest complains about /usr/local/bin directory . Both places are not available from usual snap packages.

Documentation Adjustment: Support symlinks to .tfswitchrc in `cdtfswitch()`

Hi there, great tool you've made here. I would just like to suggest changing the example switching bash function:

cdtfswitch(){
  builtin cd "$@";
  cdir=$PWD;
  # if [ -f "$cdir/.tfswitchrc" ]; then
  # -e evaluates to true for both files and symlinks
  if [ -e "$cdir/.tfswitchrc" ]; then
    tfswitch
  fi
}
alias cd='cdtfswitch'

Support mirrors eg Artifactory

For those trapped behind a corporate firewall, we often need to mirror in external resources.

One way to do this is to use a tool like Nexus or Artifactory.

It would be good feature to support the ability to point to a mirror, rather than directly to Hashicorp's releases page.

add switch load latest [stable]

  1. great tool!
  2. as the tf and tg switch are continuing their release
    please set a flag such tfswitch --latest the will auto change to latest stable

Permissions Issues on linux

After installing with curl <script localtion> | sudo bash I cannot actually do a tfswitch, I get the error:

2018/11/14 09:42:56 Creating directory for teraform: /home/aleinoff/.terraform.versions/
✔ 0.11.10
Downloading https://releases.hashicorp.com/terraform/0.11.10/terraform_0.11.10_linux_amd64.zip to terraform_0.11.10_linux_amd64.zip
Downloading ...
20940986 bytes downloaded.
lstat /usr/local/bin/terraform: no such file or directory
2018/11/14 09:43:04 Unable to create symlink. You must have SUDO privileges

running sudo tfswitch does work, but results in a terraform that is only available to the root user, which is undesirable.

Os version: ubuntu 18.something

Thanks!

Listing terraform versions makes terraform bin unavailable

Hello,

I have just started to use the switcher (v0.7.737). It is a great tool :-).

But when you list terraform versions with

 tfswitch -l

You entre in an interactive mode where you had to choose a version of Terraform. It is no really the behavior waited from an api documented as a "list." The less convenient aspect is that if you do not choose any version and you enter in another terminal session, terraform command will not be recognized.

I hope it help

Cannot Install on Ubuntu 20.x "permission denied"

I can't install TFSwitch on my Ubuntu Budgie 20.x system because of a permission error

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS"

This is the error:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9159  100  9159    0     0   111k      0 --:--:-- --:--:-- --:--:--  110k
warrensbox/terraform-switcher info checking GitHub for latest tag
warrensbox/terraform-switcher info found version: 0.8.832 for 0.8.832/linux/amd64
install: cannot create regular file '/usr/local/bin/tfswitch': Permission denied

Tried installing using sudo but nothing changes.

Add versions.tf support

For now TF version to switch can be automatically taken from .tfswitchrc or .terraform-version files.
In the meantime versions.tf file became de facto standard for TF version control.
It would be very useful to use already existing required_version from terraform code instead of duplicating this info in separate file(s).

How to add additional tf version to tfswitch

On my MacOs I have tf 13 installed (using brew) and then installed tfswitch (using brew).
Now i'd like to install tf 12 and have it switched with tfswitch but can't find any documentation on how to add tf12 to tfswitch.

The output of the tfswitch command is

$tfswitch
Reading required version from terraform file, constraint: >= 0.12
Matched version: 0.13.2
Switched terraform to version "0.13.2" 

$tfswitch -v      
Version: 0.8.832

Terraform Download Issue

I receive this error - "Unable to remove symlink. You must have SUDO privileges" when attempting to download a version of terraform. I have tried running "sudo tfswitch", and still received the same error.

Add a help page

There should be a help page or a man page for this or something

Error - Binary path does not exist: /usr/local/bin

error is not true - it exists, the only thing is that the user doesn't have write access to it..

dow184@township-sl:~/src/onaci/terraform-cloud$ tfswitch 
Reading required version from terraform file, constraint: >= 0.13
Matched version: 0.14.6
Error - Binary path does not exist: /usr/local/bin
Create binary path: /usr/local/bin for terraform installation
dow184@township-sl:~/src/onaci/terraform-cloud$ ls -la /usr/local/bin
total 113232
drwxr-xr-x  3 root   root       4096 Feb 15 13:58 .
drwxr-xr-x 12 root   root       4096 Feb 15 13:54 ..
-rwxr-xr-x  1 dow184 dow184  6766991 May 26  2020 3mux

Issue setting the right version in .tfswitch.toml file

Hi, this issue pops up a few versions back, 0.9.934 but is still present in the current 0.10.1010.
I have a .tfswitch.toml file with the following configuration:
version = "0.12.29"
Single line, no other chars in the file, simple and clean.

When I move into the directory tfswitch reads the file and switches to terraform version 0.12.30 with the following
message:
Reading configuration from current directory for .tfswitch.toml Reading required version from terraform file, constraint: ~> 0.12 Matched version: 0.12.30 Switched terraform to version "0.12.30"

and a terraform version is effectively 0.12.30:
$ terraform -v
Terraform v0.12.30
+ provider.aws v2.68.0
+ provider.local v2.1.0
+ provider.sops v0.5.2
+ provider.template v2.2.0

Your version of Terraform is out of date! The latest version is 0.14.7. You can update by downloading from https://www.terraform.io/downloads.html

I can swap versions by hand without any trouble:
$ tfswitch 0.12.29
Reading configuration from current directory for .tfswitch.toml
Switched terraform to version "0.12.29"

Running Catalina 10.15.7

Any clue what could be the issue?

Alpine linux compatible version

Installer does not install a correct version for alpine linux.

Alpine linux does not support musl and therefore needs a different compilation target.

Here's a simple docker to build it on alpine:

FROM alpine:3.11 AS build
RUN apk upgrade -U -a && \
          apk upgrade && \
          apk add --update go gcc g++ git ca-certificates curl make && \
          git clone https://github.com/warrensbox/terraform-switcher.git /app
WORKDIR /app
RUN CGO_ENABLED=1 GOOS=linux go build

ARM support?

Interested in running from ARM hardware, but it looks like it's not possible at this time.

Any chance you'll be releasing a version with ARM support?

Support setting environment variable - current version

I would like to be able to set at the prompt using ZSH what version of Terraform is currently 'set'. Rather than capturing the output of terraform --version which is slow and cannot sensibly be done every line. It feels like it would be useful for when we use tfswitch to then set an ENV variable which is set to the current working version of Terraform.

Thoughts?

Ctrl-C Interrupt Breaks `terraform` executable.

MacOS Mojave 10.14.6, tfswitch Version: 0.7.737

ctrl-c signaling while in the tfswitch versions menu will result in no terraform executable being linked to the system wide terraform command.

$ terraform -v 
Terraform v0.12.20
Your version of Terraform is out of date! The latest version
is 0.12.21. You can update by downloading from https://www.terraform.io/downloads.html
$ tfswitch
Use the arrow keys to navigate: ↓ ↑ → ← 
? Select Terraform version: 
  ▸ 0.12.20 *recent
    0.11.14 *recent
    0.11.13 *recent
    0.12.21
↓   0.12.19
2020/02/27 17:48:16 Prompt failed ^C
$ terraform -v
bash: /usr/local/bin/terraform: No such file or directory

tfswitch --help or --version can not run unless you have write access to /usr/local/bin/terraform

If /usr/local/bin/terraform exists (does not have to be in your PATH) and you do not have write access to the directory or file, then you can not run even commands that arguably should be non-destructive - e.g. tfswitch --help.

This is due to the lib.init() method which tries to unlink that path and runs before the command arguments are processed. I think that there should be a way to override or disable this behavior if you don't want it to run.

A work around is to create an executable file named terraform, put it in a different directory that you have write access to, and then add that directory to your PATH.

Error while creating /home/drew/.terraform.versions/terraform_0.13.5_linux_amd64.zip - permission denied

Not sure why it cannot create this file. The permissions seem fine.

 drew@drew-ubuntu  ~  
▶tfswitch 
✔ 0.13.5
Downloading https://releases.hashicorp.com/terraform/0.13.5/terraform_0.13.5_linux_amd64.zip to terraform_0.13.5_linux_amd64.zip
Downloading ...
Error while creating /home/drew/.terraform.versions/terraform_0.13.5_linux_amd64.zip - open /home/drew/.terraform.versions/terraform_0.13.5_linux_amd64.zip: permission denied
open /home/drew/.terraform.versions/terraform_0.13.5_linux_amd64.zip: permission denied
 drew@drew-ubuntu  ~  
▶ls -lha | grep terr
drwxrwxr-x  2 drew drew 4.0K Nov  1 11:04 .terraform.versions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.