|
|
|
@ -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(
|
|
|
|
|