Use Terraform Outputs in Workflow Steps

Updated 1 year ago by Michael Cretzman

To define a dynamically provisioned target Infrastructure Definition, you map the Terraform script output variables to the required Harness settings. To perform the mapping you use a Harness variable expression in the format ${terraform.output_name}.

These outputs can be used in other Workflow steps by using the same expressions.

This topic demonstrates how to use these expressions in other Workflow steps.

In this topic:

Before You Begin

This topic assumes you have read the following:

Step 1: Add a Workflow Step

This topic assumes you have a Workflow that uses an Infrastructure Definition that is dynamically mapped to a Harness Terraform Infrastructure Provisioner. For details, see Map Terraform Infrastructure.

Add a Workflow step where you want to use the Terraform script output. Typically, this is a Shell Script step.

Step 2: Enter the Output Variable Expression

You can use any variable expression that is already used in the Infrastructure Definition in the Workflow settings. For Canary Workflows, the Infrastructure Definition is added in the Phase settings.

For example, let's say you use ${terraform.clusterName} to map a cluster name output to the cluster name in an Infrastructure Definition. You can add a Shell Script step in your Workflow and use echo ${terraform.clusterName} to print the value.

You can see the Terraform log display the output clusterName = us-central1-a/harness-test in the following Terraform Provision step:

Next, you could add a Shell Script step that uses the Terraform output variable ${terraform.clusterName}:

In the Shell Script step in the deployment, you can see the value us-central1-a/harness-test printed:

How did we do?