Giter Club home page Giter Club logo

tgswitch's Introduction

Build Status Go Report Card CircleCI

Terragrunt Switcher

drawing

The tgswitch command line tool lets you switch between different versions of terragrunt. If you do not have a particular version of terragrunt installed, tgswitch 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 terragrunt.

Installation

tgswitch 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/tgswitch

Linux

Installation for Linux operation systems.

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

Install from source

Alternatively, you can install the binary from the source here.

Having trouble installing.

How to use:

Use dropdown menu to select version

drawing

  1. You can switch between different versions of terragrunt by typing the command tgswitch on your terminal.
  2. Select the version of terragrunt 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, tgswitch 0.37.1 for version 0.37.1 of terragrunt.
  3. Hit Enter to switch.

Use environment variables

drawing

  1. You can also set the TG_VERSION environment variable to your desired terragrunt version. For example:
export TG_VERSION=0.37.0
tgswitch #will automatically switch to terragrunt version 0.37.0

Use .tgswitch.toml file (For non-admin AND Apple M1 users with limited privilege on their computers)

Specify a custom binary path for your terragrunt installation

drawing

drawing

  1. Create a custom binary path. Ex: mkdir /Users/uveerum/bin (replace uveerum with your username)
  2. Add the path to your PATH. Ex: export PATH=$PATH:/Users/uveerum/bin (add this to your bash profile or zsh profile)
  3. Pass -b or --bin parameter with your custom path to install terragrunt. Ex: tgswitch -b /Users/uveerum/bin/terragrunt 0.34.0
  4. Optionally, you can create a .tgswitch.toml file in your terragrunt directory(current directory) OR in your home directory(~/.tgswitch.toml). The toml file in the current directory has a higher precedence than toml file in the home directory
  5. Your .tgswitch.toml file should look like this:
bin = "/usr/local/bin/terragrunt"
version = "0.34.0"
  1. Run tgswitch and it should automatically install the required terragrunt version in the specified binary path

NOTE

  1. For linux users that do not have write permission to /usr/local/bin/, tgswitch will attempt to install terragrunt at $HOME/bin. Run export PATH=$PATH:$HOME/bin to append bin to PATH
  2. For windows host, tgswitch need to be run under Administrator mode, and $HOME/.tgswitch.toml with bin must be defined (with a valid path) as minimum, below is an example for $HOME/.tgswitch.toml on windows
bin = "C:\\Users\\<%USRNAME%>\\bin\\terragrunt.exe"

Use .tgswitchrc file

drawing

  1. Create a .tgswitchrc file containing the desired version
  2. For example, echo "0.33.0" >> .tgswitchrc for version 0.33.0 of terragrunt
  3. Run the command tgswitch in the same directory as your .tgswitchrc

Instead of a .tgswitchrc file, a .terragrunt-version file may be used as well

Use terragrunt.hcl file

drawing

If a terragrunt.hcl file with the terragrunt constrain is included in the current directory, it should automatically download or switch to that terragrunt version. For example, the following should automatically switch terragrunt to version 0.36.0:

terragrunt_version_constraint = ">= 0.36, < 0.36.1"
...

Get the version from a subdirectory

tgswitch --chdir terragrunt_dir
tgswitch -c terragrunt_dir

Automatically switch with bash

Add the following to the end of your ~/.bashrc file: (Use either .tgswitchrc or .tgswitch.toml or .terragrunt-version)

cdtgswitch(){
  builtin cd "$@";
  cdir=$PWD;
  if [ -e "$cdir/.tgswitchrc" ]; then
    tgswitch
  fi
}
alias cd='cdtgswitch'

Automatically switch with zsh

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

load-tgswitch() {
  local tgswitchrc_path=".tgswitchrc"

  if [ -f "$tgswitchrc_path" ]; then
    tgswitch
  fi
}
add-zsh-hook chpwd load-tgswitch
load-tgswitch

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/.tgswitchrc" ]; then
    tgswitch
  fi
}

Issues

Please open issues here: New Issue

Upcoming Features

N/A

tgswitch's People

Contributors

andreasprang avatar bmbferreira avatar crablab avatar ddaskal avatar dependabot[bot] avatar jtdoepke avatar lumasepa avatar stashedup avatar steven-edgar avatar tommydroptables avatar warrensbox 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

