Giter Site home page Giter Site logo

robertpeteuil / terraform-installer Goto Github PK

View Code? Open in Web Editor NEW
74.0 8.0 40.0 86 KB

Installer for HashiCorp Terraform - Automatic Download, Extract and Install of Latest or Specific Version

License: Apache License 2.0

Shell 100.00%
terraform terraform-scripts installer bash-script automated-deployment automation hashicorp-downloads terraform-installer hashicorp-terraform hashicorp

terraform-installer's Introduction

Installer for HashiCorp Terraform - Automated Installation

Automatically Download, Extract and Install Latest or Specific Version

release bash license


Note: An updated script with additional capabilities and multi-product support has been published to the hashicorp-installer repo. It defaults to installing Terraform and can be a drop-in replacement for this script.


The terraform-install script automates the process of downloading and installing Terraform. It provides an ideal method for installing installing updates or a specific version.

This script detects the latest version, OS and CPU-Architecture and allows installation to local or system locations. Optional parameters allow installing a specific version and installing to /usr/local/bin without prompting.

Example - install last pre-0.13 release: ./terraform-install.sh -i 0.12.29

Options:

  • -i VERSION: Install specific version
  • -a: Automatically use sudo to install to /usr/local/bin
    • allows for unattended installation via scripts or CD tools
    • can be set as default behavior by uncommenting line 14 (sudoInstall=true)
    • sudo password may be required unless NOPASSWD is enabled
  • -c: leave binary in working directory (for CI/DevOps use)
  • -h: help
  • -v: display version

This installer is similar to my Packer Installer and Vault Installer

Download and Use Locally

Download Installer

curl -LO https://raw.github.com/robertpeteuil/terraform-installer/master/terraform-install.sh
chmod +x terraform-install.sh

Download installer via my bootstrap server (iac.sh or https://iac.sh)

curl iac.sh/terraform > getinst.sh
bash getinst.sh
# installer downloaded as terraform-install.sh in current directory

Run local installer

./terraform-install.sh

# usage: terraform-install.sh [-i VERSION] [-a] [-c] [-h] [-v]
#      -i VERSION	: specify version to install in format '' (OPTIONAL)
#      -a		: automatically use sudo to install to /usr/local/bin
#      -c		: leave binary in working directory (for CI/DevOps use)
#      -h		: help
#      -v		: display vault-install.sh version

System Requirements

  • System with Bash Shell (Linux, macOS, Windows Subsystem for Linux)
  • unzip - terraform downloads are in zip format
  • curl or wget - script will use either one to retrieve metadata and download

Optional

  • jq - if installed, latest version parsed from hashicorp downloads
    • Useful if latest github release differs from version on hashicorp downloads
    • Avoids github api limit of 60 requests per hour (unauthenticated)

Script Process Details

  • Determines Version to Download and Install
    • Uses Version specified by -i VERSION parameter (if specified)
    • Otherwise determines Latest Version
      • If jq installed parse version from hashicorp downloads
      • Otherwise use GitHub API to retrieve latest version
  • Calculates Download URL based on Version, OS and CPU-Architecture
  • Verifies URL Validity before Downloading in Case:
    • VERSION incorrectly specified with -i
    • Download URL Format Changed on terraform Website
  • Determines Install Destination
    • The destination can be specified with -c option, or passing TF_INSTALL_DIR environment variable
    • The default is /usr/local/bin if it is writable, or with -a
    • Otherwise the user is prompted for options
    • Performed before Download/Install Process in case user selects abort
  • Installation Process
    • Download, Download SHA, Verify SHA of zip, Extract, Install, Cleanup and Display Results

CPU Architecture Detection

CPU architecture is detected for each OS accordingly:

  • Linux / Windows (WSL since this is a Bash script)
    • detected with lscpu or by inspecting /proc/cpuinfo
    • Arm variants use arm as it's the only arm version available (for now)
  • macOS - uses Default Arch amd64 as it's the only version available on macOS
  • Default Value - amd64

Disclaimer

I am a HashiCorp employee, but this is a personal project and not officially endorsed or supported by HashiCorp.

License

Apache 2.0 License - Copyright (c) 2020 Robert Peteuil

terraform-installer's People

Contributors

drmikecrowe avatar robertpeteuil avatar tmatilai avatar vlad-ro 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-installer's Issues

sort --version-sort not supported on OSX 10.10

this makes heavy use of sort --version-sort which isn't a thing on osx (at least not 10.9, 10.10, and I dont really expect that to have changed in later releases...)

additionally, there's no handling (trap, set -e, something) around failed calls to external tools, so the script just plows right on through the error producing who knows what results....

%% ./terraform-install.sh -h
sort: unrecognized option `--version-sort'
Try `sort --help' for more information.
Download and Install Terraform - Latest Version unless '-i' specified

usage: terraform-install.sh [-i VERSION] [-a] [-c] [-h] [-v]
     -i VERSION	: specify version to install in format '' (OPTIONAL)
     -a		: automatically use sudo to install to /usr/local/bin
     -c		: leave binary in working directory (for CI/DevOps use)
     -h		: help
     -v		: display terraform-install.sh version

Future: add cpu detection for `arm64` for Terraform 0.14.0+

Starting with Terraform 0.14.0, HashiCorp will begin publishing a linux/arm64 binary in addition to the current linux/arm binary. (0.13.5 was re-published for linux/arm64 as well.)

The CPU detection logic will need to be adjusted accordingly. In the sort term, I don't suspect many terraform users will be running this as their primary desktop.

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.