in pkg/terraform/root_block.go [77:114]
func (b *RootBlock) removeContent(wb *hclwrite.Block, path string) {
segs := strings.Split(path, ".")
var nbs []*hclwrite.Block
if wb.Type() == "dynamic" {
nbs = wb.Body().Blocks()
}
for _, nb := range nbs {
if nb.Type() != "content" {
continue
}
wb = nb
break
}
_, ok := wb.Body().Attributes()[segs[0]]
if ok {
wb.Body().RemoveAttribute(segs[0])
return
}
nbs = make([]*hclwrite.Block, 0)
for _, nb := range wb.Body().Blocks() {
if nb.Type() == segs[0] || (nb.Type() == "dynamic" && nb.Labels()[0] == segs[0]) {
nbs = append(nbs, nb)
}
}
if len(nbs) == 0 {
return
}
if len(segs) == 1 {
for _, nb := range nbs {
wb.Body().RemoveBlock(nb)
}
return
}
for _, nb := range nbs {
b.removeContent(nb, strings.Join(segs[1:], "."))
}
}