tgswitch's Issues

inconsistently tgswitch command returned "Unable to get release from repo"

~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch --version

Version: 0.4.326
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$

~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ mkdir ~/tg-test

~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
Switched terragrunt to version "0.28.7" 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
Switched terragrunt to version "0.28.7" 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
Switched terragrunt to version "0.28.7" 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:22:45 Unable to get release from repo 
2021/09/09 21:22:45 Unable to make request Please try again.
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:22:48 Unable to make request Please try again.
2021/09/09 21:22:48 Unable to make request Please try again.
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:22:50 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:22:53 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:22:55 Unable to get release from repo 
2021/09/09 21:22:55 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:22:58 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:23:02 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:23:03 Unable to get release from repo 
2021/09/09 21:23:03 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:23:05 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:23:07 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:23:09 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:23:11 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:23:13 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:23:16 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:23:19 Unable to get release from repo 
2021/09/09 21:23:19 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:23:21 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:23:24 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:23:26 Unable to get release from repo 
2021/09/09 21:23:26 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:23:29 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:23:31 Unable to get release from repo 
2021/09/09 21:23:31 Unable to get release from repo 
2021/09/09 21:23:31 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ tgswitch -b ~/tg-test/terragrunt 0.28.7
2021/09/09 21:23:43 Unable to get release from repo 
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$ ll ~/tg-test/
total 0
drwxr-xr-x+ 84 xxxxxxxx  staff  2688 Sep  9 21:21 ..
lrwxr-xr-x   1 xxxxxxxx  staff    55 Sep  9 21:22 terragrunt -> /Users/xxxxxx/.terragrunt.versions/terragrunt_0.28.7
drwxr-xr-x   3 xxxxxxxx  staff    96 Sep  9 21:22 .
~/github/azure/az-AKS/modules/deploy_Kubernetes_pod$

Do not always call lib.GetAppList

Always calling lib.GetAppList is unnecessary. We should first check if we already have that version downloaded. If so, use it. If not, then go through the routine of downloading the list and all that.

The way it is now generates a lot of unnecessary API calls to github and slows things down a lot.

Tgswitch sometimes fails with a 404 from GitHub

Splitting this out as it should have been a separate issue.

Originally posted by @maxfriedrich in #117 (comment)


Hi, I have a simple setup that results in a 404 page from GitHub pages being downloaded and stored in ~/.terragrunt.versions:

terragrunt.hcl:

terragrunt_version_constraint = "0.35.20"
$ rm -r ~/.terragrunt.versions && tgswitch
Terragrunt file found: /Users/max.friedrich/tgswitch-test/terragrunt.hcl
Reading required version from constraint: 0.35.20
Matched version: 0.35.20
2022/07/07 14:56:54 Creating directory for terragrunt: /Users/max.friedrich/.terragrunt.versions/
Downloading https://warrensbox.github.io/terragunt-versions-list/index.json/v0.35.20/terragrunt_darwin_amd64 to terragrunt_darwin_amd64
Downloading ...
9339 bytes downloaded.
Switched terragrunt to version "0.35.20"

$ head ~/.terragrunt.versions/terragrunt_0.35.20
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; img-src data:; connect-src 'self'">
    <title>Page not found &middot; GitHub Pages</title>
    <style type="text/css" media="screen">
      body {
        background-color: #f1f1f1;
        margin: 0;

If the specified version was already downloaded before with tgswitch "0.35.20" everything works as expected.


Opening a new issue as we similar issue with this, periodically, in our pipelines.

Getting a SIGSEGV when running tgswitch

Hi, I just installed tgswitch via the curl instruction on Linux Mint 19.1 Cinnamon. The version installed is 0.4.315. When I run tgswitch, I get the following error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x6fae71]

goroutine 1 [running]:
github.com/warrensbox/tgswitch/lib.GetAppList(0x7cb598, 0x3e, 0xc0000d7f00, 0x0, 0x817740, 0xc00008f470, 0x1a, 0x1, 0xc00008b020)
/go/src/github.com/warrensbox/tgswitch/lib/list_versions.go:54 +0x321
main.main()
/go/src/github.com/warrensbox/tgswitch/main.go:115 +0x3e2

Anyone else seeing this? My version of Go is:

go version go1.13.5 linux/amd64

