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

If you're not sure about the file name format, learn more about wheel file names.

tfparse-0.4.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

tfparse-0.4.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.3 MB view details)

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

tfparse-0.4.1-cp311-cp311-macosx_11_0_arm64.whl (7.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

tfparse-0.4.1-cp311-cp311-macosx_10_9_x86_64.whl (8.3 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

tfparse-0.4.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

tfparse-0.4.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.3 MB view details)

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

tfparse-0.4.1-cp310-cp310-macosx_11_0_arm64.whl (7.7 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

tfparse-0.4.1-cp310-cp310-macosx_10_9_x86_64.whl (8.3 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

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

File metadata

File hashes

Hashes for tfparse-0.4.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0c972d5ad521525adc39db4ea5580bdeda43795e9b3229dd39518a25f2c780c5
MD5 fbd20cba509a36bb3b55bb006a04c0f8
BLAKE2b-256 ce8ed905ab035c7ac295b72233aac00c01e61ab01f159f8c5c8d9efc8dee35a7

See more details on using hashes here.

File details

Details for the file tfparse-0.4.1-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.4.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c06e397999049cb5cfee735c22e159c1fb9aab6834a5ba03a27b5f612fefa4f0
MD5 9d1e30ee1b834f272fe2eaa257d0710c
BLAKE2b-256 8d92ad1df54fda902fcc788e42fc603444609e7bc6dfb7956dd93bb6568af55c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.4.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3b2e53be7e568207fcffad99a8a29e399a6254f1dae235fbbfb5f3bffbf6a50c
MD5 b5546f160c0a382821bb76bc3e8ad675
BLAKE2b-256 a3ae4c4c64ede95312e1bfd14901cd1b577a1c700944e470a7a41ac8bef1675a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.4.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cd4505b6aa16b66cbe1f74a81f832f557a522024059683d67b2cb5b7c9a91b15
MD5 ee24f02a42683fc5b5d98acceeee0e0f
BLAKE2b-256 964b851410df64b7220fb901c2daed6011f123506c02276ca4afcf1b0a5886bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.4.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5b5594629334a848f37ccb494c41dc7823b599a2d271acb321c7f76fac9fa11a
MD5 7aafef5804a8568a34630cc16a83cf8d
BLAKE2b-256 355f7e627d35990adf6bab242117b2e2be9496278ecb54c65cd5401e72f08acf

See more details on using hashes here.

File details

Details for the file tfparse-0.4.1-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.4.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d40845652b8a764130d6ba719af9dc24a364ba1859583868ed42ecf2e5e0f8cf
MD5 ff8af520f3be216369af0e4bc2a73a8a
BLAKE2b-256 0c9eee58d3c3bc8ade846387ba60ee7a8f1b5a994dcc52da42406786471e5f73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.4.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b0af5b555a72e8eb833f44e9550d5f6fea937e7896789ef533a956ac9d9ceb90
MD5 943347f20cdb24cd15f61660336c2c25
BLAKE2b-256 ff92bf6fed0e4d9a5b2df67fb02f6044981349a546c7d13ae1d9c17f7d32c96f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.4.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 580bac0dca6bb94e4a69c0c80516a2f2c568826a039754c23b4120ae910c9f61
MD5 daa1595007c6277edba1d7772d8e5e2f
BLAKE2b-256 d2d48b171d02afeddb92da13c5a22a3a53141de3a259bb764c47e5ee56b04d99

See more details on using hashes here.

Supported by

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