@@ -133,19 +133,6 @@ func convertConfigsWithDynamicBlock(specbSrc *hclwrite.Body, diskSizeGB hclwrite
133
133
configForEach := fmt .Sprintf ("%s.%s" , nSpec , nConfig )
134
134
configBlockName := getResourceName (d .block )
135
135
transformReferences (configBody , configBlockName , nRegion )
136
- for _ , block := range configBody .Blocks () {
137
- transformReferences (block .Body (), configBlockName , nRegion )
138
- }
139
- for name , attr := range configBody .Attributes () {
140
- expr := transformReference (hcl .GetAttrExpr (attr ), nRepSpecs , nSpec )
141
- configBody .SetAttributeRaw (name , hcl .TokensFromExpr (expr ))
142
- }
143
- for _ , block := range configBody .Blocks () {
144
- for name , attr := range block .Body ().Attributes () {
145
- expr := transformReference (hcl .GetAttrExpr (attr ), nRepSpecs , nSpec )
146
- block .Body ().SetAttributeRaw (name , hcl .TokensFromExpr (expr ))
147
- }
148
- }
149
136
regionConfigFile := hclwrite .NewEmptyFile ()
150
137
regionConfigBody := regionConfigFile .Body ()
151
138
copyAttributesSorted (regionConfigBody , configBody .Attributes ())
@@ -181,13 +168,8 @@ func convertConfig(repSpecs *hclwrite.Body, diskSizeGB hclwrite.Tokens) error {
181
168
}
182
169
if dConfig .IsPresent () {
183
170
blockName := getResourceName (dConfig .block )
184
- transform := func (expr string ) string {
185
- return transformReference (expr , blockName , nRegion )
186
- }
187
- copyAttributesSorted (dConfig .content .Body (), dConfig .content .Body ().Attributes (), transform )
188
- for _ , block := range dConfig .content .Body ().Blocks () {
189
- copyAttributesSorted (block .Body (), block .Body ().Attributes (), transform )
190
- }
171
+ transformReferences (dConfig .content .Body (), blockName , nRegion )
172
+ copyAttributesSorted (dConfig .content .Body (), dConfig .content .Body ().Attributes ())
191
173
processAllSpecs (dConfig .content .Body (), diskSizeGB )
192
174
tokens := hcl .TokensFromExpr (buildForExpr (nRegion , hcl .GetAttrExpr (dConfig .forEach ), false ))
193
175
tokens = append (tokens , hcl .TokensObject (dConfig .content .Body ())... )
@@ -235,6 +217,9 @@ func copyAttributesSorted(targetBody *hclwrite.Body, sourceAttrs map[string]*hcl
235
217
}
236
218
targetBody .SetAttributeRaw (name , hcl .TokensFromExpr (expr ))
237
219
}
220
+ for _ , block := range targetBody .Blocks () {
221
+ copyAttributesSorted (block .Body (), block .Body ().Attributes (), transforms ... )
222
+ }
238
223
}
239
224
240
225
func processAllSpecs (body * hclwrite.Body , diskSizeGB hclwrite.Tokens ) {
0 commit comments