@@ -80,22 +80,18 @@ func convertRepSpecs(resourceb *hclwrite.Body, diskSizeGB hclwrite.Tokens) error
80
80
blockb := block .Body ()
81
81
shardsAttr := blockb .GetAttribute (nNumShards )
82
82
blockb .RemoveAttribute (nNumShards )
83
-
84
- // Process config - inlined from convertConfig
85
83
dConfig , err := getDynamicBlock (blockb , nConfig )
86
84
if err != nil {
87
85
return err
88
86
}
89
-
90
87
if dConfig .IsPresent () {
91
- blockName := getResourceName (dConfig .block )
92
- transformReferences (dConfig .content .Body (), blockName , nRegion )
88
+ transformReferences (dConfig .content .Body (), getResourceName (dConfig .block ), nRegion )
93
89
copyAttributesSorted (dConfig .content .Body (), dConfig .content .Body ().Attributes ())
94
90
processAllSpecs (dConfig .content .Body (), diskSizeGB )
95
91
tokens := hcl .TokensFromExpr (buildForExpr (nRegion , hcl .GetAttrExpr (dConfig .forEach ), false ))
96
92
tokens = append (tokens , hcl .TokensObject (dConfig .content .Body ())... )
97
- blockb .RemoveBlock (dConfig .block )
98
93
blockb .SetAttributeRaw (nConfig , hcl .EncloseBracketsNewLines (tokens ))
94
+ blockb .RemoveBlock (dConfig .block )
99
95
} else {
100
96
var configs []* hclwrite.Body
101
97
for _ , configBlock := range collectBlocks (blockb , nConfig ) {
@@ -149,33 +145,30 @@ func convertConfigsWithDynamicBlock(specbSrc *hclwrite.Body, diskSizeGB hclwrite
149
145
return dynamicBlock {}, err
150
146
}
151
147
configBody := d .content .Body ()
152
- repSpecb := hclwrite .NewEmptyFile ().Body ()
153
- if zoneNameAttr := specbSrc .GetAttribute (nZoneName ); zoneNameAttr != nil {
154
- expr := transformReference (hcl .GetAttrExpr (zoneNameAttr ), nRepSpecs , nSpec )
155
- repSpecb .SetAttributeRaw (nZoneName , hcl .TokensFromExpr (expr ))
156
- }
157
- configForEach := fmt .Sprintf ("%s.%s" , nSpec , nConfig )
158
- configBlockName := getResourceName (d .block )
159
- transformReferences (configBody , configBlockName , nRegion )
148
+ transformReferences (configBody , getResourceName (d .block ), nRegion )
160
149
regionConfigBody := hclwrite .NewEmptyFile ().Body ()
161
150
copyAttributesSorted (regionConfigBody , configBody .Attributes ())
162
151
for _ , block := range configBody .Blocks () {
163
152
blockType := block .Type ()
164
153
blockBody := hclwrite .NewEmptyFile ().Body ()
165
154
copyAttributesSorted (blockBody , block .Body ().Attributes ())
166
- if diskSizeGB != nil && ( blockType == nElectableSpecs ||
167
- blockType == nReadOnlySpecs || blockType == nAnalyticsSpecs ) {
155
+ if diskSizeGB != nil &&
156
+ ( blockType == nElectableSpecs || blockType == nReadOnlySpecs || blockType == nAnalyticsSpecs ) {
168
157
blockBody .SetAttributeRaw (nDiskSizeGB , diskSizeGB )
169
158
}
170
159
regionConfigBody .SetAttributeRaw (blockType , hcl .TokensObject (blockBody ))
171
160
}
172
- regionTokens := hcl .TokensFromExpr (buildForExpr (nRegion , configForEach , false ))
161
+ repSpecb := hclwrite .NewEmptyFile ().Body ()
162
+ if zoneNameAttr := specbSrc .GetAttribute (nZoneName ); zoneNameAttr != nil {
163
+ repSpecb .SetAttributeRaw (nZoneName , hcl .TokensFromExpr (
164
+ transformReference (hcl .GetAttrExpr (zoneNameAttr ), nRepSpecs , nSpec )))
165
+ }
166
+ regionTokens := hcl .TokensFromExpr (buildForExpr (nRegion , fmt .Sprintf ("%s.%s" , nSpec , nConfig ), false ))
173
167
regionTokens = append (regionTokens , hcl .TokensObject (regionConfigBody )... )
174
- regionConfig := hcl .EncloseBracketsNewLines (regionTokens )
175
- repSpecb .SetAttributeRaw (nConfig , regionConfig )
168
+ repSpecb .SetAttributeRaw (nConfig , hcl .EncloseBracketsNewLines (regionTokens ))
176
169
if numShardsAttr := specbSrc .GetAttribute (nNumShards ); numShardsAttr != nil {
177
- numShardsExpr := transformReference ( hcl .GetAttrExpr ( numShardsAttr ), nRepSpecs , nSpec )
178
- tokens := hcl . TokensFromExpr ( buildForExpr ( "i" , fmt .Sprintf ("range(%s)" , numShardsExpr ), false ))
170
+ tokens := hcl .TokensFromExpr ( buildForExpr ( "i" ,
171
+ fmt .Sprintf ("range(%s)" , transformReference ( hcl . GetAttrExpr ( numShardsAttr ), nRepSpecs , nSpec ) ), false ))
179
172
tokens = append (tokens , hcl .TokensObject (repSpecb )... )
180
173
return dynamicBlock {tokens : hcl .EncloseBracketsNewLines (tokens )}, nil
181
174
}
0 commit comments