Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

261
Vistas
Extracting terraform resource changes with github-script@v5 action

I have a github workflow where I want to filter the terraform destroy changes from the terraform plan file and post that as comment in the PR.

    - name: Terraform Plan
      id: plan_json
      run: |
        terraform plan -out planfile 2>error.log
        terraform show -json planfile > plan.json
      continue-on-error: true

    - uses: actions/github-script@v5
      id: message
      if: ${{ always() }}
      with:
        result-encoding: string
        script: |
          const fs = require('fs');
          const report = JSON.parse(fs.readFileSync('./plan.json'));

          var message = '';
          for (const changes in report.resource_changes) {
            message += `${changes.change.actions[0]} ${changes.name} (${changes.type})\n`
          };

          console.log('Message: ', message);
          return message;

When I run the workflow it gives this error:

SyntaxError: Unexpected token c in JSON at position 1
    at JSON.parse (<anonymous>)
    at eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:4942:56), <anonymous>:4:21)
    at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:4943:12)
Error: Unhandled error: SyntaxError: Unexpected token c in JSON at position 1
    at main (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:4997:26)
    at Module.272 (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:4981:1)
    at __webpack_require__ (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:24:31)
    at startup (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:43:19)
    at /home/runner/work/_actions/actions/github-script/v5/dist/index.js:49:18
    at Object.<anonymous> (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:52:10)
    at Module._compile (internal/modules/cjs/loader.js:959:30)

I don't have any nodejs/javascript experience so I have no clue what I am doing wrong here.

The actual plan file can be found here.

When I run the nodejs script locally it works.

❯ node tfplan.js
Message:  create, rg (azurerm_resource_group)
create, rg-name (random_pet)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

    - uses: hashicorp/setup-terraform@v1
      with:
        terraform_wrapper: false

terraform_wrapper: false had to be added to the terraform setup task. For more info check this.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda