From 4b76b06148033344750b431df951fcac5c0ef95b Mon Sep 17 00:00:00 2001 From: Michael Seele Date: Tue, 5 May 2026 09:22:49 +0000 Subject: [PATCH] feat: add output export for Terraform apply action --- terraform-apply/README.md | 10 +++++++++- terraform-apply/action.yml | 11 ++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/terraform-apply/README.md b/terraform-apply/README.md index 2cb60c6..4828152 100644 --- a/terraform-apply/README.md +++ b/terraform-apply/README.md @@ -12,18 +12,26 @@ Apply Terraform configuration files using the official Terraform CLI. | `workspace` | No | `""` | Terraform workspace to select | | `jfrog-token` | No | `""` | JFrog Artifactory token for the Terraform provider registry (`TF_TOKEN_schmalz_jfrog_io`) | +## Outputs + +All Terraform outputs are automatically exported after apply. They are accessible on the calling step via `steps..outputs.`. Complex types (lists, maps) are JSON-encoded. + ## Usage ```yaml - uses: https://schmalz-git.git.onstackit.cloud/schmalz/shared-actions/terraform-apply@terraform-apply-v1 + id: tf-apply with: workspace: stage var-file: stage.tfvars jfrog-token: ${{ secrets.JFROG_TOKEN }} + +- run: echo ${{ steps.tf-apply.outputs.s3_bucket_name }} ``` ## Notes - Runs `terraform init`, selects the workspace (if provided), and applies with `-auto-approve`. - Sets `TF_TOKEN_schmalz_jfrog_io` on both `init` and `apply` steps if `jfrog-token` is provided. -- If `var-file` is provided, it is passed as `-var-file` to the apply command. \ No newline at end of file +- If `var-file` is provided, it is passed as `-var-file` to the apply command. +- All Terraform outputs are written to `$GITHUB_OUTPUT` after apply — no separate `terraform output` step needed. \ No newline at end of file diff --git a/terraform-apply/action.yml b/terraform-apply/action.yml index 23899ac..a22fc6a 100644 --- a/terraform-apply/action.yml +++ b/terraform-apply/action.yml @@ -61,4 +61,13 @@ runs: if [ -n "$VAR_FILE" ]; then ARGS="$ARGS -var-file=$VAR_FILE" fi - terraform -chdir="$TF_DIR" apply $ARGS \ No newline at end of file + terraform -chdir="$TF_DIR" apply $ARGS + + - name: Export Terraform Outputs + shell: bash + env: + TF_DIR: ${{ inputs.terraform-dir }} + run: | + terraform -chdir="$TF_DIR" output -json | \ + jq -r 'to_entries[] | "\(.key)=\(.value.value | if type == "string" then . else tojson end)"' \ + >> "$GITHUB_OUTPUT" \ No newline at end of file