Merge pull request #49 from Spikeophant/develop
Adding workspace support
This commit is contained in:
commit
a05fc98e8d
2 changed files with 76 additions and 1 deletions
|
@ -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()
|
||||||
|
|
||||||
|
|
|
@ -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 == ''
|
||||||
|
|
Loading…
Reference in a new issue