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.3.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.3.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py2terraform-0.3.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.3.0.tar.gz
Algorithm Hash digest
SHA256 2a76678bbd5d206c721287729d14776f3ca0c01bcba562045e29d838a2be0a6c
MD5 2511b82110fab3f4f8862e3533513bf6
BLAKE2b-256 ebcc9959fd75f8d2d1704ce09dd3f76478a5a2bc30f86f755d54c70d31ed9677

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py2terraform-0.3.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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ef456e8dba87588d1bd89e45c4cb363d7fac8df33e22f6a11c0be00e428d4af
MD5 981df088870a460b0bed111e6e124135
BLAKE2b-256 accb5a8c9c4de9e0f3764a68fa190f68e154923a6a12001daa12bc588482dbfd

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