Skip to content

Commit

Permalink
Merge pull request #97 from aubustou/develop
Browse files Browse the repository at this point in the history
Support for Terraform 0.14 and Python 3.6+
  • Loading branch information
Spikeophant authored Mar 1, 2021
2 parents a33aebc + edfc33b commit e1ae747
Show file tree
Hide file tree
Showing 19 changed files with 899 additions and 890 deletions.
7 changes: 0 additions & 7 deletions .bumpversion.cfg

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ Icon

# virtualenv
.virtualenv/
venv/


# Intellij
.idea/

# VSCode
.vscode/
pyrightconfig.json
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
default_language_version:
python: python3.6
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0 # v2.1.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-json
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: requirements-txt-fixer
- repo: https://github.com/pycqa/isort
rev: 5.5.2
hooks:
- id: isort
- repo: https://github.com/lovesegfault/beautysh
rev: 6.0.1
hooks:
- id: beautysh
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
34 changes: 5 additions & 29 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
language: python
python:
- '2.7'
- '3.5'
- '3.6'
- '3.7'
- '3.8'
- '3.9'
before_install: sudo apt-get install unzip
before_script:
- export TFVER=0.10.0
- export TFVER=0.13.4
- export TFURL=https://releases.hashicorp.com/terraform/
- TFURL+=$TFVER
- TFURL+="/terraform_"
Expand All @@ -16,37 +17,12 @@ before_script:
- unzip terraform_bin.zip -d tf_bin
install:
- curl https://bootstrap.pypa.io/ez_setup.py -o - | python
- pip install tox-travis
- pip install .
script:
- export PATH=$PATH:$PWD/tf_bin
- tox
- pytest -v
branches:
only:
- master
- develop
- release/**
deploy:
- provider: pypi
distributions: sdist
server: https://testpypi.python.org/pypi
user: beelit94
password:
secure: sWxc+p/gdq3k2WbUGNG2F4TukFNkTkvq6OPaiOvyfgWThYNk6/juRkMd8flmTbh0VGhcjFbpDLeSApb2kFhfiokYJSH1hOOcmXf8xzYH8/+R4DDEiGa5Y/pR9TBvYu4S8eJEfFUFfb1BBpapykj7o43hcaqMExBJIdVJU7aeoEAC1jQeTJh8wWwdJKHy2dNSM+6RVhk3e5+b0LfK7Bk5sU5P+YdEMj79MJU450J4OmZXWzJgvBN5/2QfVa5LrUD00nYuGuiBniz2lVevIHWjUYawUzpPsTa7F0s2WemG9YcV7U8u06xNjY9Ce3CTbxNhc7OIKq+TCkOgR3qZFXVJ8A87G+AT2iQ01VslQ4DJCxnJNTnpqojWnwf6MFL9O8ONioWYO32bhQFKOQ806ASHP4lNMRDKqx8hXtP5In7/r0SARKscv6Bas83rp+FESkKD5vWgkZJG+yx96LlwRLUhSVnVyb/nOJ++zt5RR3BvY2O4p9YAZY3Qt8TQihOdBQKnY3UXsMyNaE25+yvyNWpmyJiePRbTUd+cpLnycnqG9Ll8v6TpFXb6ahFMjlAFfJNQYlREfseClTHSRjZNxfsXGQCsJh6TZAq7jOB5hCk3q41eOUFWARxbyj8j59NBV8fSQrrGJJ9/VZKQeYiQlBB9KpK4PrnH84oeQ8i+VSbVr5w=
on:
branch: release/**
tags: false
condition: $TRAVIS_PYTHON_VERSION = "3.5"
- provider: pypi
distributions: sdist
user: beelit94
password:
secure: QhCiTLrBvw/Uzt3eiLEmvMP3uHnayVCETqEDA+2+Q9vFavqj0CHA76zqYonBFqnh0a3HFCRIVVt+6ynpZ10kpQ3tAObIw+pY39ZPnpAhOjSpFzzMdpIF9Bhv9A93ng2iSESAZPAOwktHzUwjFx0Zvl0lSYD9rutHgttGgdU2CajiUtwTUhCTjOAVdR2Gm+15H808vzKWnMaKflXxZt+fkt279mQTYAtz6eBWtZwIKry/uAJCSrPSWtbi50O0HsWRMXLXWH5Jn/BVjWSDSM92DssUDq0D+tQyp4M5nQXJ9EyAvEdsKNLx3cvNruznh2ohI2jmcoIjwFiS6+wrEmUiXkP86iyzCSqL/EbcOG0xUh3vbfYtMBp7jENgD405+3SEhPY4PlqUmc+HDtB7FUcHz4y7wGWJRGyQzNnjJ6Tv0Ajdz5mfJubWVIvHjcRqkxTVtUKt50o00xZ62M0ZzQkDTIHQEsZly0XeHAgSvNzWkmjt9BiBrZ9OkoWVkRpSrCBy/EcpDNPCTSfSzOQ0Nq1ePFjkkW1n8QWDW9Pdb+/7/P2y9E2S8CT+nXBkRQeQiO86Qf1Ireg7k9TA5VYisVZ6bEXEc9UV0mAojpSsC7zWhVlbAoltN6ZbjKmqy/wqn2QIcJemcSie0JigzKpdw7l8FPT2lCRyTKlYLpRyKXzSkNI=
on:
branch: master
tags: false
condition: $TRAVIS_PYTHON_VERSION = "3.5"
notifications:
email:
recipients:
- [email protected]
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

## [0.10.1]
1. [#48] adding extension for temp file to adopt the change in terraform 0.12.0
1. [#49] add workspace support
1. [#49] add workspace support
2 changes: 1 addition & 1 deletion DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Please see README at github_

.. _github: https://github.com/beelit94/python-terraform/blob/master/README.md
.. _github: https://github.com/beelit94/python-terraform/blob/master/README.md
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
73 changes: 34 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
## Introduction

python-terraform is a python module provide a wrapper of `terraform` command line tool.
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/

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)

### Status
[![Build Status](https://travis-ci.org/beelit94/python-terraform.svg?branch=develop)](https://travis-ci.org/beelit94/python-terraform)
[![Build Status](https://travis-ci.org/aubustou/python-terraform.svg?branch=develop)](https://travis-ci.org/aubustou/python-terraform)

## Installation
pip install python-terraform

## Usage
#### For any terraform command

Expand All @@ -29,44 +32,44 @@ or just call cmd method directly
from python_terraform import *
t = Terraform()
return_code, stdout, stderr = t.cmd(<cmd_name>, *arguments, **options)

#### For any argument
simply pass the string to arguments of the method, for example,

terraform apply target_dir
terraform apply target_dir
--> <instance>.apply('target_dir')
terraform import aws_instance.foo i-abcd1234
terraform import aws_instance.foo i-abcd1234
--> <instance>.import('aws_instance.foo', 'i-abcd1234')

#### For any options

* dash to underscore

remove first dash, and then use underscore to replace dash symbol as option name

ex. -no-color --> no_color

* for a simple flag option

use ```IsFlagged/None``` as value for raising/not raising flag, for example,
terraform taint -allow-missing
use ```IsFlagged/None``` as value for raising/not raising flag, for example,

terraform taint -allow-missing
--> <instance>.taint(allow_missing=IsFlagged)
terraform taint
terraform taint
--> <instance>.taint(allow_missing=None) or <instance>.taint()
terraform apply -no-color
--> <instance>.apply(no_color=IsFlagged)

* for a boolean value option

assign True or False, for example,

terraform apply -refresh=true --> <instance>.apply(refresh=True)

* if a flag could be used multiple times, assign a list to it's value

terraform apply -target=aws_instance.foo[1] -target=aws_instance.foo[2]
--->
--->
<instance>.apply(target=['aws_instance.foo[1]', 'aws_instance.foo[2]'])
* for the "var" flag, assign dictionary to it

Expand All @@ -84,19 +87,19 @@ By default, stdout and stderr are captured and returned. This causes the applica
return_code, stdout, stderr = t.<cmd_name>(capture_output=False)

## Examples
### Have a test.tf file under folder "/home/test"
### Have a test.tf file under folder "/home/test"
#### 1. 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 *
tf = Terraform(working_dir='/home/test')
tf.apply(no_color=IsFlagged, refresh=False, var={'a':'b', 'c':'d'})

or

from python_terraform import *
Expand All @@ -108,40 +111,32 @@ or
from python_terraform import *
tf = Terraform(working_dir='/home/test', variables={'a':'b', 'c':'d'})
tf.apply(no_color=IsFlagged, refresh=False)

#### 2. fmt command, diff=true
In shell:

cd /home/test
terraform fmt -diff=true
terraform fmt -diff=true

In python-terraform:

from python_terraform import *
tf = terraform(working_dir='/home/test')
tf.fmt(diff=True)


## 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

1. ```input=False```, in this case process won't hang because you missing a variable
1. ```no_color=IsFlagged```, in this case, stdout of result is easier for parsing

## Implementation
IMHO, how terraform design boolean options is confusing.
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
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
Therefore I end-up with using `IsFlagged` or `IsNotFlagged` as value of option
like `-no-color` and `True/False` value reserved for option like `refresh=true`








Loading

0 comments on commit e1ae747

Please sign in to comment.