@@ -21,7 +21,8 @@ func RegisterSweepers() {
21
21
awsv2 .Register ("aws_vpclattice_service" , sweepServices )
22
22
awsv2 .Register ("aws_vpclattice_service_network" , sweepServiceNetworks , "aws_vpclattice_service" )
23
23
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 )
25
26
}
26
27
27
28
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
168
169
169
170
return sweepResources , nil
170
171
}
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