Merge pull request #52 from beelit94/release/0.10.1

release/0.10.1
This commit is contained in:
beelit94 2019-06-20 23:43:10 -07:00 committed by GitHub
commit 76351ba371
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 85 additions and 7 deletions

View file

@ -1,5 +1,5 @@
[bumpversion] [bumpversion]
current_version = 0.10.0 current_version = 0.10.1
commit = True commit = True
tag = False tag = False

View file

@ -3,14 +3,17 @@
1. [#10] log handler error on Linux environment 1. [#10] log handler error on Linux environment
1. [#11] Fix reading state file for remote state and support backend config for 1. [#11] Fix reading state file for remote state and support backend config for
init command init command
## [0.9.0] ## [0.9.0]
### Fixed
1. [#12] Output function doesn't accept parameter 'module' 1. [#12] Output function doesn't accept parameter 'module'
1. [#16] Handle empty space/special characters when passing string to command line options 1. [#16] Handle empty space/special characters when passing string to command line options
1. Tested with terraform 0.10.0 1. Tested with terraform 0.10.0
## [0.10.0] ## [0.10.0]
### Fixed
1. [#27] No interaction for apply function 1. [#27] No interaction for apply function
1. [#18] Return access to the subprocess so output can be handled as desired 1. [#18] Return access to the subprocess so output can be handled as desired
1. [#24] Full support for output(); support for raise_on_error 1. [#24] Full support for output(); support for raise_on_error
## [0.10.1]
1. [#48] adding extension for temp file to adopt the change in terraform 0.12.0
1. [#49] add workspace support

0
CONTRIBUTING.md Normal file
View file

View file

@ -49,7 +49,8 @@ class Terraform(object):
parallelism=None, parallelism=None,
var_file=None, var_file=None,
terraform_bin_path=None, terraform_bin_path=None,
is_env_vars_included=True): is_env_vars_included=True,
):
""" """
:param working_dir: the folder of the working folder, if not given, :param working_dir: the folder of the working folder, if not given,
will be current working folder will be current working folder
@ -387,6 +388,41 @@ class Terraform(object):
self.tfstate = Tfstate.load_file(file_path) self.tfstate = Tfstate.load_file(file_path)
def set_workspace(self, workspace):
"""
set workspace
:param workspace: the desired workspace.
:return: status
"""
return self.cmd('workspace' ,'select', workspace)
def create_workspace(self, workspace):
"""
create workspace
:param workspace: the desired workspace.
:return: status
"""
return self.cmd('workspace', 'new', workspace)
def delete_workspace(self, workspace):
"""
delete workspace
:param workspace: the desired workspace.
:return: status
"""
return self.cmd('workspace', 'delete', workspace)
def show_workspace(self):
"""
show workspace
:return: workspace
"""
return self.cmd('workspace', 'show')
def __exit__(self, exc_type, exc_value, traceback): def __exit__(self, exc_type, exc_value, traceback):
self.temp_var_files.clean_up() self.temp_var_files.clean_up()
@ -396,7 +432,7 @@ class VariableFiles(object):
self.files = [] self.files = []
def create(self, variables): def create(self, variables):
with tempfile.NamedTemporaryFile('w+t', delete=False) as temp: with tempfile.NamedTemporaryFile('w+t', suffix='.tfvars.json', delete=False) as temp:
log.debug('{0} is created'.format(temp.name)) log.debug('{0} is created'.format(temp.name))
self.files.append(temp) self.files.append(temp)
log.debug( log.debug(

View file

@ -20,7 +20,7 @@ except IOError:
setup( setup(
name=module_name, name=module_name,
version='0.10.0', version='0.10.1',
url='https://github.com/beelit94/python-terraform', url='https://github.com/beelit94/python-terraform',
license='MIT', license='MIT',
author='Freddy Tan', author='Freddy Tan',

View file

@ -320,3 +320,42 @@ class TestTerraform(object):
tf = Terraform(working_dir=current_path) tf = Terraform(working_dir=current_path)
tf.import_cmd('aws_instance.foo', 'i-abc1234', no_color=IsFlagged) tf.import_cmd('aws_instance.foo', 'i-abc1234', no_color=IsFlagged)
assert 'command: terraform import -no-color aws_instance.foo i-abc1234' in string_logger() assert 'command: terraform import -no-color aws_instance.foo i-abc1234' in string_logger()
def test_create_workspace(self):
tf = Terraform(working_dir=current_path)
tf.init()
ret, out, err = tf.create_workspace('test')
tf.set_workspace('default')
tf.delete_workspace('test')
assert ret == 0
assert err == ''
def test_set_workspace(self):
tf = Terraform(working_dir=current_path)
tf.init()
tf.create_workspace('test')
tf.set_workspace('test')
tf.set_workspace('default')
ret, out, err = tf.delete_workspace('test')
assert ret == 0
assert err == ''
def test_show_workspace(self):
tf = Terraform(working_dir=current_path)
tf.init()
tf.create_workspace('test')
ret, out, err = tf.show_workspace()
tf.set_workspace('default')
tf.delete_workspace('test')
assert ret == 0
assert err == ''
def test_delete_workspace(self):
tf = Terraform(working_dir=current_path)
tf.init()
tf.create_workspace('test')
tf.set_workspace('default')
ret, out, err = tf.delete_workspace('test')
tf.show_workspace()
assert ret == 0
assert err == ''