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
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
For any terraform command
|
|
|
|
|
|
|
|
|
|
def cmd(self, cmd, *args, **kwargs):
|
2016-11-19 10:25:35 +00:00
|
|
|
|
"""
|
|
|
|
|
run a terraform command, if success, will try to read state file
|
|
|
|
|
:param cmd: command and sub-command of terraform, seperated with space
|
|
|
|
|
refer to https://www.terraform.io/docs/commands/index.html
|
|
|
|
|
:param args: arguments of a command
|
|
|
|
|
:param kwargs: any option flag with key value without prefixed dash character
|
|
|
|
|
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, 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
|
|
|
|
|
:return: ret_code, out, err
|
2016-11-19 10:24:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
### Have a test.tf file under folder "/home/test"
|
|
|
|
|
#### apply with variables a=b, c=d, refresh=False, no color in the output
|
|
|
|
|
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
|
|
|
|
|
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-11-19 10:24:33 +00:00
|
|
|
|
#### taint command, allow-missing and no color
|
|
|
|
|
In shell:
|
|
|
|
|
|
|
|
|
|
cd /home/test
|
|
|
|
|
terraform taint -allow-missing -no-color
|
|
|
|
|
|
|
|
|
|
In python-terraform:
|
|
|
|
|
|
|
|
|
|
from python_terraform import Terraform
|
|
|
|
|
tf = terraform(working_dir='/home/test')
|
|
|
|
|
tf.cmd('taint', allow_missing=IsFlagged, no_color=IsFlagged)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|