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)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a76678bbd5d206c721287729d14776f3ca0c01bcba562045e29d838a2be0a6c
|
|
| MD5 |
2511b82110fab3f4f8862e3533513bf6
|
|
| BLAKE2b-256 |
ebcc9959fd75f8d2d1704ce09dd3f76478a5a2bc30f86f755d54c70d31ed9677
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ef456e8dba87588d1bd89e45c4cb363d7fac8df33e22f6a11c0be00e428d4af
|
|
| MD5 |
981df088870a460b0bed111e6e124135
|
|
| BLAKE2b-256 |
accb5a8c9c4de9e0f3764a68fa190f68e154923a6a12001daa12bc588482dbfd
|