Skip to content

Commit 5a50012

Browse files
authored
add pagination to stack resources list (#227)
1 parent 62c9e6a commit 5a50012

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

cmd/orphaned.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,25 @@ func getRootedResources(svc CloudformationAPI, kind string) map[string]bool {
134134
if Debug {
135135
fmt.Printf("Processing %v\n", *stack.StackName)
136136
}
137-
resources, err := svc.ListStackResources(&cloudformation.ListStackResourcesInput{
138-
StackName: stack.StackName,
139-
})
140-
if err != nil {
141-
fmt.Printf("Error processing %v: %v\n", *stack.StackName, err)
142-
continue
143-
}
144-
for _, resource := range resources.StackResourceSummaries {
145-
if *resource.ResourceType == kind {
146-
if Debug {
147-
fmt.Printf("Found rooted resource %v : %v\n", *resource.PhysicalResourceId, *resource.ResourceType)
137+
var resourceToken *string
138+
for ok := true; ok; ok = (resourceToken != nil) {
139+
resources, err := svc.ListStackResources(&cloudformation.ListStackResourcesInput{
140+
StackName: stack.StackName,
141+
NextToken: resourceToken,
142+
})
143+
if err != nil {
144+
fmt.Printf("Error processing %v: %v\n", *stack.StackName, err)
145+
break
146+
}
147+
resourceToken = resources.NextToken
148+
149+
for _, resource := range resources.StackResourceSummaries {
150+
if *resource.ResourceType == kind {
151+
if Debug {
152+
fmt.Printf("Found rooted resource %v : %v\n", *resource.PhysicalResourceId, *resource.ResourceType)
153+
}
154+
rootedResources[*resource.PhysicalResourceId] = true
148155
}
149-
rootedResources[*resource.PhysicalResourceId] = true
150-
151156
}
152157
}
153158
}

0 commit comments

Comments
 (0)