@@ -11,9 +11,10 @@ import (
1111)
1212
1313const (
14- resourceType = "resource"
15- cluster = "mongodbatlas_cluster"
16- advCluster = "mongodbatlas_advanced_cluster"
14+ resourceType = "resource"
15+ cluster = "mongodbatlas_cluster"
16+ advCluster = "mongodbatlas_advanced_cluster"
17+
1718 nameReplicationSpecs = "replication_specs"
1819 nameRegionConfigs = "region_configs"
1920 nameElectableSpecs = "electable_specs"
@@ -26,6 +27,9 @@ const (
2627 nameClusterType = "cluster_type"
2728 namePriority = "priority"
2829
30+ valClusterType = "REPLICASET"
31+ valPriority = 7
32+
2933 errFreeCluster = "free cluster (because no " + nameReplicationSpecs + ")"
3034)
3135
@@ -49,10 +53,13 @@ func ClusterToAdvancedCluster(config []byte) ([]byte, error) {
4953 labels [0 ] = advCluster
5054 resource .SetLabels (labels )
5155
52- if isFreeTier (resourceBody ) {
53- if err := fillFreeTier (resourceBody ); err != nil {
54- return nil , err
55- }
56+ if resourceBody .FirstMatchingBlock (nameReplicationSpecs , nil ) != nil {
57+ err = fillReplicationSpecs (resourceBody )
58+ } else {
59+ err = fillFreeTier (resourceBody )
60+ }
61+ if err != nil {
62+ return nil , err
5663 }
5764
5865 resourceBody .AppendNewline ()
@@ -62,15 +69,7 @@ func ClusterToAdvancedCluster(config []byte) ([]byte, error) {
6269 return parser .Bytes (), nil
6370}
6471
65- func isFreeTier (body * hclwrite.Body ) bool {
66- return body .FirstMatchingBlock (nameReplicationSpecs , nil ) == nil
67- }
68-
6972func fillFreeTier (body * hclwrite.Body ) error {
70- const (
71- valClusterType = "REPLICASET"
72- valPriority = 7
73- )
7473 body .SetAttributeValue (nameClusterType , cty .StringVal (valClusterType ))
7574 regionConfig := hclwrite .NewEmptyFile ()
7675 regionConfigBody := regionConfig .Body ()
@@ -96,6 +95,10 @@ func fillFreeTier(body *hclwrite.Body) error {
9695 return nil
9796}
9897
98+ func fillReplicationSpecs (body * hclwrite.Body ) error {
99+ return nil
100+ }
101+
99102func moveAttribute (fromAttrName , toAttrName string , fromBody , toBody * hclwrite.Body , errPrefix string ) error {
100103 attr := fromBody .GetAttribute (fromAttrName )
101104 if attr == nil {
0 commit comments