Python-powered structural DSL for authoring native HCL2.
Project description
PHCL
PHCL is a Python DSL that compiles to native HCL2 and enables dynamic infrastructure generation.
Core layer for phcl-terraform
Idea
In Terraform, HCL is great for describing infrastructure, but not for generating it dynamically. As complexity grows, configuration turns into a combinatorial explosion and becomes hard to maintain.
It also struggles when infrastructure depends on external data — YAML, JSON, databases, APIs — where data needs to be loaded, transformed, and combined before turning into resources.
PHCL moves generation, composition, and data processing into Python while keeping the output as clean, readable HCL2.
Architecture
This repository contains the PHCL core.
Product-specific layers are expected to live above it in separate packages.
PHCL is split into three parts:
core— declarative modelrender— HCL2 generationcli— compiles source files and writes output
Generation cycle:
- execute a PHCL source file
- collect concrete
Nodesubclasses in the registry - render them as top-level output
- render nested
Block(...)values as part of node bodies
Nodedescendants are the root units of generation- plain
Blockvalues are structural content, not top-level declarations - abstract declarations are skipped
Boundaries:
- Python handles declaration, reuse, generation, and transformation
- HCL remains the output format
- HCL expressions stay native when needed
- product-specific semantics live above the core DSL
See also:
CLI
The CLI supports:
- compile a single Python file into HCL output
- walk a directory and compile each file independently
- emit generated files next to sources, into another directory, or to stdout
- infer output suffix from the source filename, or override it explicitly
This makes PHCL easy to adopt incrementally:
- generate one file beside existing HCL
- generate one subtree into a separate output directory
- generate an entire repository in place
- generate an entire repository into another target tree
See also:
Installation
The package exposes a phcl CLI entrypoint:
pip install .
or:
uv sync
Then:
phcl build test.py --ext .tf
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file phcl-0.1.0.tar.gz.
File metadata
- Download URL: phcl-0.1.0.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
091a355ca8585f51fd97ba864de1ebd36bd897b57601d17301b588d4b8849ca0
|
|
| MD5 |
a38cea427acca21349bf33b099707655
|
|
| BLAKE2b-256 |
fcdb7b717f286ba9349fd423df8980cc3aaac2e94325cef4cfd1553b34da7acd
|
File details
Details for the file phcl-0.1.0-py3-none-any.whl.
File metadata
- Download URL: phcl-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6f8b5598834cbfb6a9d57da716df9af03458e9f08baf5384942c79031e1476b
|
|
| MD5 |
cf0037494c8786969ed444d98a04f94a
|
|
| BLAKE2b-256 |
8d94a3fddde17338c3c7010138122e27c4ce3321d354ef65acd4636613ea0c2f
|