if that matters. I also downgraded to 0.3.308 and see the same issue

Any ideas what might be wrong with my setup? Thanks!

Support terragrunt.hcl file like tfswitch

Hi. First of all, thanks for both tgswitch and tfswitch. Absolute life savers.

Would be awesome if you could support using the terragrunt.hcl file like tfswitch does.

install.sh script is broken

When install tgswitch via install script getting error

ssv:~# curl -L https://raw.githubusercontent.com/warrensbox/tgswitch/master/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9186  100  9186    0     0   379k      0 --:--:-- --:--:-- --:--:--  390k
warrensbox/tgswitch info checking GitHub for latest tag
warrensbox/tgswitch info found version: 0.5.375 for 0.5.375/linux/amd64
install: can't stat '/tmp/tmp.FgBfBi/tgswitch': No such file or directory

It seems happen because inside archive file was renamed from tgswitch to terragrunt-switch

`brew install warrensbox/tap/tgswitch` fails

I get the following errors trying to install via brew. It seems like maybe a recent brew version dropped support for these deprecated commands.

$ brew install warrensbox/tap/tgswitch
==> Tapping warrensbox/tap
Cloning into '/opt/homebrew/Library/Taps/warrensbox/homebrew-tap'...
remote: Enumerating objects: 549, done.
remote: Counting objects: 100% (107/107), done.
remote: Compressing objects: 100% (106/106), done.
remote: Total 549 (delta 49), reused 5 (delta 1), pack-reused 442
Receiving objects: 100% (549/549), 69.88 KiB | 1.16 MiB/s, done.
Resolving deltas: 100% (251/251), done.
Error: Invalid formula: /opt/homebrew/Library/Taps/warrensbox/homebrew-tap/Formula/jscheck.rb
jscheck: Calling bottle :unneeded is disabled! There is no replacement.
Please report this issue to the warrensbox/tap tap (not Homebrew/brew or Homebrew/core):
  /opt/homebrew/Library/Taps/warrensbox/homebrew-tap/Formula/jscheck.rb:6

Error: Invalid formula: /opt/homebrew/Library/Taps/warrensbox/homebrew-tap/Formula/hubapp.rb
hubapp: Calling bottle :unneeded is disabled! There is no replacement.
Please report this issue to the warrensbox/tap tap (not Homebrew/brew or Homebrew/core):
  /opt/homebrew/Library/Taps/warrensbox/homebrew-tap/Formula/hubapp.rb:9

Error: Invalid formula: /opt/homebrew/Library/Taps/warrensbox/homebrew-tap/Formula/health-check.rb
health-check: Calling bottle :unneeded is disabled! There is no replacement.
Please report this issue to the warrensbox/tap tap (not Homebrew/brew or Homebrew/core):
  /opt/homebrew/Library/Taps/warrensbox/homebrew-tap/Formula/health-check.rb:9

Error: Cannot tap warrensbox/tap: invalid syntax in tap!

This is on a M1 Max Macbook Pro with the following brew version:

$ brew -v
Homebrew 3.4.0
Homebrew/homebrew-core (git revision 33264a81e51; last commit 2022-03-03)
Homebrew/homebrew-cask (git revision e62bce2db1; last commit 2022-03-04)

Permissions issues on linux

Same issue as warrensbox/terraform-switcher#33

$ tgswitch     
✔ 0.18.7
lstat /usr/local/bin/terragrunt: no such file or directory
symlink /home/user/.terragrunt.versions/terragrunt_0.18.7 /usr/local/bin/terragrunt: permission denied
2019/07/04 09:32:37 Unable to create symlink. You must have SUDO privileges symlink /home/user/.terragrunt.versions/terragrunt_0.18.7 /usr/local/bin/terragrunt: permission denied 

we need the same solution to use a configuration file to specify the destination bin link.

Thanks!

Does not run in Alpine Linux container

I am attempting to use tgswitch in an Alpine based image (Atlantis) and getting not found. I was able to replicate with a base apline container:

FROM alpine
ARG TERRAGRUNT_VERSION="0.26.7"
RUN apk add curl bash
RUN curl -L https://raw.githubusercontent.com/warrensbox/tgswitch/release/install.sh | bash && \
    tgswitch ${TERRAGRUNT_VERSION}

This returns the following:

