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) and Windows.

Note on Windows we currently don't free memory allocated on parse results.

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.8-cp312-cp312-win_amd64.whl (8.6 MB view hashes)

Uploaded CPython 3.12 Windows x86-64

tfparse-0.6.8-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.2 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

tfparse-0.6.8-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.9 MB view hashes)

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

tfparse-0.6.8-cp312-cp312-macosx_11_0_arm64.whl (8.0 MB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

tfparse-0.6.8-cp312-cp312-macosx_10_9_x86_64.whl (8.4 MB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

tfparse-0.6.8-cp311-cp311-win_amd64.whl (8.6 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

tfparse-0.6.8-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

tfparse-0.6.8-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.9 MB view hashes)

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

tfparse-0.6.8-cp311-cp311-macosx_11_0_arm64.whl (8.0 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

tfparse-0.6.8-cp311-cp311-macosx_10_9_x86_64.whl (8.4 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

tfparse-0.6.8-cp310-cp310-win_amd64.whl (8.6 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

tfparse-0.6.8-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

tfparse-0.6.8-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.9 MB view hashes)

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

tfparse-0.6.8-cp310-cp310-macosx_11_0_arm64.whl (8.0 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

tfparse-0.6.8-cp310-cp310-macosx_10_9_x86_64.whl (8.4 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

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