@@ -248,26 +248,27 @@ type tgListOutput struct {
248248func (s * defaultTargetGroupManager ) List (ctx context.Context ) ([]tgListOutput , error ) {
249249 lattice := s .cloud .Lattice ()
250250 var tgList []tgListOutput
251- targetGroupListInput := vpclattice.ListTargetGroupsInput {
252- VpcIdentifier : aws .String (config .VpcID ),
253- TargetGroupType : aws .String (vpclattice .TargetGroupTypeIp ),
254- }
251+ targetGroupListInput := vpclattice.ListTargetGroupsInput {}
255252 resp , err := lattice .ListTargetGroupsAsList (ctx , & targetGroupListInput )
256253 if err != nil {
257254 return nil , err
258255 }
259256 if len (resp ) == 0 {
260257 return nil , nil
261258 }
262- tgArns := utils .SliceMap (resp , func (tg * vpclattice.TargetGroupSummary ) string {
259+ validTgs := utils .SliceFilter (resp , func (tg * vpclattice.TargetGroupSummary ) bool {
260+ return aws .StringValue (tg .VpcIdentifier ) == config .VpcID &&
261+ aws .StringValue (tg .Type ) == vpclattice .TargetGroupTypeIp
262+ })
263+ tgArns := utils .SliceMap (validTgs , func (tg * vpclattice.TargetGroupSummary ) string {
263264 return aws .StringValue (tg .Arn )
264265 })
265266 tgArnToTagsMap , err := s .cloud .Tagging ().GetTagsForArns (ctx , tgArns )
266267
267268 if err != nil {
268269 return nil , err
269270 }
270- for _ , tg := range resp {
271+ for _ , tg := range validTgs {
271272 tgList = append (tgList , tgListOutput {
272273 tgSummary : tg ,
273274 tags : tgArnToTagsMap [* tg .Arn ],
@@ -288,44 +289,43 @@ func (s *defaultTargetGroupManager) findTargetGroup(
288289 if len (arns ) == 0 {
289290 return nil , nil
290291 }
291- // Tag fields guarantee one result, as there can be only one target group for one service/route combination.
292- // We move forward but log this situation to help troubleshooting
293- if len (arns ) > 1 {
294- s .log .Warnw ("Target groups with conflicting tags found" , "arns" , arns )
295- }
296- arn := arns [0 ]
297292
298- latticeTg , err := s .cloud .Lattice ().GetTargetGroupWithContext (ctx , & vpclattice.GetTargetGroupInput {
299- TargetGroupIdentifier : & arn ,
300- })
301- if err != nil {
302- return nil , services .IgnoreNotFound (err )
303- }
293+ for _ , arn := range arns {
294+ latticeTg , err := s .cloud .Lattice ().GetTargetGroupWithContext (ctx , & vpclattice.GetTargetGroupInput {
295+ TargetGroupIdentifier : & arn ,
296+ })
297+ if err != nil {
298+ if services .IsNotFoundError (err ) {
299+ continue
300+ }
301+ return nil , err
302+ }
304303
305- // we ignore create failed status, so may as well check for it first
306- status := aws .StringValue (latticeTg .Status )
307- if status == vpclattice .TargetGroupStatusCreateFailed {
308- return nil , nil
309- }
304+ // we ignore create failed status, so may as well check for it first
305+ status := aws .StringValue (latticeTg .Status )
306+ if status == vpclattice .TargetGroupStatusCreateFailed {
307+ continue
308+ }
310309
311- // Double-check the immutable fields to ensure TG is valid
312- match , err := s .IsTargetGroupMatch (ctx , modelTargetGroup , & vpclattice.TargetGroupSummary {
313- Arn : latticeTg .Arn ,
314- Port : latticeTg .Config .Port ,
315- Protocol : latticeTg .Config .Protocol ,
316- IpAddressType : latticeTg .Config .IpAddressType ,
317- Type : latticeTg .Type ,
318- VpcIdentifier : latticeTg .Config .VpcIdentifier ,
319- }, nil ) // we already know that tags match
320- if err != nil {
321- return nil , err
322- }
323- if match {
324- switch status {
325- case vpclattice .TargetGroupStatusCreateInProgress , vpclattice .TargetGroupStatusDeleteInProgress :
326- return nil , errors .New (LATTICE_RETRY )
327- case vpclattice .TargetGroupStatusDeleteFailed , vpclattice .TargetGroupStatusActive :
328- return latticeTg , nil
310+ // Check the immutable fields to ensure TG is valid
311+ match , err := s .IsTargetGroupMatch (ctx , modelTargetGroup , & vpclattice.TargetGroupSummary {
312+ Arn : latticeTg .Arn ,
313+ Port : latticeTg .Config .Port ,
314+ Protocol : latticeTg .Config .Protocol ,
315+ IpAddressType : latticeTg .Config .IpAddressType ,
316+ Type : latticeTg .Type ,
317+ VpcIdentifier : latticeTg .Config .VpcIdentifier ,
318+ }, nil ) // we already know that tags match
319+ if err != nil {
320+ return nil , err
321+ }
322+ if match {
323+ switch status {
324+ case vpclattice .TargetGroupStatusCreateInProgress , vpclattice .TargetGroupStatusDeleteInProgress :
325+ return nil , errors .New (LATTICE_RETRY )
326+ case vpclattice .TargetGroupStatusDeleteFailed , vpclattice .TargetGroupStatusActive :
327+ return latticeTg , nil
328+ }
329329 }
330330 }
331331
0 commit comments