Harness, Terragrunt, and other IaC

In Continuous Delivery, every company has a different need or requirement for their Infrastructure (i.e. ephemeral environments, environment bootstrapping, scaling infrastructure for single-tenant applications, etc.). The use of Infrastructure-as-Code is becoming more of an essential for every DevOps Engineer to automate the way that their Infrastructure is created or behaves.

Although Harness has the ability to integrate very well with Terraform and CloudFormation, it would be naive to assume that every company in the world only uses those two specific IaC options (although they are the most popular). There are different IaCs available (like Pulumi), plugins for Terraform or CloudFormation (like Terragrunt), and even Change Management providers (like Puppet, Chef, or Ansible) that can be used to manage infrastructure. In fact, some of these tools have such a lack of opinionation, you can make them do a host of different things (like deploying) through writing and maintaining scripts.

Whenever a user starts to use Harness, more often than not, there is a prior setup using one of the tools above, typically because there were not many good tools to handle everything that they needed or because of a SysAdmin that was convinced that Ansible can do anything, if I script it enough. So, for those who are not using straight Terraform or CloudFormation, especially if there has been a significant investment in some of the other tools mentioned, this post will help you automate your processes using Harness’s Shell Script Infrastructure Provisioner.

For a high-level how-to, this link will help you with the setup of a Shell Script Provisioner and this link is an overview Infrastructure Provisioners.

We will assume the use of Terragrunt for the rest of this post, but the example can be easily extended to the rest of the available tools.

The three main commands that we will be looking at is Terragrunt Plan, Terragrunt Apply, and Terragrunt Destroy.

  1. Create a Shell Script Provisioner called Terragrunt Plan


  1. If you want to run the commands from the delegate, you’ll need to pull the repo down using git, and then run the desired CLI command

  1. You might require the ability to add variables or encrypted strings (like AWS Account Info) for the command. For this, use the Variables section

  1. You’ll follow the same steps to create a Terragrunt Apply-All and a Terragrunt Destroy-All version as well

  1. The next step is to tie them all together in a workflow. Create a Multi-Service Workflow

  1. Add the Shell Script Provisioners in the pre-deployment phase as needed (The example will show an approval after the plan is run in order to approve the apply step)

This process will look the same with the other tools that you might have. Make sure that you put the Terragrunt and Git CLIs in the Delegate Profile to make sure you can execute the commands as needed (follow this doc if you need direction on setting up a delegate profile).

Hopefully this helps!

Don’t forget to like/comment/share!

1 Like