Skip to content

Commit 9323d6e

Browse files
authored
Merge pull request #44443 from hashicorp/td-sweep-vpclattice-target-group-attachment
sweeper:`aws_vpclattice_target_group_attachment`
2 parents bfeb6a0 + 6d740e1 commit 9323d6e

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

internal/service/vpclattice/sweep.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ func RegisterSweepers() {
2121
awsv2.Register("aws_vpclattice_service", sweepServices)
2222
awsv2.Register("aws_vpclattice_service_network", sweepServiceNetworks, "aws_vpclattice_service")
2323
awsv2.Register("aws_vpclattice_service_network_resource_association", sweepServiceNetworkResourceAssociations)
24-
awsv2.Register("aws_vpclattice_target_group", sweepTargetGroups)
24+
awsv2.Register("aws_vpclattice_target_group", sweepTargetGroups, "aws_vpclattice_target_group_attachment")
25+
awsv2.Register("aws_vpclattice_target_group_attachment", sweepTargetGroupAttachments)
2526
}
2627

2728
func sweepResourceConfigurations(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) {
@@ -168,3 +169,43 @@ func sweepTargetGroups(ctx context.Context, client *conns.AWSClient) ([]sweep.Sw
168169

169170
return sweepResources, nil
170171
}
172+
173+
func sweepTargetGroupAttachments(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) {
174+
conn := client.VPCLatticeClient(ctx)
175+
var sweepResources []sweep.Sweepable
176+
177+
var input vpclattice.ListTargetGroupsInput
178+
pages := vpclattice.NewListTargetGroupsPaginator(conn, &input)
179+
for pages.HasMorePages() {
180+
page, err := pages.NextPage(ctx)
181+
if err != nil {
182+
return nil, err
183+
}
184+
185+
for _, targetGroup := range page.Items {
186+
input := vpclattice.ListTargetsInput{
187+
TargetGroupIdentifier: targetGroup.Id,
188+
}
189+
pages := vpclattice.NewListTargetsPaginator(conn, &input)
190+
for pages.HasMorePages() {
191+
page, err := pages.NextPage(ctx)
192+
if err != nil {
193+
return nil, err
194+
}
195+
196+
for _, target := range page.Items {
197+
r := resourceTargetGroupAttachment()
198+
d := r.Data(nil)
199+
200+
d.SetId(targetGroupAttachmentCreateResourceID(aws.ToString(targetGroup.Id), aws.ToString(target.Id), aws.ToInt32(target.Port)))
201+
d.Set("target_group_identifier", targetGroup.Id)
202+
d.Set(names.AttrTarget, []any{flattenTargetSummary(&target)})
203+
204+
sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client))
205+
}
206+
}
207+
}
208+
}
209+
210+
return sweepResources, nil
211+
}

0 commit comments

Comments
 (0)