2015-12-31 06:48:26 +00:00
|
|
|
|
## Introduction
|
|
|
|
|
|
|
|
|
|
python-terraform is a python module provide a wrapper of `terraform` command line tool.
|
|
|
|
|
`terraform` is a tool made by Hashicorp, please refer to https://terraform.io/
|
|
|
|
|
|
2016-11-18 09:39:25 +00:00
|
|
|
|
### Status
|
|
|
|
|
[![Build Status](https://travis-ci.org/beelit94/python-terraform.svg?branch=develop)](https://travis-ci.org/beelit94/python-terraform)
|
2015-12-31 06:57:23 +00:00
|
|
|
|
|
|
|
|
|
## Installation
|
2016-11-19 17:11:21 +00:00
|
|
|
|
pip install python-terraform
|
2016-11-19 10:24:33 +00:00
|
|
|
|
|
2016-12-20 10:53:01 +00:00
|
|
|
|
## Implementation
|
|
|
|
|
IMHO, how terraform design boolean options is confusing.
|
|
|
|
|
Take `input=True` and `-no-color` option of `apply` command for example,
|
|
|
|
|
they're all boolean value but with different option type.
|
|
|
|
|
This make api caller don't have a general rule to follow but to do
|
|
|
|
|
a exhaustive method implementation which I don't prefer to.
|
|
|
|
|
Therefore I end-up with using `IsFlagged` or `IsNotFlagged` as value of option
|
|
|
|
|
like `-no-color` and `True/False` value reserved for option like
|
|
|
|
|
|
2016-11-19 10:24:33 +00:00
|
|
|
|
## Usage
|
|
|
|
|
For any terraform command
|
|
|
|
|
|
2016-12-20 10:53:01 +00:00
|
|
|
|
from python_terraform import Terraform
|
|
|
|
|
t = Terraform()
|
|
|
|
|
return_code, stdout, stderr = t.<cmd_name>(*arguments, **options)
|
|
|
|
|
|
|
|
|
|
For any options
|
|
|
|
|
|
|
|
|
|
if there's a dash in the option name, use under line instead of dash,
|
|
|
|
|
ex. -no-color --> no_color
|
|
|
|
|
if it's a simple flag with no value, value should be IsFlagged
|
|
|
|
|
ex. cmd('taint', allow_missing=IsFlagged)
|
|
|
|
|
if it's a boolean value flag like "-refresh=true", assign True or False
|
|
|
|
|
if it's a flag could be used multiple times, assign list to it's value
|
|
|
|
|
if it's a "var" variable flag, assign dictionary to it
|
|
|
|
|
if a value is None, will skip this option
|
2016-11-19 10:24:33 +00:00
|
|
|
|
|
|
|
|
|
## Examples
|
2016-12-20 10:53:01 +00:00
|
|
|
|
### Have a test.tf file under folder "/home/test"
|
|
|
|
|
#### 1. apply with variables a=b, c=d, refresh=false, no color in the output
|
2016-11-19 10:24:33 +00:00
|
|
|
|
In shell:
|
|
|
|
|
|
|
|
|
|
cd /home/test
|
|
|
|
|
terraform apply -var='a=b' -var='c=d' -refresh=false -no-color
|
|
|
|
|
|
|
|
|
|
In python-terraform:
|
|
|
|
|
|
|
|
|
|
from python_terraform import Terraform
|
2016-12-20 10:53:01 +00:00
|
|
|
|
tf = Terraform(working_dir='/home/test')
|
2016-11-24 07:09:16 +00:00
|
|
|
|
tf.apply(no_color=IsFlagged, refresh=False, var={'a':'b', 'c':'d'})
|
2016-12-20 10:53:01 +00:00
|
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
|
|
from python_terraform import Terraform
|
|
|
|
|
tf = Terraform()
|
|
|
|
|
tf.apply('/home/test', no_color=IsFlagged, refresh=False, var={'a':'b', 'c':'d'})
|
|
|
|
|
|
|
|
|
|
#### 2. fmt command, diff=true
|
2016-11-19 10:24:33 +00:00
|
|
|
|
In shell:
|
|
|
|
|
|
|
|
|
|
cd /home/test
|
2016-12-20 10:53:01 +00:00
|
|
|
|
terraform fmt -diff=true
|
2016-11-19 10:24:33 +00:00
|
|
|
|
|
|
|
|
|
In python-terraform:
|
|
|
|
|
|
|
|
|
|
from python_terraform import Terraform
|
|
|
|
|
tf = terraform(working_dir='/home/test')
|
2016-12-20 10:53:01 +00:00
|
|
|
|
tf.fmt(diff=True)
|
2016-11-19 10:24:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|