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.6.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.1 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

tfparse-0.6.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.8 MB view details)

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

tfparse-0.6.2-cp311-cp311-macosx_11_0_arm64.whl (8.2 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

tfparse-0.6.2-cp311-cp311-macosx_10_9_x86_64.whl (8.8 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

tfparse-0.6.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.1 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

tfparse-0.6.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.8 MB view details)

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

tfparse-0.6.2-cp310-cp310-macosx_11_0_arm64.whl (8.2 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

tfparse-0.6.2-cp310-cp310-macosx_10_9_x86_64.whl (8.8 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

File details

Details for the file tfparse-0.6.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tfparse-0.6.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 687e5d097d0605fd5cd67ac8fbccbdfa88ea8ce0823fa01cc9e609e9d33e810c
MD5 22e45ba1a70df79dc482d48c747f8b00
BLAKE2b-256 ebd822d7481c1fd99f80ad488b41fb8b9da1c9afc39efd02eb4110fc8e285098

See more details on using hashes here.

File details

Details for the file tfparse-0.6.2-cp311-cp311-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.6.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 adccdd5a38c28d410fd557786ca98682c615fff8aa8b3637f698b59cfa9be9a3
MD5 21bd31b56d56636bde6b2510f2ac6897
BLAKE2b-256 868cb2ad1890e1526c806ceda6c59348ac772cf313e560c4ec7819ce6839ba40

See more details on using hashes here.

File details

Details for the file tfparse-0.6.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tfparse-0.6.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ab501687bc56130cd0d9ef3f0d7033de2c1a6cfe7b7174f11237847625e3b416
MD5 4160cfe2218dde2266dfda04dc6ed4d9
BLAKE2b-256 9fa647cf838ebd734f3c8b709ae361d7ee8d9f51636c6e320ec4616da53e68bf

See more details on using hashes here.

File details

Details for the file tfparse-0.6.2-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tfparse-0.6.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 84ac794dcfd1aa520b8b5e08e3e8f33b714663319da14e9bbf011a2b2017f762
MD5 604af7c736d3ac94fa78ee33502c9d00
BLAKE2b-256 73c60be138dfe5fcbb29082a326af1f5ff415d9e6c576585cfb0d034f98356be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.6.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 86c342d746f0a4d9edbe703246cbe48adfccbe1a7284e34848c5cdc7674223fc
MD5 85a2aa615e908ab069877cc063747462
BLAKE2b-256 145e69e45b0411f532975a3d8f2646d0d10146238f14ce336654d55b72a8392d

See more details on using hashes here.

File details

Details for the file tfparse-0.6.2-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.6.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7253aec2a903796ed00149af84e2608198525fa78a4d20ce62ae5945294570d9
MD5 f226c6b580d2f9a1b64d8205960b6a46
BLAKE2b-256 68cff953201da3c6e540c663a5c5b545d08f56d12e4f36ab43cb6b7a12816aac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.6.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 445a4cd168bc096b89b2361c8446c4fe6b7c3c3df84ee4473ab0f2828f1c78dc
MD5 98ed12b00f3956c12e1949a8bb8caa8f
BLAKE2b-256 b471240efd1a2b84534627a5331cd233065e2b1e896655f2b8abebfd833f392c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.6.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f6a551b66394f1f82567ca34aca9bd87ff0a2cb3056f4b37a832c2506b8e7fc3
MD5 ec0ea932eaad2cb729a6681d811eae74
BLAKE2b-256 6902fb334954366ac21a17a41f0f09bb475c96bf8963434049f080bec555043a

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