Skip to content

Commit eb2f34a

Browse files
raffidahmadsuika
andauthored
Adding optional parameters 'apply' and 'cleanup' for the 'plan for automation. (#783)
Useful for CI/CD pipelines. Co-authored-by: suika <[email protected]>
1 parent b41b228 commit eb2f34a

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

ecs_composex/cli.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ def main_parser():
153153
parser.add_argument(
154154
"--loglevel", type=str, help="Log level. Defaults to INFO", required=False
155155
)
156+
base_command_parser.add_argument(
157+
"--apply",
158+
dest="apply",
159+
help="Whether to apply the change-set automatically (True/False).",
160+
required=False,
161+
type=bool,
162+
)
163+
base_command_parser.add_argument(
164+
"--cleanup",
165+
dest="cleanup",
166+
help="Whether to cleanup the change-set automatically (True/False).",
167+
required=False,
168+
type=bool,
169+
)
156170
for command in ComposeXSettings.active_commands:
157171
cmd_parsers.add_parser(
158172
name=command["name"],
@@ -216,7 +230,7 @@ def main():
216230
if settings.deploy:
217231
deploy(settings, root_stack)
218232
elif settings.plan:
219-
plan(settings, root_stack)
233+
plan(settings, root_stack, apply=args.apply, cleanup=args.cleanup)
220234
return 0
221235

222236

ecs_composex/common/aws.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,13 @@ def get_change_set_status(client, change_set_name, settings):
381381
return status
382382

383383

384-
def plan(settings, root_stack):
384+
def plan(settings, root_stack, apply=None, cleanup=None):
385385
"""
386386
Function to create a recursive change-set and return diffs
387387
:param ComposeXSettings settings:
388388
:param ComposeXStack root_stack:
389+
:param apply: Optional[bool] - Whether to apply the change-set (True/False). Default is None (prompt user).
390+
:param cleanup: Optional[bool] - Whether to clean up the change-set (True/False). Default is None (prompt user).
389391
:return:
390392
"""
391393
validate_stack_availability(settings, root_stack)
@@ -408,14 +410,20 @@ def plan(settings, root_stack):
408410
)
409411
status = get_change_set_status(client, change_set_name, settings)
410412
if status:
411-
apply_q = input("Want to apply? [yN]: ")
412-
if apply_q in ["y", "Y", "YES", "Yes", "yes"]:
413+
if apply is None:
414+
apply_q = input("Want to apply? [yN]: ")
415+
apply = apply_q.lower() in ["y", "yes"]
416+
417+
if apply:
413418
client.execute_change_set(
414419
ChangeSetName=change_set_name,
415420
StackName=settings.name,
416421
DisableRollback=settings.disable_rollback,
417422
)
418423
else:
419-
delete_q = input("Cleanup ChangeSet ? [yN]: ")
420-
if delete_q in ["y", "Y", "YES", "Yes", "yes"]:
424+
if cleanup is None:
425+
delete_q = input("Cleanup ChangeSet ? [yN]: ")
426+
cleanup = delete_q.lower() in ["y", "yes"]
427+
428+
if cleanup:
421429
client.delete_stack(StackName=settings.name)

0 commit comments

Comments
 (0)