Python-powered structural DSL for authoring native HCL2 configuration.
Project description
PHCL
PHCL is a Python-based Infrastructure as Code (IaC) tool for dynamic infrastructure workflows.
It provides an authoring and generation layer for HCL-based tools such as Terraform, OpenTofu, and Packer.
Declarations are written as Python classes. The source stays close to the shape of HCL while adding composition, dynamic generation, and integration with Python data and logic.
Example
class Logs(Resource["aws_s3_bucket"]):
bucket = "app-logs"
force_destroy = True
tags = {
"Name": "logs",
"ManagedBy": "PHCL",
}
class BucketId(Output):
value = Logs._.id
renders as native HCL:
resource "aws_s3_bucket" "logs" {
bucket = "app-logs"
force_destroy = true
tags = {
Name = "logs"
ManagedBy = "PHCL"
}
}
output "bucket_id" {
value = aws_s3_bucket.logs.id
}
Use Cases
PHCL is useful when HCL is derived from project data rather than written directly: RBAC rules, users, roles, regions, environments, inventories, service definitions, or other source-of-truth records. When used alongside an existing Python project, PHCL can share data, constants, validation, and project logic, adapting generated configuration to the application it belongs to.
For example, repeated declarations can be generated from normal Python data:
BUCKETS = {
"logs": {"bucket": "app-logs"},
"assets": {"bucket": "app-assets"},
}
@generate(BUCKETS)
class Bucket(Resource["aws_s3_bucket"]):
bucket = this.value["bucket"]
tags = {"Name": this.key}
PHCL also fits incremental adoption in existing HCL projects: generate one file, one subtree, or one environment at a time, while the output remains plain HCL that can live next to hand-written configuration.
CLI
Install PHCL:
pip install phcl
Install PHCL with the Terraform dialect:
pip install 'phcl[terraform]'
Build one file or a source tree:
ENV=dev phcl build src --out-dir envs/dev/
Example output:
==> build src
write src/backend.py -> envs/dev/backend.tf
write src/database.py -> envs/dev/database.tf
write src/network.py -> envs/dev/network.tf
write src/security.py -> envs/dev/security.tf
==> done in 0.06s
13 written, 0 skipped, 0 failed
Documentation
Project details
Release history Release notifications | RSS feed
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.5.2.tar.gz.
File metadata
- Download URL: phcl-0.5.2.tar.gz
- Upload date:
- Size: 28.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99b1eed88a4e614d835cd627a8fbee41af508714dfc9a2bb5c3e3802466d6c02
|
|
| MD5 |
b4848085cafe7db3b7b19283d174f3df
|
|
| BLAKE2b-256 |
675a7b9fe067d8a44f610a803cfe2c0d3581238df0b98fb2482d6f5ad308a9cd
|
File details
Details for the file phcl-0.5.2-py3-none-any.whl.
File metadata
- Download URL: phcl-0.5.2-py3-none-any.whl
- Upload date:
- Size: 34.6 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 |
85560760527981ab524bb72cb1ddfe9e9a7a6daa6c4a7ce71ef5295380998514
|
|
| MD5 |
893c4be116dd7fc38b2b0ff6ec3b16db
|
|
| BLAKE2b-256 |
04f71e4570d1d683e23c6775628d8c908244fbe354854e3c5f687446c9f16412
|