Harness ❤️ Terraform

Hi guys, here at Harness we love leveraging Terraform. I noticed some customers leverage the Terraform Outputs in workflows in a pipeline. Today, I want to share with the community how do this.

Use Case

  • Taking the Outputs and print out a summary for the Developer or the Deployment Management Team
  • Updating a JIRA ticket with crucial information about the Infrastructure provisioned
  • Powerful to leverage when a development team wants to use ephemeral environments when testing features.

Step 1

Go to your source code repository and make sure you are outputting some variables for Harness to leverage! In this example, I’m outputting the AWS Region, the value blackbelt (Harness Solution Architecture Team :smiley:) and the cluster name.

Step 2

Next go to your application and create a workflow that you are using to provision infrastructure. If you need help with this, please refer to the Harness Docs on Infrastructure Provisioning through Terraform: https://docs.harness.io/article/9pvvgcdbjh-terrform-provisioner

Click on ‘Add Command’ and select Shell Script.

Step 3

In Harness we refer to the terraform outputs like so:




These output values need to match like so ${terraform.output_val_here}. Next, add the variables to the script outputs section like screenshot below.

Click on the “Publish Output in Context Box”

In the Publish Variable Name section, please provide a variable you want to publish all these values under. In this example, I chose info, but it can be anything you want.

Now to leverage the variable in a pipeline please click on the scope dropdown and select “Pipeline”.

Note: You can also choose “Phase”, or “Workflow”. The Scope gets smaller when you choose those options. Please hit submit.

Step 4

Within your application, create a new workflow and select a canary type. The canary workflow isn’t tied to service but an environment so you can leverage this in numerous ways. You can pass the outputs into the Pre Deployment step, or during an actual phase of the deployment.

Pro Tip: Canary is an excellent way to do Terraform Provisioning.

Step 5

Once the Workflow is created, please navigate to the Pre-Deployment Phase and “add a command”. Select Shell Script and add the following information or similar information if your doing your own values. In this example, we are just printing the variables.

More Complex Use Case:

  • Passing it along in a JIRA Ticket, ServiceNow Ticket
  • Passing the contents in an Email
  • Using that information for a deployment, or deployment configuration

Hit Submit to continue.

Step 6

Please create a Pipeline in the Application. Add The Provisioning Workflow as the first stage and the Outputting workflow as the Second Stage.

Step 7

Run the deployment and view the outputs. In my case, I’m provisioning an ECS Cluster named “Rohan”. I am deploying Nginx into the ECS Cluster. I’m printing out the values in a shell script.

For stage 1:

For stage 2:

Hope this tutorial helps you leverage terraform outputs in your deployment. Thanks for reading!