Step 4/4 : RUN curl -L https://raw.githubusercontent.com/warrensbox/tgswitch/release/install.sh | bash &&     tgswitch ${TERRAGRUNT_VERSION}
 ---> Running in 33603e3002f1
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9129  100  9129    0     0  11105      0 --:--:-- --:--:-- --:--:-- 11092
warrensbox/tgswitch info checking GitHub for latest tag
warrensbox/tgswitch info found version: 0.4.326 for 0.4.326/linux/amd64
warrensbox/tgswitch info installed /usr/local/bin/tgswitch
/bin/sh: tgswitch: not found
The command '/bin/sh -c curl -L https://raw.githubusercontent.com/warrensbox/tgswitch/release/install.sh | bash &&     tgswitch ${TERRAGRUNT_VERSION}' returned a non-zero code: 127

I was able to run the same commands in a Ubuntu container and there are no issues.

同学,您这个项目引入了36个开源组件,存在1个漏洞,辛苦升级一下

检测到 warrensbox/tgswitch 一共引入了36个开源组件,存在1个漏洞

漏洞标题:go-yaml < 2.2.8拒绝服务漏洞
缺陷组件:gopkg.in/[email protected]
漏洞编号:CVE-2019-11254
漏洞描述:gopkg.in/yaml.v2是go语言中用于处理yaml格式的包。
在2.2.8之前的版本中,处理恶意的yaml数据时,会导致CPU资源耗尽。
漏洞由Kubernetes开发者在fuzz测试中发现并提交修复补丁。
国家漏洞库信息:https://www.cnvd.org.cn/flaw/show/CNVD-2020-35519
影响范围:(∞, 2.2.8)
最小修复版本:2.2.8
缺陷组件引入路径:github.com/warrensbox/tgswitch@->gopkg.in/[email protected]

另外还有几个漏洞,详细报告:https://mofeisec.com/jr?p=ae634e

.tgswitch doesn't work as intended

I have this in my configuration file:

❯ cat ~/.tgswitch.toml
bin = "/home/sibi/bin/terragrunt"

And if I do this, I get an error:

❯ tgswitch 0.35.14
2022/07/22 12:07:52
                Unable to create new symlink.
                Maybe symlink already exist. Try removing existing symlink manually.
                Try running "unlink" to remove existing symlink.
                If error persist, you may not have the permission to create a symlink at /usr/local/bin/terragrunt.
                Error: symlink /home/sibi/.terragrunt.versions/terragrunt_0.35.14 /usr/local/bin/terragrunt: no such file or directory

It shouldn't try to create a symbolic link under /usr/local/bin/terragrunt since the configuration file specifies a different path. Passing an explicit option works:

tgswitch --bin=/home/sibi/bin/terragrunt 0.35.14

Option to add version via command line

Currently, you can add a version from the drop-down option. A good feature would be to add a version via the command-line. For example, tgshift 0.14.11

Support for concurrent uses of different terragrunt versions

Right now tgswitch changes the symlink to a terragrunt binary on the PATH or via -b.

If I invoke a script which internally uses terragrunt multiple times from different directories concurrent with different .terragrunt-version files I will get (somewhat) non-deterministic behaviour.

If tgswitch provided a single terragrunt command that exec'd the version in the nearest .tgswitchrc or .terragrunt-version up the directory tree, it could support arbitrary numbers of concurrent sessions with varying versions.

Add .tgswitchrc support like on tfswitch

It's just an idea....

On tfswitch, there is a .tfswitchrc file that allows you to put a specific version of Terraform linked to your project.

Why not add the .tgswitchrc file on tgswitch?

Add Macbook M1 Version Check

Terragrunt binaries for darwin/arm64 started being built as of v0.28.12.

Starting this release, we will be publishing binaries for the darwin/arm64 (compatible with Mac M1 chips) and linux/arm64 platforms.

Executing tgswitch on any version before v0.28.12 should result in an incompatibility error, rather than downloading GitHub's generic 404 page source code and failing to execute.

Example to recreate on Macbook M1:

