1+ import logging
12from datetime import datetime
2- from typing import ClassVar , Dict , Optional , List , Type , Any
3+ from typing import ClassVar , Dict , Optional , List , Type , Any , cast
34
45from attrs import define , field
56from fix_plugin_aws .aws_client import AwsClient
1920from fixlib .utils import chunks
2021from fix_plugin_aws .utils import TagsValue , ToDict
2122
23+ log = logging .getLogger ("fix.plugins.aws" )
2224service_name = "ecs"
2325
2426
@@ -1075,7 +1077,9 @@ class AwsEcsTaskDefinition(EcsTaggable, AwsResource):
10751077 " Container Service (ECS), providing information such as the Docker image,"
10761078 " CPU, memory, network configuration, and other parameters."
10771079 )
1078- api_spec : ClassVar [AwsApiSpec ] = AwsApiSpec (service_name , "list-task-definitions" , "taskDefinitionArns" )
1080+ api_spec : ClassVar [AwsApiSpec ] = AwsApiSpec (
1081+ service_name , "list-task-definitions" , "taskDefinitionArns" , {"sort" : "desc" }
1082+ )
10791083 reference_kinds : ClassVar [ModelReference ] = {
10801084 "predecessors" : {"default" : ["aws_iam_role" ], "delete" : ["aws_iam_role" ]},
10811085 }
@@ -1141,7 +1145,7 @@ def called_collect_apis(cls) -> List[AwsApiSpec]:
11411145
11421146 @classmethod
11431147 def collect (cls : Type [AwsResource ], json : List [Json ], builder : GraphBuilder ) -> None :
1144- for task_def_arn in json :
1148+ def collect_task_definition ( task_def_arn : str ) -> None :
11451149 response = builder .client .get (
11461150 service_name ,
11471151 "describe-task-definition" ,
@@ -1154,7 +1158,17 @@ def collect(cls: Type[AwsResource], json: List[Json], builder: GraphBuilder) ->
11541158 tags = response ["tags" ]
11551159 task_definition ["tags" ] = tags
11561160 if task_definition_instance := cls .from_api (task_definition , builder ):
1157- builder .add_node (task_definition_instance , task_def_arn )
1161+ builder .add_node (task_definition_instance )
1162+
1163+ last_task_def_arn = ""
1164+ for arn in cast (List [str ], json ):
1165+ # Skip task definition with same arn but older version
1166+ no_version = arn .rsplit (":" , 1 )[0 ]
1167+ if no_version == last_task_def_arn :
1168+ log .info (f"Skipping task definition { arn } as it is an older version of { last_task_def_arn } " )
1169+ continue
1170+ last_task_def_arn = no_version
1171+ builder .submit_work (service_name , collect_task_definition , arn )
11581172
11591173 def connect_in_graph (self , builder : GraphBuilder , source : Json ) -> None :
11601174 for role in [self .task_role_arn , self .execution_role_arn ]:
0 commit comments