Skip to content

Commit 9027f4d

Browse files
lantoliCopilot
andauthored
Improve collectBlocks
Co-authored-by: Copilot <[email protected]>
1 parent 65fa29e commit 9027f4d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

internal/convert/shared.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ func transformReferences(body *hclwrite.Body, blockName, varName string) {
115115
// collectBlocks removes and returns all blocks of the given name from body in order of appearance.
116116
func collectBlocks(body *hclwrite.Body, name string) []*hclwrite.Block {
117117
var blocks []*hclwrite.Block
118-
for {
119-
block := body.FirstMatchingBlock(name, nil)
120-
if block == nil {
121-
break
118+
for _, block := range body.Blocks() {
119+
if block.Type() == name {
120+
blocks = append(blocks, block)
122121
}
122+
}
123+
for _, block := range blocks {
123124
body.RemoveBlock(block)
124-
blocks = append(blocks, block)
125125
}
126126
return blocks
127127
}

0 commit comments

Comments
 (0)