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

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

tfparse-0.6.0-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.6.0-cp311-cp311-macosx_11_0_arm64.whl (7.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

tfparse-0.6.0-cp311-cp311-macosx_10_9_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

tfparse-0.6.0-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.6.0-cp310-cp310-macosx_11_0_arm64.whl (7.7 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

tfparse-0.6.0-cp310-cp310-macosx_10_9_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

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

File metadata

File hashes

Hashes for tfparse-0.6.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 76334344523f0fb55198818986c56d81b8ca3cbff623108d3c723b69f56b446a
MD5 c53bfd15e55c89394567e785e450758a
BLAKE2b-256 d91516e8e65ae5b0d806af59bac95309a084779d8898c4831c881d0f291bf978

See more details on using hashes here.

File details

Details for the file tfparse-0.6.0-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.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ad4cb44a84e6a4627d72f03a2e1b928ea0134f257d3eada0381071c0743009fd
MD5 a18ca090a5c998caf96ba9042e647564
BLAKE2b-256 3f36624aaf85d47205ff900850f87e7c6ad7c17bfe7ed6df0079f5579afbb2da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.6.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9a2ce20d93bd0748b2ba7369c30eeb23dede11a30c2a9ae942fb2f1c5656611a
MD5 f5ef8eb60086d75f9d969e31e32cf21c
BLAKE2b-256 758e38524074afbde2c8b9fbb22c2503f68184af8790fdb4774740f147851954

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.6.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0bc299d86cfc81c2a20eb8cd6f4561859228f7f63de9eea8b4f7904f9f25df40
MD5 8889fe8c63ea0bb3140562ebd1ff0e5b
BLAKE2b-256 791327c08674b3fc81ed345061b5cb7f2f9d2df1be40559bf95e45a7ac510f0b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.6.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a1546a1cb5442c9102e276a053da86ff03939a496c49a16f5b4800a6970fca89
MD5 7171ae47bf6ff19d897a1abe3a0cec05
BLAKE2b-256 a9a0b73d6cdee783afb4e13d9e8f044855c265fe241003ee83c9bcd750ec476a

See more details on using hashes here.

File details

Details for the file tfparse-0.6.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.6.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7e300b455a1c66e0ad49dadea5f5a75062d9c34c39a1bfcfcdc20d6fabff488f
MD5 b794b5ecb146bef963150300b45c9c02
BLAKE2b-256 5daab620ceb8014ea14f2288686e3a8428077c1f66648fa353fc662cfb2187f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.6.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d51eacf2a9437b56bb7ef2914f0f78b0038746de6554cc1ce86abc2c9f4f514f
MD5 722d4cb55f30a213cb250aab45fa6531
BLAKE2b-256 9ec9857c4837dfd0a07bd23ebd0b0e4b0049f07330484044a867fd065fdd1c9a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.6.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d0ecf85f9ee0dfc7e5a486c92ac804572aace21180c2f3ffdda53c8664a557cc
MD5 828ea706e8e00248b077479565fbded0
BLAKE2b-256 fb1c28a96bdbed76aa467482d1ec6df076168c620e3544297db38110ac42cb09

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