Python-Terrascript generates Terraform configuration in JSON from Python scripts. It adds Python control flow, functions, and libraries when defining infrastructure.
Overview
Python-Terrascript is a Python package that emits Terraform configuration files in JSON format. Authors write infrastructure in Python instead of hand-editing HCL, which allows if/else, loops, exceptions, richer string handling, and reuse through Python functions.
The package can draw on the Python standard library and third-party packages while building configs. A PROVIDERS.md file lists supported Terraform providers for generated output.
Install from PyPI with pip or from the GitHub tree using setup.py on master or develop branches. Released Terrascript versions align with specific Terraform generations, including lines aimed at Terraform 0.13 namespaces and provider blocks.
Python functions may stand in for Terraform modules in supported workflows. Output targets Terraform's JSON syntax documented by HashiCorp.
Terrascript release lines pair with Terraform 0.11, 0.12, and 0.13 feature sets rather than mixing formats across major Terraform versions.
Key features
- Terraform JSON generation
- Python control structures
- Provider coverage list
- PyPI and source install
- Python functions as modules
- Third-party Python imports
- Version-matched releases
- Registry provider support
Use cases
- Programmatic IaC generation
- Dynamic provider configs
- Large Terraform JSON outputs
- Python-native infra templates
- Multi-environment generation