bridgecrewio / checkov

Prevent cloud misconfigurations and find vulnerabilities during build-time in infrastructure as code, container images and open source packages with Checkov by Bridgecrew.
https://www.checkov.io/
Apache License 2.0
7.16k stars 1.12k forks source link

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

Open matthias-bruhse opened 4 days ago

matthias-bruhse commented 4 days ago

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):