Skip to content

Back-end config file in json throws an error #233

@rsealsovtech

Description

@rsealsovtech

Problem description

Previously I was using a json formatted back-end file. On Friday suddenly terraform plan started throwing errors about not expecting a Left brace. I updated the name of the file to exclude .json and changed the syntax to HCL and it worked.

I did test a plan and apply locally with the same json files and received no syntax errors.

Terraform version

1.3.6

Backend

s3

Workflow YAML

- name: Plan Terraform
        if: ${{ github.event_name == 'pull_request' }}
        uses: dflook/terraform-plan@v1
        with:
          path: infrastructure
          backend_config_file: infrastructure/.s3.tfbackend.json
          var_file: infrastructure/terraform.tfvars.json

Workflow log

Plan: 0 to add, 6 to change, 0 to destroy.
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/lark/parsers/lalr_parser.py", line 59, in get_action
    return states[state][token.type]
KeyError: 'LBRACE'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/terraform/hcl.py", line 16, in try_load
    return hcl2.load(f)
  File "/usr/local/lib/python3.9/dist-packages/hcl2/api.py", line 9, in load
    return loads(file.read())
  File "/usr/local/lib/python3.9/dist-packages/hcl2/api.py", line 18, in loads
    return hcl2.parse(text + "\n")
  File "/usr/local/lib/python3.9/dist-packages/lark/lark.py", line 464, in parse
    return self.parser.parse(text, start=start)
  File "/usr/local/lib/python3.9/dist-packages/lark/parser_frontends.py", line 115, in parse
    return self._parse(token_stream, start)
  File "/usr/local/lib/python3.9/dist-packages/lark/parser_frontends.py", line 63, in _parse
    return self.parser.parse(input, start, *args)
  File "/usr/local/lib/python3.9/dist-packages/lark/parsers/lalr_parser.py", line 35, in parse
    return self.parser.parse(*args)
  File "/usr/local/lib/python3.9/dist-packages/lark/parsers/lalr_parser.py", line 88, in parse
    action, arg = get_action(token)
  File "/usr/local/lib/python3.9/dist-packages/lark/parsers/lalr_parser.py", line 66, in get_action
    raise UnexpectedToken(token, expected, state=state, puppet=puppet)
lark.exceptions.UnexpectedToken: Unexpected token Token('LBRACE', '***') at line 1, column 1.
Expected one of: 
	* __ANON_3
	* __ANON_0
	* __ANON_1
	* __ANON_2
	* $END


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.9/dist-packages/terraform/hcl.py", line 61, in <module>
    try_load(Path(sys.argv[1]))
  File "/usr/local/lib/python3.9/dist-packages/terraform/hcl.py", line 18, in try_load
    debug(e)
  File "/usr/local/lib/python3.9/dist-packages/github_actions/debug.py", line 9, in debug
    for line in msg.splitlines():
AttributeError: 'UnexpectedToken' object has no attribute 'splitlines'
Failed to load backend config file infrastructure/.s3.tfbackend.json

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions