'Download terraform plan as a file from GitHub

I am working on a GitHub Actions pipeline where I am creating a terraform plan and then after downloading and reviewing the plan in a file authentication the apply stage. Everything is working smoothly, I get a plan that I am then saving as a tt file using the 'out' flag, but I am not able to figure out how to download the plan file from the runner to my local machine or even save it as an artifact. Please help me out if there is a workaround.

name: 'Terraform PR'
on:
  push:
    branches:
      - main
  pull_request:

jobs:
  terraform:
    name: 'Terraform'
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: infrastructure/env/dev-slb-alpha/dev
    permissions:
      id-token: write
      contents: write

    steps:
      - name: Clone Repository (Latest)
        uses: actions/checkout@v2
        if: github.event.inputs.git-ref != ''
      - name: Clone Repository (Custom Ref)
        uses: actions/checkout@master
        if: github.event.inputs.git-ref == ''
        with:
          ref: ${{ github.event.inputs.git-ref }}

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@master
        with:
          role-to-assume: arn:aws:iam::262267462662:role/slb-dev-github-actions
          aws-region: us-east-1
          # role-session-name: GithubActionsSession
      - name: Setup Terraform
        uses: hashicorp/setup-terraform@v1
        with:
          terraform_version: 1.1.2

      - name: Terraform Format
        id: fmt
        run: terraform fmt -check

      - name: Terraform Init
        id: init
        run: |
          # cd infrastructure/env/dev-slb-alpha/dev
          terraform init
      - name: Terraform Validate
        id: validate
        run: terraform validate -no-color

      - name: Terraform Plan
        id: plan
        if: github.event_name == 'pull_request'
        continue-on-error: true
        run: |
          # cd infrastructure/env/dev-slb-alpha/dev
          touch tfplan.txt
          # terraform force-unlock -force d5f2d86a-e0f6-222f-db3f-2c1d792ed528
          # terraform force-unlock -force QOCDA86JVO02CCFV3SB010RGP3VV4KQNSO5AEMVJF66Q9ASUAAJG
          terraform plan -lock=false -input=false -out=tfplan.txt
          readlink -f tfplan.txt


      - name: terraform plan upload
        uses: actions/upload-artifact@v2
        with:
         name: plan
         path: tfplan.txt
         retention-days: 5
         
      - uses: actions/download-artifact@v3
        with:
         name: my-plan
         path: tfplan.txt
       

      - name: Terraform Apply
        id: apply
        if: github.event_name == 'pull_request'
        run: |
          cd infrastructure/env/dev-slb-alpha/dev
          terraform force-unlock -force 8de3f689-282e-12fd-72b2-cdd27f94e4da
          terraform apply 


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source