Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengroat authored Mar 11, 2020
2 parents f2a66c2 + a9c7e38 commit 5f98e8c
Show file tree
Hide file tree
Showing 26 changed files with 2,079 additions and 614 deletions.
14 changes: 10 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
before_install:
- 'if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install bash; fi' # Bash4 Required
language: generic
matrix:
include:
- os: windows
language: shell
- os: linux
dist: bionic
- os: linux
dist: xenial
- os: linux
dist: trusty
- os: osx
osx_image: xcode8.2 # OS X 10.12
- os: osx
osx_image: xcode8 # OS X 10.11
osx_image: xcode11.2
- os: osx
osx_image: xcode7 # OS X 10.10
osx_image: xcode10.3
#- os: osx
# osx_image: xcode9.4 # brew update is excruciatingly slow on xcode9.4
script:
- ./test/run.sh
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 2.0.0 (Unreleased)

* New logging library
* New bash4 dependency
* Massive testing, logging and loading refactoring
* Fix to 'use' logic: don't overwrite .terraform-version files

## 1.0.2 (October 29, 2019)

* Fix failing 0.11.15-oci version, Add additional tests for 0.11.15-oci and alphas, betas and rcs #145
* Fix to README section link for .terraform-version file #146

## 1.0.1 (June 22, 2019)

