Skip to main content

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

Installing from source

Installing will build the module and install the local copy of tfparse in to the current Python environment.

> pip install -e .
> 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.

python setup.py bdist_wheel
ls -l dist/

Running the tests

This project uses pytest

pytest

Testing CI Builds for cross compiling

You can test our cross compiling CI/CD builds by running the following:

CIBW_BUILD=cp310* cibuildwheel --platform macos --archs x86_64

This will try to build an intel wheel on python3.10

Credits

aquasecurity/defsec - golang module for parsing and evaluating terraform hcl

Scalr/pygohcl - python bindings for terraform hcl via golang extension

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

tfparse-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.9 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

tfparse-0.3.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.5 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

tfparse-0.3.0-cp310-cp310-macosx_11_0_arm64.whl (7.0 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

tfparse-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl (7.5 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

File details

Details for the file tfparse-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tfparse-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4aa3e22c53f6e7f89ba611f7f38bd1705517ed8e6ef818fab91f724f50f43fc7
MD5 ca045694575fe707d8bafefaaeab3ac7
BLAKE2b-256 40e50d51ef99714f288fde5df1201ee01b008629e83024f65282bf877f5cfd11

See more details on using hashes here.

File details

Details for the file tfparse-0.3.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tfparse-0.3.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 563570692f8a81b58d7046bef629c6eea01d4aec5e350b895db04ac9e6bc7b7c
MD5 8d7d9d2432fa05af1932f4bc6b539af1
BLAKE2b-256 1bc6ed1e1d3cd129cf41089574f05d3d0bef73170e8a9fb24062d741afb625c0

See more details on using hashes here.

File details

Details for the file tfparse-0.3.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tfparse-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f1dda1d9cbf817d560f67ebd78c61284315ac1f53ef985dd8c1e09ec45e35422
MD5 69c7f855f189e2cda7263fb9dc5f18ad
BLAKE2b-256 b9bc13a3a27f124ed9fa2ea8aab94d4ce0011b9db781199c2e0f7d291225934b

See more details on using hashes here.

File details

Details for the file tfparse-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tfparse-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3f9041b8fde62e4fc078f8b55e2db56337867f3c82109501048b7ed28c8d05de
MD5 423bc9e83c76abdf9aaabb8b057af5d9
BLAKE2b-256 4c2ef15f6dfbb3f9f7b8ad35bfb6eb1989ac408c3f5e8b3b199407d6d4145422

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page