Skip to main content

Python-based Infrastructure as Code (IaC) tool for dynamic infrastructure workflows.

Project description

PHCL

PHCL provides an authoring and generation layer for HCL-based tools such as Terraform, OpenTofu, and Packer.

PHCL does not assume a full project rewrite.
You can keep your existing Terraform/OpenTofu codebase and use PHCL only for a single .tf file that needs to be parameterized or generated from external data.

PHCL code is not an application framework or runtime model. There is no entry point.

PHCL .py files are rendered directly and independently into the corresponding .tf files, so they can be mixed with regular HCL files inside the same project:

src/network.pysrc/network.tf

HCL 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

phcl-0.5.3.tar.gz (26.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

phcl-0.5.3-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

Details for the file phcl-0.5.3.tar.gz.

File metadata

  • Download URL: phcl-0.5.3.tar.gz
  • Upload date:
  • Size: 26.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for phcl-0.5.3.tar.gz
Algorithm Hash digest
SHA256 e560f20b3be031740dae51b610ccd5a3c7aeb3ae7138f8c48b9f66350f554994
MD5 c76f04e171d127e23cb7cf4c8212f03c
BLAKE2b-256 c2fb0e0785f6a3dffc76fe41e8f98ec77284bbe20e4ac77ee20de2ce69ada10a

See more details on using hashes here.

File details

Details for the file phcl-0.5.3-py3-none-any.whl.

File metadata

  • Download URL: phcl-0.5.3-py3-none-any.whl
  • Upload date:
  • Size: 30.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for phcl-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9a5a681136aa2e0ae10a3249bf6a4b67f0df621f95a72a5dedd54afc7dac6157
MD5 cab462cf7973301ce31affd5a4d2f6d1
BLAKE2b-256 10f80cebc475e9a4a8f89876d0cadf72fd566e25e0d93c9dd65de7e8766f0a7a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page