@@ -113,18 +113,14 @@ func processFreeTierCluster(resourceb *hclwrite.Body) error {
113113 configb := hclwrite .NewEmptyFile ().Body ()
114114 hcl .SetAttrInt (configb , nPriority , valMaxPriority )
115115
116- // Move required attributes for free tier cluster
117- moveAttrs := []struct {
118- src , dst string
119- }{
120- {nRegionNameSrc , nRegionName },
121- {nProviderName , nProviderName },
122- {nBackingProviderName , nBackingProviderName },
123- }
124- for _ , attr := range moveAttrs {
125- if err := hcl .MoveAttr (resourceb , configb , attr .src , attr .dst , errFreeCluster ); err != nil {
126- return err
127- }
116+ if err := hcl .MoveAttr (resourceb , configb , nRegionNameSrc , nRegionName , errFreeCluster ); err != nil {
117+ return err
118+ }
119+ if err := hcl .MoveAttr (resourceb , configb , nProviderName , nProviderName , errFreeCluster ); err != nil {
120+ return err
121+ }
122+ if err := hcl .MoveAttr (resourceb , configb , nBackingProviderName , nBackingProviderName , errFreeCluster ); err != nil {
123+ return err
128124 }
129125 electableSpecb := hclwrite .NewEmptyFile ().Body ()
130126 if err := hcl .MoveAttr (resourceb , electableSpecb , nInstanceSizeSrc , nInstanceSize , errFreeCluster ); err != nil {
@@ -432,43 +428,39 @@ func sortConfigsByPriority(configs []*hclwrite.Body) []*hclwrite.Body {
432428
433429// popRootAttrs deletes the attributes common to all replication_specs/regions_config and returns them.
434430func popRootAttrs (body * hclwrite.Body ) (attrVals , error ) {
435- type attrConfig struct {
436- name string
437- required bool
438- }
439-
440- attrs := []attrConfig {
441- // Required attributes
442- {nProviderName , true },
443- {nInstanceSizeSrc , true },
444- // Optional attributes
445- {nElectableNodes , false },
446- {nReadOnlyNodes , false },
447- {nAnalyticsNodes , false },
448- {nDiskSizeGB , false },
449- {nDiskGBEnabledSrc , false },
450- {nComputeEnabledSrc , false },
451- {nComputeMinInstanceSizeSrc , false },
452- {nComputeMaxInstanceSizeSrc , false },
453- {nComputeScaleDownEnabledSrc , false },
454- {nEBSVolumeTypeSrc , false },
455- {nDiskIOPSSrc , false },
431+ var (
432+ reqNames = []string {
433+ nProviderName ,
434+ nInstanceSizeSrc ,
435+ }
436+ optNames = []string {
437+ nElectableNodes ,
438+ nReadOnlyNodes ,
439+ nAnalyticsNodes ,
440+ nDiskSizeGB ,
441+ nDiskGBEnabledSrc ,
442+ nComputeEnabledSrc ,
443+ nComputeMinInstanceSizeSrc ,
444+ nComputeMaxInstanceSizeSrc ,
445+ nComputeScaleDownEnabledSrc ,
446+ nEBSVolumeTypeSrc ,
447+ nDiskIOPSSrc ,
448+ }
449+ req = make (map [string ]hclwrite.Tokens )
450+ opt = make (map [string ]hclwrite.Tokens )
451+ )
452+ for _ , name := range reqNames {
453+ tokens , err := hcl .PopAttr (body , name , errRepSpecs )
454+ if err != nil {
455+ return attrVals {}, err
456+ }
457+ req [name ] = tokens
456458 }
457-
458- req := make (map [string ]hclwrite.Tokens )
459- opt := make (map [string ]hclwrite.Tokens )
460-
461- for _ , attr := range attrs {
462- tokens , err := hcl .PopAttr (body , attr .name , errRepSpecs )
463- if attr .required {
464- if err != nil {
465- return attrVals {}, err
466- }
467- req [attr .name ] = tokens
468- } else if tokens != nil {
469- opt [attr .name ] = tokens
459+ for _ , name := range optNames {
460+ tokens , _ := hcl .PopAttr (body , name , errRepSpecs )
461+ if tokens != nil {
462+ opt [name ] = tokens
470463 }
471464 }
472-
473465 return attrVals {req : req , opt : opt }, nil
474466}
0 commit comments