in pkg/transform_update_in_place.go [100:120]
func (u *UpdateInPlaceTransform) PatchWriteBlock(dest terraform.Block, patch *hclwrite.Block) {
// we cannot patch one-line block
if dest.Range().Start.Line == dest.Range().End.Line {
dest.WriteBody().AppendNewline()
}
for name, attr := range patch.Body().Attributes() {
dest.SetAttributeRaw(name, attr.Expr().BuildTokens(nil))
}
// Handle nested blocks
for _, patchNestedBlock := range patch.Body().Blocks() {
destNestedBlocks := dest.GetNestedBlocks()[patchNestedBlock.Type()]
if len(destNestedBlocks) == 0 {
// If the nested block does not exist in dest, add it
dest.AppendBlock(patchNestedBlock)
} else {
for _, nb := range destNestedBlocks {
u.PatchWriteBlock(nb, patchNestedBlock)
}
}
}
}