commit
76351ba371
6 changed files with 85 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
|||
[bumpversion]
|
||||
current_version = 0.10.0
|
||||
current_version = 0.10.1
|
||||
commit = True
|
||||
tag = False
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
## [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
0
CONTRIBUTING.md
Normal file
|
@ -49,7 +49,8 @@ class Terraform(object):
|
|||
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
|
||||
|
@ -387,6 +388,41 @@ class Terraform(object):
|
|||
|
||||
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()
|
||||
|
||||
|
@ -396,7 +432,7 @@ class VariableFiles(object):
|
|||
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(
|
||||
|
|
2
setup.py
2
setup.py
|
@ -20,7 +20,7 @@ except IOError:
|
|||
|
||||
setup(
|
||||
name=module_name,
|
||||
version='0.10.0',
|
||||
version='0.10.1',
|
||||
url='https://github.com/beelit94/python-terraform',
|
||||
license='MIT',
|
||||
author='Freddy Tan',
|
||||
|
|
|
@ -320,3 +320,42 @@ class TestTerraform(object):
|
|||
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 == ''
|
||||
|
|
Loading…
Reference in a new issue