Skip to content

Commit

Permalink
Merge pull request #76 from angulo-solido:72-create-flag-when-env-select
Browse files Browse the repository at this point in the history
terrabutler: tf.py: Fix terraform_init_all_sites()
  • Loading branch information
MiguelNdeCarvalho authored Jul 13, 2022
2 parents a24ed52 + 3d3b4af commit 1260fbe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions terrabutler/click.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ def env_new_cli(name, y, t, a, s3):

@env_cli.command(name="select", help="Select a environment")
@click.argument('NAME')
@click.option("-init", default=True,
help="Disable auto init of the sites")
@click.option("-s3", is_flag=True,
help="Access S3 instead of parsing terraform output")
def env_select_cli(name, s3):
set_current_env(name, s3)
def env_select_cli(name, init, s3):
set_current_env(name, s3, init=init)


@env_cli.command(name="show", help="Show the name of the current environment")
Expand Down
5 changes: 3 additions & 2 deletions terrabutler/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_current_env():
return f.read()


def set_current_env(env, s3):
def set_current_env(env, s3, init=False):
current_env = get_current_env()
available_envs = get_available_envs(s3)

Expand All @@ -117,7 +117,8 @@ def set_current_env(env, s3):
exit(1)

reload_direnv()
terraform_init_all_sites()
if init:
terraform_init_all_sites()
print("\n\n" + Fore.GREEN + f"Switched to environment '{env}'.")


Expand Down
3 changes: 2 additions & 1 deletion terrabutler/tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,5 @@ def terraform_init_all_sites():
sites.remove("inception")
for site in sites:
print(Fore.YELLOW + f"Initializing {site} site")
terraform_command_runner("init", ["-reconfigure"], "backend", site)
terraform_command_runner("init", site, options=["-reconfigure"],
needed_options="backend")

0 comments on commit 1260fbe

Please sign in to comment.