terraform-github-actions

tofu-output action

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

Retrieve the root-level outputs from an OpenTofu configuration.

Inputs

Outputs

Environment Variables

Example usage

String

This example uses an OpenTofu 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/tofu-output@v1
        id: tf-outputs
        with:
          path: my-tofu-config

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

Complex output

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

With this OpenTofu 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 tofu output
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Get outputs
        uses: dflook/tofu-output@v1
        id: tf-outputs
        with:
          path: my-tofu-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