Merge branch 'release/0.8.3'

This commit is contained in:
beelit94 2017-04-20 15:25:54 +08:00
commit 6416bdb068
4 changed files with 73 additions and 53 deletions

View file

@ -1,60 +1,51 @@
language: python language: python
python: python:
- "2.7" - '2.7'
# - "3.2" - '3.5'
# - "3.3" before_install: sudo apt-get install unzip
# - "3.4"
- "3.5"
# - "3.5-dev" # 3.5 development branch
# - "3.6-dev" # 3.6 development branch
# - "nightly" # currently points to 3.7-dev
# command to install dependencies
before_install: 'sudo apt-get install unzip'
before_script: before_script:
- 'export TFVER=0.8.1' - export TFVER=0.8.1
- 'export TFURL=https://releases.hashicorp.com/terraform/' - export TFURL=https://releases.hashicorp.com/terraform/
- 'TFURL+=$TFVER' - TFURL+=$TFVER
- 'TFURL+="/terraform_"' - TFURL+="/terraform_"
- 'TFURL+=$TFVER' - TFURL+=$TFVER
- 'TFURL+="_linux_amd64.zip"' - TFURL+="_linux_amd64.zip"
- 'wget $TFURL -O terraform_bin.zip' - wget $TFURL -O terraform_bin.zip
- 'mkdir tf_bin' - mkdir tf_bin
- 'unzip terraform_bin.zip -d tf_bin' - unzip terraform_bin.zip -d tf_bin
install: install:
- "curl https://bootstrap.pypa.io/ez_setup.py -o - | python" - curl https://bootstrap.pypa.io/ez_setup.py -o - | python
- "pip install tox-travis" - pip install tox-travis
- "pip install ." - pip install .
# command to run tests
script: script:
- "export PATH=$PATH:$PWD/tf_bin" - export PATH=$PATH:$PWD/tf_bin
- tox - tox
branches: branches:
only: only:
- master - master
- develop - develop
- release/** - release/**
deploy: deploy:
# test pypi - provider: pypi
- provider: pypi
distributions: sdist distributions: sdist
server: https://testpypi.python.org/pypi server: https://testpypi.python.org/pypi
user: "beelit94" user: beelit94
password: password:
secure: "sWxc+p/gdq3k2WbUGNG2F4TukFNkTkvq6OPaiOvyfgWThYNk6/juRkMd8flmTbh0VGhcjFbpDLeSApb2kFhfiokYJSH1hOOcmXf8xzYH8/+R4DDEiGa5Y/pR9TBvYu4S8eJEfFUFfb1BBpapykj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RbTUd+cpLnycnqG9Ll8v6TpFXb6ahFMjlAFfJNQYlREfseClTHSRjZNxfsXGQCsJh6TZAq7jOB5hCk3q41eOUFWARxbyj8j59NBV8fSQrrGJJ9/VZKQeYiQlBB9KpK4PrnH84oeQ8i+VSbVr5w=
on: on:
branch: "release/**" branch: release/**
tags: false tags: false
condition: $TRAVIS_PYTHON_VERSION = "3.5" condition: $TRAVIS_PYTHON_VERSION = "3.5"
# production pypi - provider: pypi
- provider: pypi
distributions: sdist distributions: sdist
user: "beelit94" user: beelit94
password: password:
secure: "QhCiTLrBvw/Uzt3eiLEmvMP3uHnayVCETqEDA+2+Q9vFavqj0CHA76zqYonBFqnh0a3HFCRIVVt+6ynpZ10kpQ3tAObIw+pY39ZPnpAhOjSpFzzMdpIF9Bhv9A93ng2iSESAZPAOwktHzUwjFx0Zvl0lSYD9rutHgttGgdU2CajiUtwTUhCTjOAVdR2Gm+15H808vzKWnMaKflXxZt+fkt279mQTYAtz6eBWtZwIKry/uAJCSrPSWtbi50O0HsWRMXLXWH5Jn/BVjWSDSM92DssUDq0D+tQyp4M5nQXJ9EyAvEdsKNLx3cvNruznh2ohI2jmcoIjwFiS6+wrEmUiXkP86iyzCSqL/EbcOG0xUh3vbfYtMBp7jENgD405+3SEhPY4PlqUmc+HDtB7FUcHz4y7wGWJRGyQzNnjJ6Tv0Ajdz5mfJubWVIvHjcRqkxTVtUKt50o00xZ62M0ZzQkDTIHQEsZly0XeHAgSvNzWkmjt9BiBrZ9OkoWVkRpSrCBy/EcpDNPCTSfSzOQ0Nq1ePFjkkW1n8QWDW9Pdb+/7/P2y9E2S8CT+nXBkRQeQiO86Qf1Ireg7k9TA5VYisVZ6bEXEc9UV0mAojpSsC7zWhVlbAoltN6ZbjKmqy/wqn2QIcJemcSie0JigzKpdw7l8FPT2lCRyTKlYLpRyKXzSkNI=" secure: QhCiTLrBvw/Uzt3eiLEmvMP3uHnayVCETqEDA+2+Q9vFavqj0CHA76zqYonBFqnh0a3HFCRIVVt+6ynpZ10kpQ3tAObIw+pY39ZPnpAhOjSpFzzMdpIF9Bhv9A93ng2iSESAZPAOwktHzUwjFx0Zvl0lSYD9rutHgttGgdU2CajiUtwTUhCTjOAVdR2Gm+15H808vzKWnMaKflXxZt+fkt279mQTYAtz6eBWtZwIKry/uAJCSrPSWtbi50O0HsWRMXLXWH5Jn/BVjWSDSM92DssUDq0D+tQyp4M5nQXJ9EyAvEdsKNLx3cvNruznh2ohI2jmcoIjwFiS6+wrEmUiXkP86iyzCSqL/EbcOG0xUh3vbfYtMBp7jENgD405+3SEhPY4PlqUmc+HDtB7FUcHz4y7wGWJRGyQzNnjJ6Tv0Ajdz5mfJubWVIvHjcRqkxTVtUKt50o00xZ62M0ZzQkDTIHQEsZly0XeHAgSvNzWkmjt9BiBrZ9OkoWVkRpSrCBy/EcpDNPCTSfSzOQ0Nq1ePFjkkW1n8QWDW9Pdb+/7/P2y9E2S8CT+nXBkRQeQiO86Qf1Ireg7k9TA5VYisVZ6bEXEc9UV0mAojpSsC7zWhVlbAoltN6ZbjKmqy/wqn2QIcJemcSie0JigzKpdw7l8FPT2lCRyTKlYLpRyKXzSkNI=
on: on:
branch: master branch: master
tags: false tags: false
condition: $TRAVIS_PYTHON_VERSION = "3.5" condition: $TRAVIS_PYTHON_VERSION = "3.5"
notifications:
email:
recipients:
- beelit94@gmail.com

View file

@ -98,6 +98,16 @@ In python-terraform:
tf = terraform(working_dir='/home/test') tf = terraform(working_dir='/home/test')
tf.fmt(diff=True) tf.fmt(diff=True)
# Terraform Output
By default, stdout and stderr are captured and returned. This causes the application to appear to hang. To print terraform output in real time, provide the `capture_output` option with any value other than `None`. This will cause the output of terraform to be printed to the terminal in real time. The value of `stdout` and `stderr` below will be `None`.
from python_terraform import Terraform
t = Terraform()
return_code, stdout, stderr = t.<cmd_name>(capture_output=False)
## default values ## default values
for apply/plan/destroy command, assign with following default value to make for apply/plan/destroy command, assign with following default value to make
caller easier in python caller easier in python

View file

@ -3,6 +3,7 @@
import subprocess import subprocess
import os import os
import sys
import json import json
import logging import logging
import tempfile import tempfile
@ -202,15 +203,27 @@ class Terraform(object):
if it's a flag could be used multiple times, assign list to it's value 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 it's a "var" variable flag, assign dictionary to it
if a value is None, will skip this option if a value is None, will skip this option
if the option 'capture_output' is passed (with any value other than
True), terraform output will be printed to stdout/stderr and
"None" will be returned as out and err.
:return: ret_code, out, err :return: ret_code, out, err
""" """
capture_output = kwargs.pop('capture_output', True)
if capture_output is True:
stderr = subprocess.PIPE
stdout = subprocess.PIPE
else:
stderr = sys.stderr
stdout = sys.stdout
cmd_string = self.generate_cmd_string(cmd, *args, **kwargs) cmd_string = self.generate_cmd_string(cmd, *args, **kwargs)
log.debug('command: {c}'.format(c=cmd_string)) log.debug('command: {c}'.format(c=cmd_string))
working_folder = self.working_dir if self.working_dir else None working_folder = self.working_dir if self.working_dir else None
p = subprocess.Popen(cmd_string, stdout=subprocess.PIPE, p = subprocess.Popen(cmd_string, stdout=stdout,
stderr=subprocess.PIPE, shell=True, stderr=stderr, shell=True,
cwd=working_folder) cwd=working_folder)
out, err = p.communicate() out, err = p.communicate()
ret_code = p.returncode ret_code = p.returncode
@ -222,7 +235,10 @@ class Terraform(object):
log.warn('error: {e}'.format(e=err)) log.warn('error: {e}'.format(e=err))
self.temp_var_files.clean_up() self.temp_var_files.clean_up()
if capture_output is True:
return ret_code, out.decode('utf-8'), err.decode('utf-8') return ret_code, out.decode('utf-8'), err.decode('utf-8')
else:
return ret_code, None, None
def output(self, name): def output(self, name):
""" """

View file

@ -1,7 +1,10 @@
""" """
This is a python module provide a wrapper of terraform command line tool This is a python module provide a wrapper of terraform command line tool
""" """
from setuptools import setup try:
from setuptools import setup
except ImportError:
from distutils.core import setup
dependencies = [] dependencies = []
module_name = 'python-terraform' module_name = 'python-terraform'