Cyberithub

How to Install Terragrunt on Linux Using 4 Simple Steps

Advertisements

In this article, I will take you through the steps to install terragrunt on Linux using 4 simple steps. Terragrunt is a free and open source wrapper from Gruntwork.io which provides extra tools for keeping your configurations DRY, working with multiple Terraform modules, and managing remote state. It basically fills all the functionality gaps in Terraform. Although terraform has lot of advance features set available but when it comes to implementation, perfection is guaranteed with the use of terragrunt.

Some Important Features

  • It defines terraform code once irrespective of the number of environments you have.
  • It execute terraform commands on multiple modules at once.
  • It helps in avoiding duplicated backend code.
  • It provides the ability to run custom code before or after the terraform.
  • It sets CLI arguments for repeatable terraform commands once in terragrunt configuration.

How to Install Terragrunt on Linux Using 4 Simple Steps

How to Install Terragrunt on Linux Using 4 Simple Steps

Also Read: How to count number of lines in a File from Linux Terminal

Step 1: Prerequisites

a) You should have a running Linux(in our case it is Ubuntu 20.04 LTS) Server.

b) You should have sudo or root access to run privileged commands.

c) You should have apt and wget utility available in your System.

 

Step 2: Update Your Server

In the first step, you need to update your package cache with all the latest available versions from all the enabled repositories by using sudo apt update command as shown below.

cyberithub@ubuntu:~$ sudo apt update
Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:3 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:4 http://in.archive.ubuntu.com/ubuntu focal InRelease
Hit:5 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal InRelease
Hit:6 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease
Get:7 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Fetched 108 kB in 2s (59.3 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done

If you are using any RHEL/CentOS based systems, then you can update the packages to the latest version by using yum update or dnf update command.

 

Step 3: Install Terragrunt

There are multiple ways to install terragrunt on a Linux system. You can choose any of the below method depending on the Linux distribution you are currently using.

a) Using Snap

If you want to install the wrapper as snap package then you need to use sudo snap install terragrunt command as shown below.

cyberithub@ubuntu:~$ sudo snap install terragrunt
terragrunt 0+git.ae675d6 from dt9394 (terraform-snap) installed

b) Using Brew

If you have brew utility available in your System, then you can easily install terragrunt using brew install terragrunt command as shown below.

NOTE:

Please note that brew is the default package manager on macOS systems. If you would like to know the steps to install this package manager on Ubuntu 20.04 LTS based systems, then you need to check How to Install Homebrew Package Manager on Ubuntu 20.04 LTS.
cyberithub@ubuntu:~$ brew install terragrunt
Running `brew update --auto-update`...
==> Downloading https://ghcr.io/v2/homebrew/core/zstd/manifests/1.5.2-3
Already downloaded: /home/cyberithub/.cache/Homebrew/downloads/f1226cb81ee54df46f1bb53da8118ca107a4f229ac63dc9405f2519c9f6fb45e--zstd-1.5.2-3.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/zstd/blobs/sha256:006b5ab6a4616a8b6f59953cb9efb546d312e3ba231c303bb56749e7f66f56df
Already downloaded: /home/cyberithub/.cache/Homebrew/downloads/fad42b2ea8e815a7377d5254c66ab075b4ff6731cd31f4073a5b69fbeb1b424d--zstd--1.5.2.x86_64_linux.bottle.3.tar.gz
==> Downloading https://ghcr.io/v2/homebrew/core/gcc/11/manifests/11.3.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/gcc/11/blobs/sha256:64d9c853ddbe63e0361a993560da8b7883bde57854bef20a0f07afa4aa597b34
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:64d9c853ddbe63e0361a993560da8b7883bde57854bef20a0f07afa4aa597b34?se=2022
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/terraform/manifests/1.2.9
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/terraform/blobs/sha256:346db9dd674f6d4ebe783b5bb32364834ae2ebd991e523d745ed3eaf56fde1ac
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:346db9dd674f6d4ebe783b5bb32364834ae2ebd991e523d745ed3eaf56fde1ac?se=2022
######################################################################## 100.0%==> Downloading https://ghcr.io/v2/homebrew/core/terragrunt/manifests/0.38.12
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/terragrunt/blobs/sha256:50b05a9f9f82f52cf8717c90d1944fcd2e7c9fafe719188e33e86a1f012687e0
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:50b05a9f9f82f52cf8717c90d1944fcd2e7c9fafe719188e33e86a1f012687e0?se=2022
######################################################################## 100.0%
==> Installing dependencies for terragrunt: zstd, gcc@11 and terraform
==> Installing terragrunt dependency: zstd
==> Pouring zstd--1.5.2.x86_64_linux.bottle.3.tar.gz
🍺 /home/linuxbrew/.linuxbrew/Cellar/zstd/1.5.2: 31 files, 2.6MB
==> Installing terragrunt dependency: gcc@11
==> Pouring gcc@11--11.3.0.x86_64_linux.bottle.tar.gz
==> Creating the GCC specs file: /home/linuxbrew/.linuxbrew/Cellar/gcc@11/11.3.0/bin/../lib/gcc/11/gcc/x86_64-pc-linux-gnu/11/specs
🍺 /home/linuxbrew/.linuxbrew/Cellar/gcc@11/11.3.0: 2,187 files, 347.3MB
==> Installing terragrunt dependency: terraform
==> Pouring terraform--1.2.9.x86_64_linux.bottle.tar.gz
🍺 /home/linuxbrew/.linuxbrew/Cellar/terraform/1.2.9: 6 files, 60.5MB
==> Installing terragrunt
==> Pouring terragrunt--0.38.12.x86_64_linux.bottle.tar.gz
🍺 /home/linuxbrew/.linuxbrew/Cellar/terragrunt/0.38.12: 5 files, 24.8MB
==> Running `brew cleanup terragrunt`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

