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

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

tfparse-0.5.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.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

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

Uploaded CPython 3.11 macOS 11.0+ ARM64

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

Uploaded CPython 3.11 macOS 10.9+ x86-64

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

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

tfparse-0.5.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.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

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

Uploaded CPython 3.10 macOS 11.0+ ARM64

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

Uploaded CPython 3.10 macOS 10.9+ x86-64

File details

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

File metadata

File hashes

Hashes for tfparse-0.5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d5ef0a5c1bb5f0bae6e2be4d0715e5a3e62488bc55479c12c2b314b6a0c4f231
MD5 b85788574e009afd7bd67d1f101f0c4f
BLAKE2b-256 333287210d8ec98cddea6e91ab049d3bfddfe3b9ed03769a2a027f09211af006

See more details on using hashes here.

File details

Details for the file tfparse-0.5.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.5.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 84ae6e466c20190ce8b5ee6198504f247b0ea881f5564bbd9704830fc91f5081
MD5 be7a08e539b54865864b822b897c57ff
BLAKE2b-256 b7ba633e667199c6ef780b59ce288a5f044da5c154768b7b440cee037ffa84a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.5.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f80025ba6b7202f98f4d3f799766b1daa400bc68a7e512f6e66077561ca4fb95
MD5 2b81455b3c251d0a91759b331a5ec67d
BLAKE2b-256 78de477a103573301f205dcd8ec5145ebba603136b06dc0cae8a9e61a3e1f30f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.5.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ca8b92e064739fb9fcbd026bed0cba0150338792dafc49081b1a84596c55d4cb
MD5 82bd7f9cd62fa345e3c781a1642bef4d
BLAKE2b-256 45a5a6af3e1dd9750849a62e09f82e6dd6ce330694bbc6f500defd02e8fde1d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b46875dc7da35ae2e086343bf573a599e45224f10cbc409dfac422e2c2e2c71d
MD5 81b566542ed6c10c29dd4da149515e91
BLAKE2b-256 538f6d43bff1c94986252918f571cf40081dbb2d36c4a0eebbf9f9adcb61cdf3

See more details on using hashes here.

File details

Details for the file tfparse-0.5.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.5.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 80a4f93f95457887a30cab180dc5c0aa3144f29bd1933ea31313c74c8f8b6891
MD5 aa0a674bf04c913ac4cc1b679e9a28af
BLAKE2b-256 a5b2f920f3649e49e8fa732169ca05d4f09d95a23a153bacc6466ce16d1ccaf1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.5.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 754ba5bd7a7c7aa75ca9653a3de39c580f7fcf195f7912a26337d2fc9edd96f8
MD5 c7fc1d664e26aa03935a2469a62eb740
BLAKE2b-256 8b4f82d9b0b3874d846760b31f4e00244a09a4c1f113cbfa284d4be7d6c80981

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tfparse-0.5.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b38f9942bfd84a939dbc8ed9ca455bce8877cebe352dd55b10053aa577fc26d4
MD5 a77d7762c268a83eb3784c29c4b8b83f
BLAKE2b-256 b9d990a5188aa36a577d7e040abd021edd54893ab59a4127cd138adb9ec68e93

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