Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing of OpenTofu/Terraform files containing provider defined functions fails #6866

Open
matthias-bruhse opened this issue Nov 21, 2024 · 0 comments
Labels

Comments

@matthias-bruhse
Copy link

Describe the issue
Checkov fails to parse .tf files if they contain provider defined functions, introduced in OpenTofu 1.7 and Terraform 1.8. Both OpenTofu and Terraform use the double colon notation, which causes the fail.

Examples

provider::provider_name::function_name()

Exception Trace
Please share the trace for the exception and all relevant output by checkov.
To maximize the understanding, please run checkov with LOG_LEVEL set to debug
as follows:

[MainThread  ] [DEBUG]  failed while parsing file ***/main.tf
Traceback (most recent call last):
File "***/.local/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 126, in feed_token
  action, arg = states[state][token.type]
KeyError: 'COLON'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "***/.local/lib/python3.10/site-packages/checkov/terraform/tf_parser.py", line 731, in load_or_die_quietly
  raw_data = __parse_with_timeout(f)
File "***/.local/lib/python3.10/site-packages/checkov/terraform/tf_parser.py", line 758, in __parse_with_timeout
  raw_data = hcl2.load(f)
File "***/.local/lib/python3.10/site-packages/hcl2/api.py", line 15, in load
  return loads(file.read())
File "***/.local/lib/python3.10/site-packages/hcl2/api.py", line 89, in loads
  return hcl2.parse(text + "\n")
File "***/.local/lib/python3.10/site-packages/hcl2/parser.py", line 50, in parse
  tree = Hcl2.lark_parser.parse(text)
File "***/.local/lib/python3.10/site-packages/lark/lark.py", line 652, in parse
  return self.parser.parse(text, start=start, on_error=on_error)
File "***/.local/lib/python3.10/site-packages/lark/parser_frontends.py", line 101, in parse
  return self.parser.parse(stream, chosen_start, **kw)
File "***/.local/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 41, in parse
  return self.parser.parse(lexer, start)
File "***/.local/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 171, in parse
  return self.parse_from_state(parser_state)
File "***/.local/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 193, in parse_from_state
  raise e
File "***/.local/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 184, in parse_from_state
  state.feed_token(token)
File "***/.local/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 129, in feed_token
  raise UnexpectedToken(token, expected, state=self, interactive_parser=None)
lark.exceptions.UnexpectedToken: Unexpected token Token('COLON', ':') at line 6, column 15.
Expected one of: 
  * __ANON_3
  * PLUS
  * __ANON_6
  * SLASH
  * PERCENT
  * QMARK
  * MORETHAN
  * STAR
  * RPAR
  * __ANON_4
  * __ANON_5
  * _NEW_LINE_OR_COMMENT
  * __ANON_2
  * LESSTHAN
  * MINUS
  * __ANON_9
  * COMMA
  * __ANON_1

Desktop (please complete the following information):

  • OS: Ubuntu 22.04
  • Checkov Version: 3.2.311
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant