From c28569df49cfa0c2735f958d8e04e8aff8a19512 Mon Sep 17 00:00:00 2001 From: Marcelo Villa Date: Mon, 23 Sep 2024 15:22:39 -0500 Subject: [PATCH] Run terraform init before running terraform show (#2734) --- src/_nebari/provider/terraform.py | 6 +++++- src/_nebari/stages/base.py | 6 +++++- src/_nebari/stages/terraform_state/__init__.py | 4 +++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/_nebari/provider/terraform.py b/src/_nebari/provider/terraform.py index 1f5f7c490b..59d88e76dd 100644 --- a/src/_nebari/provider/terraform.py +++ b/src/_nebari/provider/terraform.py @@ -185,7 +185,11 @@ def tfimport(addr, id, directory=None, var_files=None, exist_ok=False): raise e -def show(directory=None) -> dict: +def show(directory=None, terraform_init: bool = True) -> dict: + + if terraform_init: + init(directory) + logger.info(f"terraform show directory={directory}") command = ["show", "-json"] with timer(logger, "terraform show"): diff --git a/src/_nebari/stages/base.py b/src/_nebari/stages/base.py index 1899872eb4..cef1322e95 100644 --- a/src/_nebari/stages/base.py +++ b/src/_nebari/stages/base.py @@ -280,11 +280,15 @@ def set_outputs( @contextlib.contextmanager def deploy( - self, stage_outputs: Dict[str, Dict[str, Any]], disable_prompt: bool = False + self, + stage_outputs: Dict[str, Dict[str, Any]], + disable_prompt: bool = False, + terraform_init: bool = True, ): deploy_config = dict( directory=str(self.output_directory / self.stage_prefix), input_vars=self.input_vars(stage_outputs), + terraform_init=terraform_init, ) state_imports = self.state_imports() if state_imports: diff --git a/src/_nebari/stages/terraform_state/__init__.py b/src/_nebari/stages/terraform_state/__init__.py index dd481dad80..37568be130 100644 --- a/src/_nebari/stages/terraform_state/__init__.py +++ b/src/_nebari/stages/terraform_state/__init__.py @@ -236,7 +236,9 @@ def deploy( ): self.check_immutable_fields() - with super().deploy(stage_outputs, disable_prompt): + # No need to run terraform init here as it's being called when running the + # terraform show command, inside check_immutable_fields + with super().deploy(stage_outputs, disable_prompt, terraform_init=False): env_mapping = {} # DigitalOcean terraform remote state using Spaces Bucket # assumes aws credentials thus we set them to match spaces credentials