@@ -314,36 +314,27 @@ func getRegionConfig(configSrc *hclwrite.Block, root attrVals, isDynamicBlock bo
314
314
if err := hcl .MoveAttr (configSrc .Body (), fileb , nPriority , nPriority , errRepSpecs ); err != nil {
315
315
return nil , err
316
316
}
317
- // Process all spec types
318
- specMappings := []struct {
319
- nodeName string
320
- specName string
321
- }{
322
- {nElectableNodes , nElectableSpecs },
323
- {nReadOnlyNodes , nReadOnlySpecs },
324
- {nAnalyticsNodes , nAnalyticsSpecs },
325
- }
326
- for _ , mapping := range specMappings {
327
- if spec , _ := getSpec (configSrc , mapping .nodeName , root , isDynamicBlock ); spec != nil {
328
- fileb .SetAttributeRaw (mapping .specName , spec )
329
- }
330
- }
317
+ processSpec (fileb , configSrc , nElectableSpecs , nElectableNodes , root , isDynamicBlock )
318
+ processSpec (fileb , configSrc , nReadOnlySpecs , nReadOnlyNodes , root , isDynamicBlock )
319
+ processSpec (fileb , configSrc , nAnalyticsSpecs , nAnalyticsNodes , root , isDynamicBlock )
320
+
331
321
if autoScaling := getAutoScalingOpt (root .opt ); autoScaling != nil {
332
322
fileb .SetAttributeRaw (nAutoScaling , autoScaling )
333
323
}
334
324
return fileb , nil
335
325
}
336
326
337
- func getSpec (configSrc * hclwrite.Block , countName string , root attrVals , isDynamicBlock bool ) (hclwrite.Tokens , error ) {
327
+ func processSpec (configb * hclwrite.Body , configSrc * hclwrite.Block ,
328
+ specName , countName string , root attrVals , isDynamicBlock bool ) {
338
329
var (
339
330
fileb = hclwrite .NewEmptyFile ().Body ()
340
331
count = configSrc .Body ().GetAttribute (countName )
341
332
)
342
333
if count == nil {
343
- return nil , fmt . Errorf ( "%s: attribute %s not found" , errRepSpecs , countName )
334
+ return
344
335
}
345
336
if countVal , errVal := hcl .GetAttrInt (count , errRepSpecs ); countVal == 0 && errVal == nil {
346
- return nil , fmt . Errorf ( "%s: attribute %s is 0" , errRepSpecs , countName )
337
+ return
347
338
}
348
339
fileb .SetAttributeRaw (nNodeCount , count .Expr ().BuildTokens (nil ))
349
340
fileb .SetAttributeRaw (nInstanceSize , root .req [nInstanceSizeSrc ])
@@ -360,7 +351,7 @@ func getSpec(configSrc *hclwrite.Block, countName string, root attrVals, isDynam
360
351
if isDynamicBlock {
361
352
tokens = append (hcl .TokensFromExpr (fmt .Sprintf ("%s == 0 ? null :" , hcl .GetAttrExpr (count ))), tokens ... )
362
353
}
363
- return tokens , nil
354
+ configb . SetAttributeRaw ( specName , tokens )
364
355
}
365
356
366
357
func getAutoScalingOpt (opt map [string ]hclwrite.Tokens ) hclwrite.Tokens {
0 commit comments