Skip to content

Latest commit

 

History

History
97 lines (73 loc) · 2.95 KB

README_OLD.md

File metadata and controls

97 lines (73 loc) · 2.95 KB

python-terrascript

PyPI license GitHub issues Travis Codecov

Terrascript provides a method of generating Terraform files, while harnessing all the features the Python 3 language provides.

Example

As an example let's translate the following Terraform configuration into terrascript.

provider "aws" {
  access_key = "ACCESS_KEY_HERE"
  secret_key = "SECRET_KEY_HERE"
  region     = "us-east-1"
}

resource "aws_instance" "example" {
  ami           = "ami-2757f631"
  instance_type = "t2.micro"
}

The equivalent terrascript example would look like this.

from terrascript import provider, dump
from terrascript.aws.r import aws_instance

provider('aws', access_key='ACCESS_KEY_HERE',
         secret_key='SECRET_KEY_HERE', region='us-east-1')

aws_instance('example', ami='ami-2757f631', instance_type='t2.micro')

# Print the JSON-style configuration to stdout.
print(dump())

Creating instances of provider and aws_instance will automatically add them to the Terraform configuration. Calling dump() will return the configuration in JSON format.

{
  "provider": {
    "aws": {
      "access_key": "ACCESS_KEY_HERE",
      "region": "us-east-1",
      "secret_key": "SECRET_KEY_HERE"
    }
  },
  "resource": {
    "aws_instance": {
      "example": {
        "ami": "ami-2757f631",
        "instance_type": "t2.micro"
      }
    }
  }
}

IMPORTANT: Terrascript does not perform any error checking whatsoever. It is entirely up to you to ensure that the generated output makes sense to Terraform.

Documentation

Examples

This section lists some more advanced examples.

Status

All Terraform providers (as of 21-Nov-2017) are supported but most haven't seen any testing at all. Please let me know if you run into any problems.

I'd also like to add more examples.

FAQ