@@ -107,6 +107,32 @@ func fillMovedBlocks(body *hclwrite.Body, moveLabels []string) {
107
107
}
108
108
}
109
109
110
+ // createDefaultReplicationSpec creates a default replication_specs for clusters without any
111
+ // (e.g. upgraded from free tier).
112
+ func createDefaultReplicationSpec (resourceb * hclwrite.Body , root attrVals ) error {
113
+ resourceb .SetAttributeValue (nClusterType , cty .StringVal (valClusterType ))
114
+ configb := hclwrite .NewEmptyFile ().Body ()
115
+ hcl .SetAttrInt (configb , nPriority , valMaxPriority )
116
+ if err := hcl .MoveAttr (resourceb , configb , nRegionNameSrc , nRegionName , errRoot ); err != nil {
117
+ return err
118
+ }
119
+ if providerNameTokens , found := root .req [nProviderName ]; found {
120
+ configb .SetAttributeRaw (nProviderName , providerNameTokens )
121
+ }
122
+
123
+ electableSpecb := hclwrite .NewEmptyFile ().Body ()
124
+ if instanceSizeTokens , found := root .req [nInstanceSizeSrc ]; found {
125
+ electableSpecb .SetAttributeRaw (nInstanceSize , instanceSizeTokens )
126
+ }
127
+ electableSpecb .SetAttributeValue (nNodeCount , cty .NumberIntVal (valDefaultNodeCount ))
128
+ configb .SetAttributeRaw (nElectableSpecs , hcl .TokensObject (electableSpecb ))
129
+
130
+ repSpecsb := hclwrite .NewEmptyFile ().Body ()
131
+ repSpecsb .SetAttributeRaw (nConfig , hcl .TokensArraySingle (configb ))
132
+ resourceb .SetAttributeRaw (nRepSpecs , hcl .TokensArraySingle (repSpecsb ))
133
+ return nil
134
+ }
135
+
110
136
// fillFreeTierCluster is the entry point to convert clusters in free tier
111
137
func processFreeTierCluster (resourceb * hclwrite.Body ) error {
112
138
resourceb .SetAttributeValue (nClusterType , cty .StringVal (valClusterType ))
@@ -160,7 +186,7 @@ func processRepSpecsCluster(resourceb *hclwrite.Body, root attrVals) error {
160
186
}
161
187
repSpecBlocks := collectBlocks (resourceb , nRepSpecs )
162
188
if len (repSpecBlocks ) == 0 {
163
- return fmt . Errorf ( "must have at least one replication_specs" )
189
+ return createDefaultReplicationSpec ( resourceb , root )
164
190
}
165
191
dConfig , err := processConfigsWithDynamicRegion (repSpecBlocks [0 ].Body (), root , false )
166
192
if err != nil {
0 commit comments