terraform-plan-comment icon indicating copy to clipboard operation
terraform-plan-comment copied to clipboard

Seeing `d token 'c', "[command]/h"... is not valid JSON`

Open hencrice opened this issue 8 months ago • 1 comments

Hi!

Here's my Github Action workflow:

name: CI Pipeline

on:
  pull_request:
    branches:
      - dev

jobs:
  terraform:
    name: validate and plan
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read
      pull-requests: write

    strategy:
      matrix:
        # environment: [staging, production]
        environment: [staging]
        workload_identity_provider: [
            # staging
            'projects/12313737332/locations/global/workloadIdentityPools/infrastructure-pool/providers/infrastructure-provider',
            # production
            'projects/<TBD>/locations/global/workloadIdentityPools/infrastructure-pool/providers/infrastructure-provider'
        ]
        exclude:
          - environment: staging
            workload_identity_provider: 'projects/<TBD>/locations/global/workloadIdentityPools/infrastructure-pool/providers/infrastructure-provider'
          - environment: production
            workload_identity_provider: 'projects/12313737332/locations/global/workloadIdentityPools/infrastructure-pool/providers/infrastructure-provider'

    steps:
      - name: Checkout code
        uses: actions/checkout@v4
    
      - id: auth
        name: Setup Google Cloud credentials for ${{ matrix.environment }} 
        uses: 'google-github-actions/auth@v2'
        with:
          project_id: dr-copilot-${{ matrix.environment }}
          workload_identity_provider: ${{ matrix.workload_identity_provider }}
          export_environment_variables: true
          create_credentials_file: true
          cleanup_credentials: true

      - name: Setup Terraform
        uses: hashicorp/setup-terraform@v2
        with:
            terraform_version: 1.11.4
      
      - name: ${{ matrix.environment }} terraform fmt
        id: fmt
        run: terraform fmt -check
        continue-on-error: false
        working-directory: environments/${{ matrix.environment }}

      - name: ${{ matrix.environment }} terraform init
        id: init
        run: terraform init
        working-directory: environments/${{ matrix.environment }}

      - name: ${{ matrix.environment }} terraform validate
        id: validate
        run: terraform validate -no-color
        working-directory: environments/${{ matrix.environment }}
      
      - name: ${{ matrix.environment }} terraform test
        id: test
        run: terraform test
        working-directory: environments/${{ matrix.environment }}

      - name: ${{ matrix.environment }} terraform plan
        id: plan
        run: terraform plan -out plan.out
        working-directory: environments/${{ matrix.environment }}
    
      - name: Post PR comment
        uses: borchero/terraform-plan-comment@v2
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          planfile: plan.out
          working-directory: environments/${{ matrix.environment }}

However, when the plan comment action ran it errored out:

Run borchero/terraform-plan-comment@v2
  with:
    token: ***
    planfile: plan.out
    working-directory: environments/staging
    terraform-cmd: terraform
    header: 📝 Terraform Plan
    skip-empty: false
    skip-comment: false
  env:
    CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE: /home/runner/work/davinci-resolve-copilot-infrastructure/davinci-resolve-copilot-infrastructure/gha-creds-d517aae9e66fa904.json
    GOOGLE_APPLICATION_CREDENTIALS: /home/runner/work/davinci-resolve-copilot-infrastructure/davinci-resolve-copilot-infrastructure/gha-creds-d517aae9e66fa904.json
    GOOGLE_GHA_CREDS_PATH: /home/runner/work/davinci-resolve-copilot-infrastructure/davinci-resolve-copilot-infrastructure/gha-creds-d517aae9e66fa904.json
    CLOUDSDK_CORE_PROJECT: dr-copilot-staging
    CLOUDSDK_PROJECT: dr-copilot-staging
    GCLOUD_PROJECT: dr-copilot-staging
    GCP_PROJECT: dr-copilot-staging
    GOOGLE_CLOUD_PROJECT: dr-copilot-staging
    TERRAFORM_CLI_PATH: /home/runner/work/_temp/179aac4f-aa0d-44b[2](https://github.com/yenlincc/davinci-resolve-copilot-infrastructure/actions/runs/14744935531/job/41390375807?pr=5#step:10:2)-b069-4a7b0416612[4](https://github.com/yenlincc/davinci-resolve-copilot-infrastructure/actions/runs/14744935531/job/41390375807?pr=5#step:10:4)
Render plan
d token 'c', "[command]/h"... is not valid JSON

Likely to be something I'm doing wrong. Could you help me understand the error?

Thanks!

hencrice avatar Apr 30 '25 01:04 hencrice

I have never seen this error, unfortunately. Could you, for debugging, add a step which runs terraform show -json plan.out and post the output here (redacting anything important, of course)?

borchero avatar May 02 '25 23:05 borchero

🤖 Stalebot

This issue hasn't seen updates in the last 60 days.

If it has been resolved or is not relevant anymore, please consider closing the issue. Otherwise, it will be closed automatically in 30 days.

github-actions[bot] avatar Jul 02 '25 06:07 github-actions[bot]

i'm getting the same error. i cannot share my plan output. total output length, formatted, is approx 4k lines, and it's valid JSON.

cleaned up debug output for this step:

##[debug]Evaluating condition for step: 'Post PR comment'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Post PR comment
##[debug]Loading inputs
##[debug]Evaluating: github.token
##[debug]Evaluating Index:
##[debug]..Evaluating github:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'token'
##[debug]=> '***'
##[debug]Result: '***'
##[debug]Loading env
Run borchero/terraform-plan-comment@v2
  with:
    token: ***
    planfile: .planfile
    terraform-cmd: terraform
    working-directory: .
    header: 📝 Terraform Plan
    skip-empty: false
    skip-comment: false
  env:
    TERRAFORM_CLI_PATH: /path/to/gha-runner/_work/_temp/68ef8bb5-4b15-5256-9538-cacd84bfba41
::group::Render plan
Render plan
  ::endgroup::
d token 'c', "[command]/c"... is not valid JSON
##[debug]Node Action run completed with exit code 1
##[debug]Finishing: Post PR comment

bwhitehead0 avatar Aug 07 '25 22:08 bwhitehead0

ok - i realized i was using an old hashicorp/setup-terraform (@v1, in fact). updating to v3 seems to have resolved.

@hencrice you want to try using the current version action and see what happens?

bwhitehead0 avatar Aug 13 '25 19:08 bwhitehead0

I hit this exact same issue and updating from hashicorp/setup-terraform@v1 to hashicorp/setup-terraform@v3 fixed it.

Piccirello avatar Sep 08 '25 20:09 Piccirello

🤖 Stalebot

This issue hasn't seen updates in the last 60 days.

If it has been resolved or is not relevant anymore, please consider closing the issue. Otherwise, it will be closed automatically in 30 days.

github-actions[bot] avatar Nov 08 '25 06:11 github-actions[bot]

Since setup-terraform@v3 seems to fix this, I'm closing the issue :)

borchero avatar Nov 15 '25 22:11 borchero