Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cloud-custodian/tfparse
python extension for terraform hcl parsing
https://github.com/cloud-custodian/tfparse
terraform
Last synced: 5 days ago
JSON representation
python extension for terraform hcl parsing
- Host: GitHub
- URL: https://github.com/cloud-custodian/tfparse
- Owner: cloud-custodian
- License: apache-2.0
- Created: 2022-08-22T17:14:25.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-01T17:59:55.000Z (4 months ago)
- Last Synced: 2024-08-24T17:53:21.227Z (3 months ago)
- Topics: terraform
- Language: Go
- Homepage:
- Size: 303 KB
- Stars: 42
- Watchers: 6
- Forks: 10
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.
```shell
> pip install -e .
> python
>>> from tfparse import load_from_path
>>> parsed = load_from_path('')
>>> print(parsed.keys())
```## Building from source
Building will produce a wheel and a source artifact for distribution or upload to package repositories.
```shell
python setup.py bdist_wheel
ls -l dist/
```## Running the tests
This project uses pytest
```shell
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