@@ -80,9 +80,34 @@ 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
- if err := convertConfig (blockb , diskSizeGB ); err != nil {
83
+
84
+ // Process config - inlined from convertConfig
85
+ dConfig , err := getDynamicBlock (blockb , nConfig )
86
+ if err != nil {
84
87
return err
85
88
}
89
+
90
+ if dConfig .IsPresent () {
91
+ blockName := getResourceName (dConfig .block )
92
+ transformReferences (dConfig .content .Body (), blockName , nRegion )
93
+ copyAttributesSorted (dConfig .content .Body (), dConfig .content .Body ().Attributes ())
94
+ processAllSpecs (dConfig .content .Body (), diskSizeGB )
95
+ tokens := hcl .TokensFromExpr (buildForExpr (nRegion , hcl .GetAttrExpr (dConfig .forEach ), false ))
96
+ tokens = append (tokens , hcl .TokensObject (dConfig .content .Body ())... )
97
+ blockb .RemoveBlock (dConfig .block )
98
+ blockb .SetAttributeRaw (nConfig , hcl .EncloseBracketsNewLines (tokens ))
99
+ } else {
100
+ var configs []* hclwrite.Body
101
+ for _ , configBlock := range collectBlocks (blockb , nConfig ) {
102
+ configBlockb := configBlock .Body ()
103
+ processAllSpecs (configBlockb , diskSizeGB )
104
+ configs = append (configs , configBlockb )
105
+ }
106
+ if len (configs ) == 0 {
107
+ return fmt .Errorf ("replication_specs must have at least one region_configs" )
108
+ }
109
+ blockb .SetAttributeRaw (nConfig , hcl .TokensArray (configs ))
110
+ }
86
111
if hasVariableShards {
87
112
resultTokens = append (resultTokens , processNumShards (shardsAttr , blockb ))
88
113
continue
@@ -161,35 +186,6 @@ func convertConfigsWithDynamicBlock(specbSrc *hclwrite.Body, diskSizeGB hclwrite
161
186
return dynamicBlock {tokens : hcl .TokensArraySingle (repSpecb )}, nil
162
187
}
163
188
164
- func convertConfig (repSpecs * hclwrite.Body , diskSizeGB hclwrite.Tokens ) error {
165
- dConfig , err := getDynamicBlock (repSpecs , nConfig )
166
- if err != nil {
167
- return err
168
- }
169
- if dConfig .IsPresent () {
170
- blockName := getResourceName (dConfig .block )
171
- transformReferences (dConfig .content .Body (), blockName , nRegion )
172
- copyAttributesSorted (dConfig .content .Body (), dConfig .content .Body ().Attributes ())
173
- processAllSpecs (dConfig .content .Body (), diskSizeGB )
174
- tokens := hcl .TokensFromExpr (buildForExpr (nRegion , hcl .GetAttrExpr (dConfig .forEach ), false ))
175
- tokens = append (tokens , hcl .TokensObject (dConfig .content .Body ())... )
176
- repSpecs .RemoveBlock (dConfig .block )
177
- repSpecs .SetAttributeRaw (nConfig , hcl .EncloseBracketsNewLines (tokens ))
178
- return nil
179
- }
180
- var configs []* hclwrite.Body
181
- for _ , block := range collectBlocks (repSpecs , nConfig ) {
182
- blockb := block .Body ()
183
- processAllSpecs (blockb , diskSizeGB )
184
- configs = append (configs , blockb )
185
- }
186
- if len (configs ) == 0 {
187
- return fmt .Errorf ("replication_specs must have at least one region_configs" )
188
- }
189
- repSpecs .SetAttributeRaw (nConfig , hcl .TokensArray (configs ))
190
- return nil
191
- }
192
-
193
189
// hasExpectedBlocksAsAttributes checks if any of the expected block names
194
190
// exist as attributes in the resource body. In that case conversion is not done
195
191
// as advanced cluster is not in a valid SDKv2 configuration.
@@ -217,9 +213,6 @@ func copyAttributesSorted(targetBody *hclwrite.Body, sourceAttrs map[string]*hcl
217
213
}
218
214
targetBody .SetAttributeRaw (name , hcl .TokensFromExpr (expr ))
219
215
}
220
- for _ , block := range targetBody .Blocks () {
221
- copyAttributesSorted (block .Body (), block .Body ().Attributes (), transforms ... )
222
- }
223
216
}
224
217
225
218
func processAllSpecs (body * hclwrite.Body , diskSizeGB hclwrite.Tokens ) {
0 commit comments