terraform-github-actions

terraform-output action

This is one of a suite of Terraform related actions - find them at dflook/terraform-github-actions.

Retrieve the root-level outputs from a Terraform configuration.

Inputs

Environment Variables

Outputs

An action output will be created for each output of the Terraform configuration.

For example, with the Terraform config:

output "service_hostname" {
  value = "example.com"
}

Running this action will produce a service_hostname output with the value example.com.

Primitive types (string, number, bool)

The values for these types get cast to a string with boolean values being ‘true’ and ‘false’.

Complex types (list/set/tuple & map/object)

The values for complex types are output as a JSON string. Terraform list, set & tuple types are cast to a JSON array, map and object types are cast to a JSON object.

These values can be used in a workflow expression by using the fromJSON function

Example usage

String

This example uses a Terraform string output to get a hostname:

on: [push]

jobs:
  show_hostname:
    runs-on: ubuntu-latest
    name: Show the hostname
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Get outputs
        uses: dflook/terraform-output@v1
        id: tf-outputs
        with:
          path: my-terraform-config

      - name: Print the hostname
        run: echo "The hostname is $"

Complex output

This example gets information from object and array(object) outputs.

With this Terraform config:

output "vpc" {
  value = aws_vpc.test
}
output "subnets" {
  value = [aws_subnet.a, aws_subnet.b, aws_subnet.c]
}

We can use the workflow:

jobs:
  output_example:
    runs-on: ubuntu-latest
    name: An example of workflow expressions with terraform output
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Get outputs
        uses: dflook/terraform-output@v1
        id: tf-outputs
        with:
          path: my-terraform-config

      - name: Print VPC
        run: |
          echo "The vpc-id is $"
          echo "The subnet-ids are $"          

Which will print to the workflow log:

The vpc-id is vpc-01463b6b84e1454ce
The subnet-ids are subnet-053008016a2c1768c,subnet-07d4ce437c43eba2f,subnet-0a5f8c3a20023b8c0