c) Using Binary Package

To install the binary package, you need to go to Release page and download the latest release from Asset section as shown below.

cyberithub@ubuntu:~$ wget https://github.com/gruntwork-io/terragrunt/releases/download/v0.38.12/terragrunt_darwin_amd64
--2022-09-16 01:29:31-- https://github.com/gruntwork-io/terragrunt/releases/download/v0.38.12/terragrunt_darwin_amd64
Resolving github.com (github.com)... 20.207.73.82
Connecting to github.com (github.com)|20.207.73.82|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/59522149/1b75bb36-25ec-40ad-8444-043c27ff54a5?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220915%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220915T195931Z&X-Amz-Expires=300&X-Amz-Signature=8a920e13e94bafc0bb4b2f1e75f07a4103948f0f23f16f9b7add4935ead6e100&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=59522149&response-content-disposition=attachment%3B%20filename%3Dterragrunt_darwin_amd64&response-content-type=application%2Foctet-stream [following]
--2022-09-16 01:29:32-- https://objects.githubusercontent.com/github-production-release-asset-2e65be/59522149/1b75bb36-25ec-40ad-8444-043c27ff54a5?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220915%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220915T195931Z&X-Amz-Expires=300&X-Amz-Signature=8a920e13e94bafc0bb4b2f1e75f07a4103948f0f23f16f9b7add4935ead6e100&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=59522149&response-content-disposition=attachment%3B%20filename%3Dterragrunt_darwin_amd64&response-content-type=application%2Foctet-stream
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.108.133, 185.199.109.133, 185.199.110.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.108.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 35034272 (33M) [application/octet-stream]
Saving to: ‘terragrunt_darwin_amd64’

terragrunt_darwin_amd64 100%[============================================================================>] 33.41M 7.00MB/s in 4.5s

2022-09-16 01:29:37 (7.41 MB/s) - ‘terragrunt_darwin_amd64’ saved [35034272/35034272]

Once downloaded in the local system, you need to rename the downloaded file to terragrunt using mv terragrunt_darwin_amd64 terragrunt command as shown below.

cyberithub@ubuntu:~$ mv terragrunt_darwin_amd64 terragrunt

Then you need to provide execute permission to terragrunt binary to make it executable using chmod u+x terragrunt command  as shown below.

cyberithub@ubuntu:~$ chmod u+x terragrunt

Finally, move the executable binary to /usr/local/bin location to make it available across the System.

cyberithub@ubuntu:~$ sudo mv terragrunt /usr/local/bin/terragrunt

Now you should be able to use terragrunt tool from anywhere in the System.

 

Step 4: Check all available options

You can check all the options available with terragrunt utility using terragrunt --help command as shown below.

cyberithub@ubuntu:~$ terragrunt --help
DESCRIPTION:
terragrunt - Terragrunt is a thin wrapper for Terraform that provides extra tools for working with multiple
Terraform modules, remote state, and locking. For documentation, see https://github.com/gruntwork-io/terragrunt/.

USAGE:
terragrunt <COMMAND>

COMMANDS:
plan-all Display the plans of a 'stack' by running 'terragrunt plan' in each subfolder
apply-all Apply a 'stack' by running 'terragrunt apply' in each subfolder
output-all Display the outputs of a 'stack' by running 'terragrunt output' in each subfolder
destroy-all Destroy a 'stack' by running 'terragrunt destroy' in each subfolder
* Terragrunt forwards all other commands directly to Terraform

GLOBAL OPTIONS:
terragrunt-config Path to the Terragrunt config file. Default is terraform.tfvars.
terragrunt-tfpath Path to the Terraform binary. Default is terraform (on PATH).
terragrunt-non-interactive Assume "yes" for all prompts.
terragrunt-working-dir The path to the Terraform templates. Default is current directory.
terragrunt-source Download Terraform configurations from the specified source into a temporary folder, and run Terraform in that temporary folder.
terragrunt-source-update Delete the contents of the temporary folder to clear out any old, cached source code before downloading new source code into it.
terragrunt-ignore-dependency-errors *-all commands continue processing components even if a dependency fails.

VERSION:


AUTHOR(S):
Gruntwork <www.gruntwork.io>

Leave a Comment