@@ -314,36 +314,27 @@ func getRegionConfig(configSrc *hclwrite.Block, root attrVals, isDynamicBlock bo
314314 if err := hcl .MoveAttr (configSrc .Body (), fileb , nPriority , nPriority , errRepSpecs ); err != nil {
315315 return nil , err
316316 }
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+
331321 if autoScaling := getAutoScalingOpt (root .opt ); autoScaling != nil {
332322 fileb .SetAttributeRaw (nAutoScaling , autoScaling )
333323 }
334324 return fileb , nil
335325}
336326
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 ) {
338329 var (
339330 fileb = hclwrite .NewEmptyFile ().Body ()
340331 count = configSrc .Body ().GetAttribute (countName )
341332 )
342333 if count == nil {
343- return nil , fmt . Errorf ( "%s: attribute %s not found" , errRepSpecs , countName )
334+ return
344335 }
345336 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
347338 }
348339 fileb .SetAttributeRaw (nNodeCount , count .Expr ().BuildTokens (nil ))
349340 fileb .SetAttributeRaw (nInstanceSize , root .req [nInstanceSizeSrc ])
@@ -360,7 +351,7 @@ func getSpec(configSrc *hclwrite.Block, countName string, root attrVals, isDynam
360351 if isDynamicBlock {
361352 tokens = append (hcl .TokensFromExpr (fmt .Sprintf ("%s == 0 ? null :" , hcl .GetAttrExpr (count ))), tokens ... )
362353 }
363- return tokens , nil
354+ configb . SetAttributeRaw ( specName , tokens )
364355}
365356
366357func getAutoScalingOpt (opt map [string ]hclwrite.Tokens ) hclwrite.Tokens {
0 commit comments