➜  tgswitch 0.28.11
Downloading https://github.com/gruntwork-io/terragrunt/releases/download/v0.28.11/terragrunt_darwin_arm64 to terragrunt_darwin_arm64
Downloading ...
249562 bytes downloaded.
Switched terragrunt to version "0.28.11"
➜ terragrunt -v
/usr/local/bin/terragrunt: line 7: syntax error near unexpected token `newline'
/usr/local/bin/terragrunt: line 7: `<!DOCTYPE html>'
➜ tgswitch 0.28.12
Downloading https://github.com/gruntwork-io/terragrunt/releases/download/v0.28.12/terragrunt_darwin_arm64 to terragrunt_darwin_arm64
Downloading ...
31663106 bytes downloaded.
Switched terragrunt to version "0.28.12"
➜ terragrunt -v
terragrunt version v0.28.12

Unable to download new version through the proxy

Hello,

I noticed that the behavior of tgswitch is different depending if the version selection is interactive or not.

Example:

root@14c36018b7f9:/data# ls
terragrunt.hcl
root@14c36018b7f9:/data# tgswitch
Terragrunt file found: /data/terragrunt.hcl
Reading required version from constraint: ~> 0.38
Matched version: 0.39.0
Downloading https://warrensbox.github.io/terragunt-versions-list/index.json/v0.39.0/terragrunt_linux_amd64 to terragrunt_linux_amd64
Downloading ...
9339 bytes downloaded.
Switched terragrunt to version "0.39.0" 

root@14c36018b7f9:/data# terragrunt version
/usr/local/bin/terragrunt: line 1: syntax error near unexpected token `newline'
/usr/local/bin/terragrunt: line 1: `<!DOCTYPE html>'

but if using interactive mode:

root@50d1fa5608b5:/data# ls -l
total 0
root@50d1fa5608b5:/data# tgswitch
✔ 0.39.0
Downloading https://github.com/gruntwork-io/terragrunt/releases/download/v0.39.0/terragrunt_linux_amd64 to terragrunt_linux_amd64
Downloading ...
35393268 bytes downloaded.
Switched terragrunt to version "0.39.0" 

root@50d1fa5608b5:/data# terragrunt --version
terragrunt version v0.39.0

The mirror URL specified here does not seem to be able to handle the latest releases automatically.

This is causing issues as a new release of terragrunt means all our CI pipelines are now failing.

Note: Ideally tgswitch would return an error if the download URL is not a 200, so we can see there's a download issue before executing terragrunt

Unable to create new symlink

 tgswitch -v

Version: 0.4.326
cat .tgswitchrc
0.23.8
cd infrastructure-live/
Reading required terragrunt version .tgswitchrc
2020/06/16 11:21:18
		Unable to create new symlink.
		Maybe symlink already exist. Try removing existing symlink manually.
		Try running "unlink" to remove existing symlink.
		If error persist, you may not have the permission to create a symlink at /Users/jim/bin.
		Error: symlink /Users/jim/.terragrunt.versions/terragrunt_0.23.8 /Users/jim/bin: file exists


ls -la /Users/jim/bin/
total 0
drwxr-xr-x   3 jim  staff    96 16 Jun 11:21 .
drwxr-xr-x+ 65 jim  staff  2080 16 Jun 11:13 ..
lrwxr-xr-x   1 jim  staff    50 16 Jun 09:40 terraform -> /Users/jim/.terraform.versions/terraform_0.12.24

ls -ls /Users/jim/.terragrunt.versions/
total 63496
63496 -rwxr-xr-x  1 jim  staff  32270640 16 Jun 11:23 terragrunt_0.23.8

Workaround for me is to add -b $HOME/bin/terragrunt notice I added terragrunt so the documentation might be outdated ?

cdtgswitch(){
  builtin cd "$@";
  cdir=$PWD;
  if [ -f "$cdir/.tgswitchrc" ]; then
    tgswitch -b $HOME/bin/terragrunt
  fi
}
alias cd='cdtgswitch'

Showing it working when adding above workaround:

cd infrastructure-live/
Reading required terragrunt version .tgswitchrc
Switched terragrunt to version "0.23.8"
$ which terragrunt && terragrunt --version
/Users/jim/bin/terragrunt
terragrunt version v0.23.8

Ctrl-C Interrupt Breaks `terragrunt` executable

➜  .terraform.versions tgswitch
Use the arrow keys to navigate: ↓ ↑ → ←
? Select terragrunt version:
  ▸ 0.23.11
    0.21.7
    0.13.20
    0.23.16
