Skip to content

Commit 613f194

Browse files
committed
remove unneeded checks
1 parent c0e0bac commit 613f194

File tree

2 files changed

+0
-56
lines changed

2 files changed

+0
-56
lines changed

internal/convert/adv2v2.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -128,48 +128,20 @@ func processRepSpecsWithDynamicBlock(resourceb *hclwrite.Body, diskSizeGB hclwri
128128

129129
// Handle static region_configs blocks inside dynamic replication_specs
130130
specBody := dSpec.content.Body()
131-
132-
// Collect static region_configs blocks
133131
staticConfigs := collectBlocks(specBody, nConfig)
134-
if len(staticConfigs) == 0 {
135-
// No static blocks found, this might be an error case
136-
// Check if there's also no dynamic block (which would have been handled above)
137-
hasDynamicBlock := false
138-
for _, block := range specBody.Blocks() {
139-
if block.Type() == nDynamic && getResourceName(block) == nConfig {
140-
hasDynamicBlock = true
141-
break
142-
}
143-
}
144-
if !hasDynamicBlock {
145-
return dynamicBlock{}, fmt.Errorf("replication_specs must have at least one region_configs")
146-
}
147-
// There's a dynamic block but convertConfigsWithDynamicBlock returned empty
148-
// This shouldn't happen, but return the error from that function
149-
return dynamicBlock{}, nil
150-
}
151-
152132
repSpecb := hclwrite.NewEmptyFile().Body()
153-
154-
// Handle zone_name attribute
155133
handleZoneName(repSpecb, specBody, nRepSpecs, nSpec)
156-
157-
// Process static region_configs blocks
158134
var configs []*hclwrite.Body
159135
for _, configBlock := range staticConfigs {
160136
configBlockb := configBlock.Body()
161137
newConfigBody := processConfigForDynamicBlock(configBlockb, diskSizeGB)
162138
configs = append(configs, newConfigBody)
163139
}
164-
165140
repSpecb.SetAttributeRaw(nConfig, hcl.TokensArray(configs))
166-
167-
// Handle num_shards attribute
168141
numShardsAttr := specBody.GetAttribute(nNumShards)
169142
forSpec := hcl.TokensFromExpr(buildForExpr(nSpec, hcl.GetAttrExpr(dSpec.forEach), true))
170143
numShardsTokens := buildNumShardsTokens(numShardsAttr, repSpecb, nRepSpecs, nSpec)
171144
dSpec.tokens = hcl.TokensFuncFlatten(append(forSpec, numShardsTokens...))
172-
173145
return dSpec, nil
174146
}
175147

internal/convert/clu2adv.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,6 @@ func processRepSpecsClusterWithDynamicBlock(resourceb *hclwrite.Body, root attrV
219219
if err != nil {
220220
return dynamicBlock{}, err
221221
}
222-
223-
// Check if we have a dynamic region_configs block that was successfully processed
224222
if dConfig.tokens != nil {
225223
forSpec := hcl.TokensFromExpr(buildForExpr(nSpec, hcl.GetAttrExpr(dSpec.forEach), true))
226224
forSpec = append(forSpec, dConfig.tokens...)
@@ -231,31 +229,9 @@ func processRepSpecsClusterWithDynamicBlock(resourceb *hclwrite.Body, root attrV
231229

232230
// Handle static region_configs blocks inside dynamic replication_specs
233231
specBody := dSpec.content.Body()
234-
235-
// Collect static region_configs blocks
236232
staticConfigs := collectBlocks(specBody, nConfigSrc)
237-
if len(staticConfigs) == 0 {
238-
// No static blocks found, check if there's also no dynamic block
239-
hasDynamicBlock := false
240-
for _, block := range specBody.Blocks() {
241-
if block.Type() == nDynamic && getResourceName(block) == nConfigSrc {
242-
hasDynamicBlock = true
243-
break
244-
}
245-
}
246-
if !hasDynamicBlock {
247-
return dynamicBlock{}, fmt.Errorf("replication_specs must have at least one regions_config")
248-
}
249-
// There's a dynamic block but fillConfigsWithDynamicRegion returned empty
250-
return dynamicBlock{}, nil
251-
}
252-
253233
repSpecb := hclwrite.NewEmptyFile().Body()
254-
255-
// Handle zone_name attribute
256234
handleZoneName(repSpecb, specBody, nRepSpecs, nSpec)
257-
258-
// Process static region_configs blocks
259235
var configs []*hclwrite.Body
260236
for _, configBlock := range staticConfigs {
261237
config, err := getRegionConfig(configBlock, root, false)
@@ -264,16 +240,12 @@ func processRepSpecsClusterWithDynamicBlock(resourceb *hclwrite.Body, root attrV
264240
}
265241
configs = append(configs, config)
266242
}
267-
268243
configs = sortConfigsByPriority(configs)
269244
repSpecb.SetAttributeRaw(nConfig, hcl.TokensArray(configs))
270-
271-
// Handle num_shards attribute
272245
numShardsAttr := specBody.GetAttribute(nNumShards)
273246
forSpec := hcl.TokensFromExpr(buildForExpr(nSpec, hcl.GetAttrExpr(dSpec.forEach), true))
274247
numShardsTokens := buildNumShardsTokens(numShardsAttr, repSpecb, nRepSpecs, nSpec)
275248
dSpec.tokens = hcl.TokensFuncFlatten(append(forSpec, numShardsTokens...))
276-
277249
return dSpec, nil
278250
}
279251

0 commit comments

Comments
 (0)