Python HCL/Terraform parser via extension for AquaSecurity defsec
Project description
What
A python extension for parsing and evaluating terraform using defsec.
While terraform uses HCL as its configuration format, it requires numerous forms of variable interpolation, function and expression evaluation, which is beyond the typical usage of an hcl parser. To achieve compatiblity with the myriad real world usages of terraform, this library uses the canonical implementation from terraform, along with the interpolation and evaluation from defsec to offer a high level interface to parsing terraform modules.
Installation
pip install tfparse
We currently distribute binaries for MacOS (x86_64, arm64) and Linux (x86_64, aarch64).
Usage
A terraform module root, with terraform init
having been performed to resolve module references.
from tfparse import load_from_path
parsed = load_from_path('path_to_terraform_root')
print(parsed.keys())
Developing
- requires Go >= 1.18
- requires Python >= 3.10
This project uses Poetry for package management, if you do not already have Poetry installed you can do so by running the following command:
curl -sSL https://install.python-poetry.org | python3 -
Installing from source
Installing will build the module and install the local copy of tfparse in to the current Python environment.
poetry install
python
>>> from tfparse import load_from_path
>>> parsed = load_from_path('<path_to_terraform>')
>>> print(parsed.keys())
Building from source
Building will produce a wheel and a source artifact for distribution or upload to package repositories.
poetry build
ls -l dist/
Running the tests
This project uses pytest
poetry run pytest
Credits
aquasecurity/defsec - golang module for parsing and evaluating terraform hcl
Scalr/pygohcl - python bindings for terraform hcl via golang extension
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for tfparse-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux_2_5_x86_64.manylinux1_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4910a4667d5584b9bd9cf21f19c469d5c47d69ad2d92c9c71e09b87d669aed90 |
|
MD5 | 5c8a1dc557586ca3f04b8e893e28e9a6 |
|
BLAKE2b-256 | af4d66f31834ad848d5f45e6fd372cef408143abb39e8a244c192c9b43e9327a |
Hashes for tfparse-0.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48a77f0f72ee95821a2431d4531e38ac0c1175b393b021000c350762257b1027 |
|
MD5 | 05b34fd443d2c0eeda80186212fa53f6 |
|
BLAKE2b-256 | 4e9cd4b8890e8345b21049f93792f3691dde3d7cee0e31cf62283c9f91cfe654 |
Hashes for tfparse-0.2.0-cp310-cp310-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76b3015fc25a39aad2b0363d1c98e03eba38f2621b3f705a045cf219d795102b |
|
MD5 | 9e4e82ab5f43ca785cacdd9f14953cbe |
|
BLAKE2b-256 | a1cae42929cb29e3346a5f8ad81f48a507f897c321ff62f13895ec88e6352dce |
Hashes for tfparse-0.2.0-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ebded6a2543f552a169fb45a4ab6ee6a1b11d4307748d79a1641123d5fdb9ec |
|
MD5 | c946f02217199dc55c46740770d048c0 |
|
BLAKE2b-256 | c7e54bf2e00304618da2c2d3dadcd0961e8f99a0ec6d4613672f40157c63dd27 |