question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GH Actions, tftest.TerraformTestError: Error decoding plan output: Expecting value: line 1 column 2 (char 1)

See original GitHub issue

Hi, I’ve been unsuccessful in debugging this error. It appears to emanate from the JSON decoder. However, this only occurs when tests are on a GitHub action. Works without error locally.

Stack

  if not output:
        return self.execute_command('plan', *cmd_args).out
      with tempfile.NamedTemporaryFile() as fp:
        fp.close()
      # for tg we need to specify a temp name that is relative for the output to go into each
      # of the .terragrunt-cache, then plan / show would work, otherwise it overwrites each other!
      temp_file = fp.name if len(
          self._tg_ra()) == 0 else os.path.basename(fp.name)
      cmd_args.append('-out={}'.format(temp_file))
      self.execute_command('plan', *cmd_args)
      result = self.execute_command('show', '-no-color', '-json', temp_file)
      try:
        return self._plan_formatter(result.out)
      except json.JSONDecodeError as e:
>       raise TerraformTestError(
            'Error decoding plan output: {}'.format(e))
E       tftest.TerraformTestError: Error decoding plan output: Expecting value: line 1 column 2 (char 1)

Code

@pytest.fixture(scope='session')
def fixtures_dir():
    return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures')

@pytest.fixture(scope='session')
def terraform_binary():
    return shutil.which('terraform')

@pytest.fixture
def plan(fixtures_dir, terraform_binary):
    tf = tftest.TerraformTest(tfdir=fixtures_dir, binary=terraform_binary, env=envs)
    tf.init()
    return tf.plan(output=True)

GH Action

  terraform-test:
    name: Terraform Unit Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Setup Terraform
        uses: hashicorp/setup-terraform@v2
        with:
          terraform_version: 1.2

      - name: Setup Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.10'

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt

      - name: Test with pytest
        run: python -m pytest test-module-fsx-lustre-monitoring.py

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11

github_iconTop GitHub Comments

0reactions
ludoocommented, Sep 13, 2022

That’s great and thanks for circling back! We should add it to the README!

Read more comments on GitHub >

github_iconTop Results From Across the Web

json.decoder.JSONDecodeError: Expecting value: line 1 ...
Bug description Did a fresh pull from git, tried to run this command python parlai/chat_service/services/browser_chat/run.py --config-path ...
Read more >
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The URL I use for the API call works fine in the browser, but gives this error when done through a curl request....
Read more >
Automate Terraform with GitHub Actions - HashiCorp Developer
In this tutorial, you will set up a complete GitHub Actions workflow to deploy a publicly accessible web server within a Terraform Cloud...
Read more >
Elevate your Terraform Workflow with GitHub Actions
Are you getting started with Terraform GitOps? Here's a practical guide to running Terraform in GitHub Actions.
Read more >
How to use 'terraform output' in a GitHub action - NillsF blog
Recently, I was building a GitHub Actions pipeline, and needed to access ... values from the shell directly, and assign them to variables...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found