Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion ecs_composex/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ def main_parser():
parser.add_argument(
"--loglevel", type=str, help="Log level. Defaults to INFO", required=False
)
base_command_parser.add_argument(
"--apply",
dest="apply",
help="Whether to apply the change-set automatically (True/False).",
required=False,
type=bool,
)
base_command_parser.add_argument(
"--cleanup",
dest="cleanup",
help="Whether to cleanup the change-set automatically (True/False).",
required=False,
type=bool,
)
for command in ComposeXSettings.active_commands:
cmd_parsers.add_parser(
name=command["name"],
Expand Down Expand Up @@ -216,7 +230,7 @@ def main():
if settings.deploy:
deploy(settings, root_stack)
elif settings.plan:
plan(settings, root_stack)
plan(settings, root_stack, apply=args.apply, cleanup=args.cleanup)
return 0


Expand Down
18 changes: 13 additions & 5 deletions ecs_composex/common/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,13 @@ def get_change_set_status(client, change_set_name, settings):
return status


def plan(settings, root_stack):
def plan(settings, root_stack, apply=None, cleanup=None):
"""
Function to create a recursive change-set and return diffs
:param ComposeXSettings settings:
:param ComposeXStack root_stack:
:param apply: Optional[bool] - Whether to apply the change-set (True/False). Default is None (prompt user).
:param cleanup: Optional[bool] - Whether to clean up the change-set (True/False). Default is None (prompt user).
:return:
"""
validate_stack_availability(settings, root_stack)
Expand All @@ -408,14 +410,20 @@ def plan(settings, root_stack):
)
status = get_change_set_status(client, change_set_name, settings)
if status:
apply_q = input("Want to apply? [yN]: ")
if apply_q in ["y", "Y", "YES", "Yes", "yes"]:
if apply is None:
apply_q = input("Want to apply? [yN]: ")
apply = apply_q.lower() in ["y", "yes"]

if apply:
client.execute_change_set(
ChangeSetName=change_set_name,
StackName=settings.name,
DisableRollback=settings.disable_rollback,
)
else:
delete_q = input("Cleanup ChangeSet ? [yN]: ")
if delete_q in ["y", "Y", "YES", "Yes", "yes"]:
if cleanup is None:
delete_q = input("Cleanup ChangeSet ? [yN]: ")
cleanup = delete_q.lower() in ["y", "yes"]

if cleanup:
client.delete_stack(StackName=settings.name)
Loading