bc-python-hcl2 is a Python library that provides a parser for HashiCorp Configuration Language 2 (HCL2). It is written in Python using Lark and can be used to parse any HCL2 configuration file, such as Terraform files. This package, currently at version 0.4.3, is a fork of the original `python-hcl2` by Amplify and is officially supported by Bridgecrew. The two projects are diverging, so it's important to be aware of which specific package is being used.
pip install bc-python-hcl2Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse HCL2 content from a file into a Python dictionary using `hcl2.load()`.
Explicitly install `bc-python-hcl2` if you intend to use the Bridgecrew-maintained fork, and consult its specific documentation for API nuances. If your project relies on the Amplify Education version, install `python-hcl2`.
Ensure that all HCL configuration files you intend to parse adhere strictly to the HCL2 specification. For HCL v1, a different parser would be required.
Refer to the latest documentation for `hcl2.dumps()`, `hcl2.dump()`, and `hcl2.Builder()` to leverage HCL2 writing capabilities.
Ensure `bc-python-hcl2` is installed in your active environment using `pip install bc-python-hcl2`. If you have `python-hcl2` also installed, consider uninstalling it or using a dedicated virtual environment.
Ensure you have the correct and most up-to-date `bc-python-hcl2` installed (`pip install --upgrade bc-python-hcl2`). If `python-hcl2` is also installed, remove it to prevent conflicts (`pip uninstall python-hcl2`). Using a dedicated virtual environment is highly recommended.
Review the HCL2 file for syntax errors, especially around conditional statements, string interpolations, or unusual HCL2 constructs. Simplify complex HCL2 expressions if possible, or report the specific HCL2 snippet as an issue to the `bc-python-hcl2` repository if it seems to be a parser limitation.