↓   0.23.15
2020/05/11 13:23:30 Prompt failed ^C
➜  .terraform.versions terragrunt -v
zsh: command not found: terragrunt

Automatic download with tgswitch 0.6.0 not working

Hello !
On my fedora, tgswitch automatic download feature is not working:

$ tgswitch
Terragrunt file found: /home/cpatry/GIT/si-paiement/terraform/terragrunt.hcl
Reading required version from constraint: >= 0.36, < 0.36.1
Matched version: 0.36.0
Installing terragrunt at /home/cpatry/bin
Downloading https://warrensbox.github.io/terragunt-versions-list/index.json/v0.36.0/terragrunt_linux_amd64 to terragrunt_linux_amd64
Downloading ...
9339 bytes downloaded.
Switched terragrunt to version "0.36.0" 

$ tgswitch 0.36.0
Installing terragrunt at /home/cpatry/bin
Switched terragrunt to version "0.36.0" 

$ rm ~/.terragrunt.versions/terragrunt_0.36.0
$ tgswitch 0.36.0
Installing terragrunt at /home/cpatry/bin
Downloading https://github.com/gruntwork-io/terragrunt/releases/download/v0.36.0/terragrunt_linux_amd64 to terragrunt_linux_amd64
Downloading ...
36462548 bytes downloaded.
Switched terragrunt to version "0.36.0"

The first time, tgswitch download the file from the wrong repo? And I obtained only a 404 HTML file.

If I just ask for a specific version, the binary is downloaded correctly (look at the size in bytes)

Thanks for the tool.

Adding an environment variable similar to TF_VERSION

Hey Warren, great tools! I use them a lot

I noticed that tfswitch can use an env variable TF_VERSION to automatically switch to that version. Can you add the same for tgswitch? Something like TG_VERSION?

I use direnv (https://direnv.net/) a lot and it's handy to include a .envrc file in a directory to switch things around, and I could include TF_VERSION and TG_VERSION variables in it to use unique tools per environment.

Inferring version from `terragrunt_version_constraint` installs an HTML 404 page as an executable

josh@josh-laptop:~/tmp$ mkdir empty
josh@josh-laptop:~/tmp$ cd empty
josh@josh-laptop:~/tmp/empty$ cat ~/.tgswitch.toml 
bin = "/home/josh/.terragrunt.versions/terragrunt"
josh@josh-laptop:~/tmp/empty$ tgswitch --version

Version: 0.6.0
josh@josh-laptop:~/tmp/empty$ rm ~/.terragrunt.versions/terragrunt_*
josh@josh-laptop:~/tmp/empty$ echo 'terragrunt_version_constraint = "=0.38.12"' > terragrunt.hcl
josh@josh-laptop:~/tmp/empty$ tgswitch 
Reading configuration from home directory for .tgswitch.toml
Terragrunt file found: /home/josh/tmp/empty/terragrunt.hcl
Reading required version from constraint: =0.38.12
Matched version: 0.38.12
Downloading https://warrensbox.github.io/terragunt-versions-list/index.json/v0.38.12/terragrunt_linux_amd64 to terragrunt_linux_amd64
Downloading ...
9379 bytes downloaded.
Switched terragrunt to version "0.38.12" 
josh@josh-laptop:~/tmp/empty$ head `which terragrunt`
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; img-src data:; connect-src 'self'">
    <title>Page not found &middot; GitHub Pages</title>
    <style type="text/css" media="screen">
      body {
        background-color: #f1f1f1;
        margin: 0;
josh@josh-laptop:~/tmp/empty$ terragrunt --version
/home/josh/.terragrunt.versions/terragrunt: line 1: syntax error near unexpected token `newline'
/home/josh/.terragrunt.versions/terragrunt: line 1: `<!DOCTYPE html>'

I probably don't need to explain how hazardous and dangerous this is.

Perhaps there's missing error checking on the HTTP status code? Also, when I tgswitch 0.38.12 explicitly, everything works, so it seems there's a bug specifically in the terragrunt_version_constraint inference path.

Clarification regarding license

I would like to package this for nixpkgs as I have started to use this extensively. But unfortunately this repository doesn't see to have any license which makes tricky to package it in upstream distributions.

Can a license be added to this repository ?

Thanks for creating tgswitch!

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.