Skip to content

dougbw/pwsh-terrafun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure DevOps builds (branch) Azure DevOps coverage (branch) Azure DevOps tests GitHub issues

terrafun

demo

Table of Contents

  1. Installation
  2. Usage
  3. Commands
  4. How to set terraform version

Terrafun

Terrafun is a tool for managing terraform versions. It enables seemless switching between different terraform versions which can be controlled by an environment variable, file, or user profile. It has been written in PowerShell but has been designed to support being used across multiple platforms and from different shells.

Features

  • terraform version management

Installation

PowerShell Gallery PowerShell Gallery Version

Once you have PowerShell installed this module can be installed from the from the PowerShell Gallery.

Supported platforms:

OS Edition Build
Windows Windows PowerShell (v5) Build Status
Windows PowerShell Core (v6+) Build Status
Linux PowerShell Core (v6+) Build Status
MacOs PowerShell Core (v6+) Build Status

Installation (in pwsh)

Install-Module terrafun -Force

Installation (in anything else)

pwsh -c "Install-Module terrafun -Force"

Update (in pwsh)

Uninstall-Module -Name terrafun -AllVersions -Force
Install-Module terrafun -Force

Usage

Install the module and simply run tf in place of terraform. E.g:

tf version
tf init
tf plan
tf apply

Usage in other shells

You can use this from other shells (bash, zsh, sh, etc) through aliases providing you have a working PowerShell installation on your workstation. You can create aliases named to terraform instead of tf if you prefer.

  • Install PowerShell on your machine
  • Install the module using the instructions above
  • Create an alias for your actual shell, examples below....

bash alias

echo "alias tf='pwsh -c tf'" >> ~/.bashrc
alias tf='pwsh -c tf'

zsh alias

echo "alias tf='pwsh -c tf'" >> ~/.zshrc
alias tf='pwsh -c tf'

Commands

Other than a couple of commands for version management you use tf exactly the same as if you are executing terraform directly.

Command Description
tf version list list available terraform versions
tf version <version> set a specific version of terraform for the current directory
tf version <version> global set a specific version of terraform across your user profile

How to set terraform version

There are three methods for selecting the desired version of terraform, prioritized in the following order:

  1. Environment Variable
  2. File
  3. User Profile

Environment Variable method

Set the terraformversion environment variable and you will get that version of terraform

bash

terraformversion="1.0.0"
tf

PowerShell

$env:terraformversion = "1.0.0"
tf

File method

Use the tf version {version} command which will save the version into a file named .terraformversion in the current directory.

tf version 0.13.5

User Profile method

Use the tf version {version} global command which will store the version infomation in a config file within your user profile: ~/.terrafun/config.json

tf version 0.13.5 global

Binary install location

Binaries are downloaded to the following directory in your user profile:

 ~/.terrafun/terraform_{version}_{platform}_{arch}/terraform(.exe)

About

Oh no! its another version manager for terraform

Topics

Resources

License

Stars

Watchers

Forks