Skip to content
Snippets Groups Projects
Commit 3024647d authored by Juraj Paluba's avatar Juraj Paluba
Browse files

fix list stack resources

parent 767de3b4
No related branches found
No related tags found
1 merge request!6fix list stack resources
Pipeline #145991 passed
...@@ -70,6 +70,17 @@ class KypoTerraformClientManager: ...@@ -70,6 +70,17 @@ class KypoTerraformClientManager:
self.init_terraform(stack_dir, stack_name) self.init_terraform(stack_dir, stack_name)
def _pull_terraform_state(self, stack_dir: str) -> None:
"""
Pull Terraform state from remote backend.
:param stack_dir: The path to the stack directory
:return: None
"""
process = subprocess.Popen(['terraform', 'state', 'pull', '>', TERRAFORM_STATE_FILE_NAME],
cwd=stack_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
self.wait_for_process(process)
@staticmethod @staticmethod
def create_directories(dir_path: str) -> None: def create_directories(dir_path: str) -> None:
""" """
...@@ -268,6 +279,7 @@ class KypoTerraformClientManager: ...@@ -268,6 +279,7 @@ class KypoTerraformClientManager:
:return: The list of dictionaries containing resources :return: The list of dictionaries containing resources
""" """
stack_dir = self.get_stack_dir(stack_name) stack_dir = self.get_stack_dir(stack_name)
self._pull_terraform_state(stack_dir)
with open(os.path.join(stack_dir, TERRAFORM_WORKSPACE_PATH.format(stack_name)), 'r')\ with open(os.path.join(stack_dir, TERRAFORM_WORKSPACE_PATH.format(stack_name)), 'r')\
as file: as file:
return list(filter(lambda res: res['mode'] == 'managed', json.load(file)['resources'])) return list(filter(lambda res: res['mode'] == 'managed', json.load(file)['resources']))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment