Skip to main content

No project description provided

Project description

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
        }
}

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

py2terraform-0.0.0.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

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

py2terraform-0.0.0.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file py2terraform-0.0.0.0.tar.gz.

File metadata

  • Download URL: py2terraform-0.0.0.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for py2terraform-0.0.0.0.tar.gz
Algorithm Hash digest
SHA256 9c129e8a180dc7100bc177fb230143b0fe49a07dd8ccb70388df30bffc561412
MD5 065528a7baebc018a38fbe325b124e0e
BLAKE2b-256 c4bc1b71a6c988a55f22506c3473b0e1ee0fa38d74985688c43677271f0fdab7

See more details on using hashes here.

File details

Details for the file py2terraform-0.0.0.0-py3-none-any.whl.

File metadata

  • Download URL: py2terraform-0.0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for py2terraform-0.0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a161fd4e7d1bf9281a84da3daba8ce91b9b067cb2908680b5138d8bd4539aa17
MD5 6c3bc584c1472a7be140edf64656cff5
BLAKE2b-256 0aa73a02d675335ce5d5f0ef220e55e0187f62df0ecc74e95030e7bfa142e8e1

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