Mix embedded modules with your own Terraform modules.
What it does
- Uses the embedded catalog by default.
- Supports a custom modules root (
--modulesor profile defaults) but custom git sources now make that optional. source: customon a module forces lookup in your custom root; others fall back to embedded.pltf module initinspects a TF module and writesmodule.yamlmetadata.- Inventory commands:
pltf module list|get -o table|json|yaml.
Example
Notes
- Custom and embedded modules can coexist in the same spec.
- Module metadata (
module.yaml) drives inputs/outputs and wiring; keep it committed. - See
docs/features/terraform-generator.mdfor bringing existing Terraform roots and per‑env workspace copies.
Adding a custom module to the inventory
-
Point at your module
Runpltf module init --path ./path/to/moduleto scan the Terraform code, detect inputs/outputs, and emitmodule.yamlinside the module directory. This metadata tells pltf how to wire and validate the module when it’s referenced. -
Review and edit
module.yaml
Confirm the generatedinputs,outputs,labels, andrequired_providers. If the module targets a non-default provider (GCP, GitHub, etc.) add it there so pltf knows which provider block to create later. -
Register the module in your spec
Add the module entry to your Environment or Service spec:
modules:
- id: my-app
type: my_custom_service
source: custom
inputs:
config_bucket: module.base.bucket
When source: custom is set, pltf looks under the --modules root instead of the embedded catalog.
-
Wire providers/variables
If the module declares provider requirements, make sure the consuming spec enables and configures that provider (providers:block plus secrets/vars such asgithub_tokenorproject_id). -
Commit the metadata
Keep the generatedmodule.yamlin version control so every run can resolve the module contract consistently.
Using existing Terraform roots
- Move the Terraform root into a module folder under your custom root.
- Run
pltf module init --path <module>to generatemodule.yaml. - Reference it as
type: <module_type>in your spec and marksource: custom.
This lets you reuse existing Terraform code while pltf handles wiring/validation (variables, providers, outputs).
Per-environment workspace copies
- A separate workspace exists per env/service (
.pltf/<environment_name>/workspaceor.pltf/<environment_name>/<service_name>/workspace). - Module inputs that refer to file paths (relative to the spec) are copied into the workspace and rewritten, keeping per-env overrides isolated.
Suggested layout
.
├─ env.yaml
├─ service.yaml
├─ modules/
│ ├─ my_network/
│ └─ my_cluster/
└─ files/
├─ dev/
└─ prod/
Use file inputs like ./files/dev/config.json; pltf copies them into the generated workspace for the selected env.
Direct Git sources
Each module entry can point directly at a git repo when source is an HTTP or SSH URL (e.g., https://github.com/org/module.git//module-id?ref=main). The module metadata (module.yaml) inside the repo defines the module type, and pltf will clone that repo and resolve the module without a shared modules_root. Ensure the repo includes module.yaml (generate it with pltf module init --path ... if needed).
Suggested workflow
- Place custom modules under a shared root and run
pltf module init --path ...for each. - (Optional) Point
pltf generate/terraform planat that root with--modulesor profile defaults when you have a shared catalog; otherwise, each module can now specify its own git source URL. - Reference modules with
source: customand include any extra provider blocks required by the module (e.g., GitHub, database, or SaaS providers).