@@ -166,8 +166,8 @@ func processDynamicRepSpecsWithoutConfig(dSpec dynamicBlock, diskSizeGB hclwrite
166
166
167
167
func buildDynamicRepSpecsWithShards (dSpec dynamicBlock , numShardsAttr * hclwrite.Attribute ) (hclwrite.Tokens , error ) {
168
168
numShardsExpr := replaceDynamicBlockReferences (hcl .GetAttrExpr (numShardsAttr ), nRepSpecs , nSpec )
169
- outerFor := buildForExpr (nSpec , hcl .GetAttrExpr (dSpec .forEach ))
170
- innerFor := buildForExpr ("i" , fmt .Sprintf ("range(%s)" , numShardsExpr ))
169
+ outerFor := buildForExpr (nSpec , hcl .GetAttrExpr (dSpec .forEach ), false )
170
+ innerFor := buildForExpr ("i" , fmt .Sprintf ("range(%s)" , numShardsExpr ), false )
171
171
forExpr := fmt .Sprintf ("%s [\n %s " , outerFor , innerFor )
172
172
tokens := hcl .TokensFromExpr (forExpr )
173
173
tokens = append (tokens , hcl .TokensObject (dSpec .content .Body ())... )
@@ -176,7 +176,7 @@ func buildDynamicRepSpecsWithShards(dSpec dynamicBlock, numShardsAttr *hclwrite.
176
176
}
177
177
178
178
func buildSimpleDynamicRepSpecs (dSpec dynamicBlock ) (hclwrite.Tokens , error ) {
179
- forExpr := buildForExpr (nSpec , hcl .GetAttrExpr (dSpec .forEach ))
179
+ forExpr := buildForExpr (nSpec , hcl .GetAttrExpr (dSpec .forEach ), false )
180
180
tokens := hcl .TokensFromExpr (forExpr )
181
181
tokens = append (tokens , hcl .TokensObject (dSpec .content .Body ())... )
182
182
return hcl .EncloseBracketsNewLines (tokens ), nil
@@ -211,7 +211,7 @@ func buildRegionConfigBody(dConfig dynamicBlock, diskSizeGB hclwrite.Tokens) *hc
211
211
212
212
func buildRegionForExpr (spec string , regionConfigBody * hclwrite.Body ) hclwrite.Tokens {
213
213
configForEach := fmt .Sprintf ("%s.%s" , spec , nConfig )
214
- regionForExpr := buildForExpr (nRegion , configForEach )
214
+ regionForExpr := buildForExpr (nRegion , configForEach , false )
215
215
regionTokens := hcl .TokensFromExpr (regionForExpr )
216
216
return append (regionTokens , hcl .TokensObject (regionConfigBody )... )
217
217
}
@@ -228,14 +228,14 @@ func buildRepSpecBody(dSpec dynamicBlock, regionTokens hclwrite.Tokens) *hclwrit
228
228
}
229
229
230
230
func buildInnerForExpr (numShardsExpr string , repSpecBody * hclwrite.Body ) hclwrite.Tokens {
231
- innerForExpr := buildForExpr ("i" , fmt .Sprintf ("range(%s)" , numShardsExpr ))
231
+ innerForExpr := buildForExpr ("i" , fmt .Sprintf ("range(%s)" , numShardsExpr ), false )
232
232
innerTokens := hcl .TokensFromExpr (innerForExpr )
233
233
return append (innerTokens , hcl .TokensObject (repSpecBody )... )
234
234
}
235
235
236
236
func buildOuterForExpr (dSpec dynamicBlock , innerTokens hclwrite.Tokens ) hclwrite.Tokens {
237
- outerForExpr := buildForExpr (nSpec , hcl .GetAttrExpr (dSpec .forEach ))
238
- outerTokens := hcl .TokensFromExpr (fmt . Sprintf ( "%s " , outerForExpr ) )
237
+ outerForExpr := buildForExpr (nSpec , hcl .GetAttrExpr (dSpec .forEach ), true )
238
+ outerTokens := hcl .TokensFromExpr (outerForExpr )
239
239
return append (outerTokens , hcl .EncloseBracketsNewLines (innerTokens )... )
240
240
}
241
241
@@ -298,12 +298,12 @@ func convertDynamicRepSpecsWithoutNumShards(resourceb *hclwrite.Body, dSpec, dCo
298
298
}
299
299
processAllSpecs (configb , diskSizeGB )
300
300
configForEach := fmt .Sprintf ("%s.%s" , nSpec , nConfig )
301
- regionForExpr := buildForExpr (nRegion , configForEach )
301
+ regionForExpr := buildForExpr (nRegion , configForEach , false )
302
302
regionTokens := hcl .TokensFromExpr (regionForExpr )
303
303
regionTokens = append (regionTokens , hcl .TokensObject (configb )... )
304
304
repSpecb .SetAttributeRaw (nConfig , hcl .EncloseBracketsNewLines (regionTokens ))
305
- forExpr := buildForExpr (nSpec , hcl .GetAttrExpr (dSpec .forEach ))
306
- innerTokens := hcl .TokensFromExpr (fmt . Sprintf ( "%s " , forExpr ) )
305
+ forExpr := buildForExpr (nSpec , hcl .GetAttrExpr (dSpec .forEach ), true )
306
+ innerTokens := hcl .TokensFromExpr (forExpr )
307
307
innerTokens = append (innerTokens , hcl .TokensArraySingle (repSpecb )... )
308
308
tokens := hcl .TokensFuncFlatten (innerTokens )
309
309
resourceb .RemoveBlock (dSpec .block )
@@ -342,7 +342,7 @@ func convertDynamicConfig(repSpecs *hclwrite.Body, dConfig dynamicBlock, diskSiz
342
342
blockName := getResourceName (dConfig .block )
343
343
transformDynamicBlockReferencesRecursive (dConfig .content .Body (), blockName , nRegion )
344
344
processAllSpecs (dConfig .content .Body (), diskSizeGB )
345
- forExpr := buildForExpr (nRegion , hcl .GetAttrExpr (dConfig .forEach ))
345
+ forExpr := buildForExpr (nRegion , hcl .GetAttrExpr (dConfig .forEach ), false )
346
346
tokens := hcl .TokensFromExpr (forExpr )
347
347
tokens = append (tokens , hcl .TokensObject (dConfig .content .Body ())... )
348
348
tokens = hcl .EncloseBracketsNewLines (tokens )
0 commit comments