From 52730452c35e0b383c6c31f544755bf7179ea7d7 Mon Sep 17 00:00:00 2001 From: abikouo Date: Fri, 4 Oct 2024 12:54:02 +0200 Subject: [PATCH] create bunch for versions --- plugins/module_utils/ec2.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/ec2.py b/plugins/module_utils/ec2.py index 30fcc084201..5d25d824a9d 100644 --- a/plugins/module_utils/ec2.py +++ b/plugins/module_utils/ec2.py @@ -1282,12 +1282,21 @@ def describe_launch_template_versions(client, **params: Dict[str, Any]) -> List[ def delete_launch_template_versions( client, versions: List[str], launch_template_id: Optional[str] = None, launch_template_name: Optional[str] = None ) -> Dict[str, Any]: - params = {"Versions": versions} + params = {} if launch_template_id: params["LaunchTemplateId"] = launch_template_id if launch_template_name: params["LaunchTemplateName"] = launch_template_name - return client.delete_launch_template_versions(**params) + response = { + "UnsuccessfullyDeletedLaunchTemplateVersions": [], + "SuccessfullyDeletedLaunchTemplateVersions": [], + } + # Using this API, You can specify up to 200 launch template version numbers. + for i in range(0, len(versions), 200): + result = client.delete_launch_template_versions(Versions=list(versions[i : i + 200]), **params) + for x in ("SuccessfullyDeletedLaunchTemplateVersions", "UnsuccessfullyDeletedLaunchTemplateVersions"): + response[x] += result.get(x, []) + return response @EC2LaunchTemplateErrorHandler.common_error_handler("delete launch template")