Skip to content

Commit

Permalink
Merge pull request #52 from beelit94/release/0.10.1
Browse files Browse the repository at this point in the history
release/0.10.1
  • Loading branch information
beelit94 authored Jun 21, 2019
2 parents 813d23d + ce788ac commit 76351ba
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.10.0
current_version = 0.10.1
commit = True
tag = False

Expand Down
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
1. [#10] log handler error on Linux environment
1. [#11] Fix reading state file for remote state and support backend config for
init command

## [0.9.0]
### Fixed
1. [#12] Output function doesn't accept parameter 'module'
1. [#16] Handle empty space/special characters when passing string to command line options
1. Tested with terraform 0.10.0

## [0.10.0]
### Fixed
1. [#27] No interaction for apply function
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
Empty file added CONTRIBUTING.md
Empty file.
40 changes: 38 additions & 2 deletions python_terraform/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def __init__(self, working_dir=None,
parallelism=None,
var_file=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,
will be current working folder
Expand Down Expand Up @@ -387,6 +388,41 @@ def read_state_file(self, file_path=None):

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):
self.temp_var_files.clean_up()

Expand All @@ -396,7 +432,7 @@ def __init__(self):
self.files = []

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))
self.files.append(temp)
log.debug(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

setup(
name=module_name,
version='0.10.0',
version='0.10.1',
url='https://github.com/beelit94/python-terraform',
license='MIT',
author='Freddy Tan',
Expand Down
39 changes: 39 additions & 0 deletions test/test_terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,42 @@ def test_import(self, string_logger):
tf = Terraform(working_dir=current_path)
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()

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 == ''

0 comments on commit 76351ba

Please sign in to comment.