Merge pull request #101 from fkrafi/feature/support_list_workspace

Added support for getting list of workspaces
merge-requests/1/head
Kiran Kumar Kotari 2 years ago committed by GitHub
commit 8a3451c54c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -456,6 +456,25 @@ class Terraform:
"""
return self.cmd("workspace", "show", **kwargs)
def list_workspace(self) -> List[str]:
"""List of workspaces
:return: workspaces
:example:
>>> tf = Terraform()
>>> tf.list_workspace()
['default', 'test']
"""
return list(
filter(
lambda workspace: len(workspace) > 0,
map(
lambda workspace: workspace.strip('*').strip(),
(self.cmd("workspace", "list")[1] or '').split()
)
)
)
def __exit__(self, exc_type, exc_value, traceback) -> None:
self.temp_var_files.clean_up()

@ -447,3 +447,9 @@ class TestTerraform:
f"Command: terraform workspace delete -force test {current_path}"
in caplog.messages
)
def test_list_workspace(self):
tf = Terraform(working_dir=current_path)
workspaces = tf.list_workspace()
assert len(workspaces) > 0
assert 'default' in workspaces

Loading…
Cancel
Save