Skip to content

Commit a425f53

Browse files
committed
simplify use of TokensFuncConcat
1 parent 472bac3 commit a425f53

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

internal/convert/adv2v2.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,7 @@ func convertRepSpecs(resourceb *hclwrite.Body, diskSizeGB hclwrite.Tokens) error
103103
}
104104
concatParts = append(concatParts, tokens)
105105
}
106-
107-
// Use concat to combine all parts
108-
if len(concatParts) > 1 {
109-
resourceb.SetAttributeRaw(nRepSpecs, hcl.TokensFuncConcat(concatParts...))
110-
} else {
111-
resourceb.SetAttributeRaw(nRepSpecs, concatParts[0])
112-
}
106+
resourceb.SetAttributeRaw(nRepSpecs, hcl.TokensFuncConcat(concatParts...))
113107
} else {
114108
// All num_shards are numeric or missing, use simple array
115109
var repSpecs []*hclwrite.Body

internal/convert/clu2adv.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,7 @@ func fillReplicationSpecs(resourceb *hclwrite.Body, root attrVals) error {
237237
}
238238
concatParts = append(concatParts, tokens)
239239
}
240-
241-
// Use concat to combine all parts
242-
if len(concatParts) > 1 {
243-
resourceb.SetAttributeRaw(nRepSpecs, hcl.TokensFuncConcat(concatParts...))
244-
} else {
245-
resourceb.SetAttributeRaw(nRepSpecs, concatParts[0])
246-
}
240+
resourceb.SetAttributeRaw(nRepSpecs, hcl.TokensFuncConcat(concatParts...))
247241
} else {
248242
// All num_shards are numeric, use simple array
249243
var specbs []*hclwrite.Body

internal/hcl/hcl.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ func TokensFuncMerge(tokens ...hclwrite.Tokens) hclwrite.Tokens {
121121
// TokensFuncConcat creates the tokens for the HCL concat function.
122122
func TokensFuncConcat(tokens ...hclwrite.Tokens) hclwrite.Tokens {
123123
params := EncloseNewLines(joinTokens(tokens...))
124+
if len(tokens) == 1 {
125+
return tokens[0] // no need to concat if there's only one element
126+
}
124127
ret := TokensFromExpr("concat")
125128
return append(ret, EncloseParens(params)...)
126129
}

0 commit comments

Comments
 (0)