* Fix '--version' flag to return version from CHANGELOG.md when not running from a git checkout.
Expand Down
189 changes: 176 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
[![Build Status](https://travis-ci.com/tfutils/tfenv.svg?branch=master)](https://travis-ci.com/tfutils/tfenv)

# tfenv

[Terraform](https://www.terraform.io/) version manager inspired by [rbenv](https://github.com/rbenv/rbenv)

## Support

Currently tfenv supports the following OSes

- Mac OS X (64bit)
- Linux
- 64bit
- Arm
- Windows (64bit) - only tested in git-bash
- 64bit
- Arm
- Windows (64bit) - only tested in git-bash - currently presumed failing due to symlink issues in git-bash

## Installation

### Automatic

Install via Homebrew

```console
Expand All @@ -28,6 +33,7 @@ include ::tfenv
```

### Manual

1. Check out tfenv into any path (here is `${HOME}/.tfenv`)

```console
Expand All @@ -45,21 +51,23 @@ include ::tfenv
```console
$ ln -s ~/.tfenv/bin/* /usr/local/bin
```

On Ubuntu/Debian touching `/usr/local/bin` might require sudo access, but you can create `${HOME}/bin` or `${HOME}/.local/bin` and on next login it will get added to the session `$PATH`
or by running `. ${HOME}/.profile` it will get added to the current shell session's `$PATH`.

```console
$ mkdir -p ~/.local/bin/
$ . ~/.profile
$ ln -s ~/.tfenv/bin/* ~/.local/bin
$ which tfenv
```


## Usage

### tfenv install [version]

Install a specific version of Terraform. Available options for version:

- `i.j.k` exact version to install
- `latest` is a syntax to install latest version
- `latest:<regex>` is a syntax to install latest version matching regex (used by grep -e)
Expand Down Expand Up @@ -91,11 +99,13 @@ see web-of-trust status; beware that a lack of trust path will not cause a
validation failure.

#### .terraform-version
If you use [.terraform-version](#terraform-version), `tfenv install` (no argument) will install the version written in it.

If you use a [.terraform-version file](#terraform-version-file), `tfenv install` (no argument) will install the version written in it.

#### min-required

Please note that we don't do semantic version range parsing but use first ever found version as the candidate for minimally required one. It is up to the user to keep the definition reasonable. I.e.

```terraform
// this will detect 0.12.3
terraform {
Expand All @@ -110,24 +120,167 @@ terraform {
}
```

### Environment Variables

#### TFENV

##### `TFENV_ARCH`

### Specify architecture
String (Default: amd64)

Architecture other than the default amd64 can be specified with the `TFENV_ARCH` environment variable
Specify architecture. Architecture other than the default amd64 can be specified with the `TFENV_ARCH` environment variable

```console
TFENV_ARCH=arm tfenv install 0.7.9
```

### Customize remote
##### `TFENV_CURL_OUTPUT`

Integer (Default: 2)

Set the mechanism used for displaying download progress when downloading terraform versions from the remote server.

* 2: v1 Behaviour: Pass `-#` to curl
* 1: Use curl default
* 0: Pass `-s` to curl

Installing from a remote other than the default https://releases.hashicorp.com can be done by specifying the `TFENV_REMOTE` environment varible
##### `TFENV_DEBUG`

##### `TFENV_REMOTE`

String (Default: https://releases.hashicorp.com)

To install from a remote other than the default

```console
TFENV_REMOTE=https://example.jfrog.io/artifactory/hashicorp
```

#### Bashlog Logging Library

##### `BASHLOG_COLOURS`

Integer (Default: 1)

To disable colouring of console output, set to 0.


##### `BASHLOG_DATE_FORMAT`

String (Default: +%F %T)

The display format for the date as passed to the `date` binary to generate a datestamp used as a prefix to:

* `FILE` type log file lines.
* Each console output line when `BASHLOG_EXTRA=1`

##### `BASHLOG_EXTRA`

Integer (Default: 0)

By default, console output from tfenv does not print a date stamp or log severity.

To enable this functionality, making normal output equivalent to FILE log output, set to 1.

##### `BASHLOG_FILE`

Integer (Default: 0)

Set to 1 to enable plain text logging to file (FILE type logging).

The default path for log files is defined by /tmp/$(basename $0).log
Each executable logs to its own file.

e.g.

```console
BASHLOG_FILE=1 tfenv use latest
```

will log to `/tmp/tfenv-use.log`

##### `BASHLOG_FILE_PATH`

String (Default: /tmp/$(basename ${0}).log)

To specify a single file as the target for all FILE type logging regardless of the executing script.

##### `BASHLOG_I_PROMISE_TO_BE_CAREFUL_CUSTOM_EVAL_PREFIX`

String (Default: "")

*BE CAREFUL - MISUSE WILL DESTROY EVERYTHING YOU EVER LOVED*

This variable allows you to pass a string containing a command that will be executed using `eval` in order to produce a prefix to each console output line, and each FILE type log entry.

e.g.

```console
BASHLOG_I_PROMISE_TO_BE_CAREFUL_CUSTOM_EVAL_PREFIX='echo "${$$} "'
```
will prefix every log line with the calling process' PID.

##### `BASHLOG_JSON`

Integer (Default: 0)

Set to 1 to enable JSON logging to file (JSON type logging).

The default path for log files is defined by /tmp/$(basename $0).log.json
Each executable logs to its own file.

e.g.

```console
BASHLOG_JSON=1 tfenv use latest
```

will log in JSON format to `/tmp/tfenv-use.log.json`

JSON log content:

`{"timestamp":"<date +%s>","level":"<log-level>","message":"<log-content>"}`

##### `BASHLOG_JSON_PATH`

String (Default: /tmp/$(basename ${0}).log.json)

To specify a single file as the target for all JSON type logging regardless of the executing script.

##### `BASHLOG_SYSLOG`

Integer (Default: 0)

To log to syslog using the `logger` binary, set this to 1.

The basic functionality is thus:

```console
local tag="${BASHLOG_SYSLOG_TAG:-$(basename "${0}")}";
local facility="${BASHLOG_SYSLOG_FACILITY:-local0}";
local pid="${$}";

logger --id="${pid}" -t "${tag}" -p "${facility}.${severity}" "${syslog_line}"
```

##### `BASHLOG_SYSLOG_FACILITY`

String (Default: local0)

The syslog facility to specify when using SYSLOG type logging.

##### `BASHLOG_SYSLOG_TAG`

String (Default: $(basename $0))

The syslog tag to specify when using SYSLOG type logging.

Defaults to the PID of the calling process.



### tfenv use &lt;version>

Switch a version to use

`latest` is a syntax to use the latest installed version
Expand All @@ -144,17 +297,21 @@ $ tfenv use latest:^0.8
```

### tfenv uninstall &lt;version>

Uninstall a specific version of Terraform
`latest` is a syntax to uninstall latest version
`latest:<regex>` is a syntax to uninstall latest version matching regex (used by grep -e)

```console
$ tfenv uninstall 0.7.0
$ tfenv uninstall latest
$ tfenv uninstall latest:^0.8
```

### tfenv list

List installed versions

```console
% tfenv list
* 0.10.7 (set by /opt/tfenv/version)
Expand All @@ -169,7 +326,9 @@ List installed versions
```

### tfenv list-remote

List installable versions

```console
% tfenv list-remote
0.9.0-beta2
Expand All @@ -193,8 +352,9 @@ List installable versions
...
```

## .terraform-version
If you put `.terraform-version` file on your project root, or in your home directory, tfenv detects it and use the version written in it. If the version is `latest` or `latest:<regex>`, the latest matching version currently installed will be selected.
## .terraform-version file

If you put a `.terraform-version` file on your project root, or in your home directory, tfenv detects it and uses the version written in it. If the version is `latest` or `latest:<regex>`, the latest matching version currently installed will be selected.

```console
$ cat .terraform-version
Expand All @@ -218,16 +378,19 @@ Terraform v0.8.8
```

## Upgrading

```console
$ git --git-dir=~/.tfenv/.git pull
```

## Uninstalling

```console
$ rm -rf /some/path/to/tfenv
```

## LICENSE

- [tfenv itself](https://github.com/tfutils/tfenv/blob/master/LICENSE)
- [rbenv](https://github.com/rbenv/rbenv/blob/master/LICENSE)
- tfenv partially uses rbenv's source code
Loading

0 comments on commit 5f98e8c

Please sign in to comment.