Skip to main content

PY2Terraform

Prototype/concept for building terraform configs using python.
May be useful for deploying flask/django apps by building the cloud configs also in python.

Usage

Extending

from py2terraform.types import TerraformBlockBase

class AWSProvider(TerraformBlockBase):
    # Define constant values
    _block_category = "provider"
    _block_type     = "aws"

    # Define defaults
    def __post_init__(self):
        self.set_params(region = "us-east-1")
        self.add_child_blocks(
            ...
        )

Examples

Desired Output

provider "aws" {
    region = "us-east-1"
}

resource "aws_instance" "my_instance" {
    ami           = "my-ami"
    instance_type = "t2.micro"

    network_interface {
        network_interface_id = "my-interface-id"
        device_index         = 0
    }
}

Python Code

import py2terraform

doc = py2terraform.TerraformDocument()

provider = py2terraform.blocks.TerraformProviderBlock(
    block_type  = "aws",
    params      = {
        "region"    : "us-east-1"
    }
)

instance = py2terraform.blocks.TerraformResourceBlock(
    block_type = "aws_instance",
    block_name = "my_instance",
    params     = {
        "ami"           : "my-ami",
        "instance_type" : "t2.micro"
    }
)
instance_network_interface = py2terraform.types.TerraformBlockBase(
    block_category  = "network_interface",
    params          = {
        "network_interface_id"  : "my-interface-id",
        "device_index"          : 0
    }
)

instance.add_child_blocks(instance_network_interface)

doc.add_blocks(
    provider,
    instance
)

print(doc)

Console Output

provider "aws" {
        region  = "us-east-1"
}

resource "aws_instance" "my_instance" {
        ami     = "my-ami"
        instance_type   = "t2.micro"

        network_interface {
                network_interface_id    = "my-interface-id"
                device_index    = 0
        }
}

Metadata

Release files for py2terraform 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py2terraform 0.3.0
File Size Uploaded Provenance
py2terraform-0.3.0.tar.gz 16.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for py2terraform 0.3.0
File Interpreter ABI Platform
py2terraform-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.2 kB

Release files / py2terraform-0.3.0.tar.gz

Download URL py2terraform-0.3.0.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2a76678bbd5d206c721287729d14776f3ca0c01bcba562045e29d838a2be0a6c
BLAKE2b-256 checksum
How to use checksums
ebcc9959fd75f8d2d1704ce09dd3f76478a5a2bc30f86f755d54c70d31ed9677
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / py2terraform-0.3.0-py3-none-any.whl

Download URL py2terraform-0.3.0-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ef456e8dba87588d1bd89e45c4cb363d7fac8df33e22f6a11c0be00e428d4af
BLAKE2b-256 checksum
How to use checksums
accb5a8c9c4de9e0f3764a68fa190f68e154923a6a12001daa12bc588482dbfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Security for py2terraform 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page