Skip to content

Commit

Permalink
Run terraform init before running terraform show (#2734)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelovilla authored Sep 23, 2024
1 parent 5f5e53c commit c28569d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/_nebari/provider/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
6 changes: 5 additions & 1 deletion src/_nebari/stages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion src/_nebari/stages/terraform_state/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c28569d

Please sign in to comment.