Skip to content

Commit acc8a7b

Browse files
INTMDB-932: remove the default value of retain_backups_enabled (#1314)
1 parent f196b54 commit acc8a7b

6 files changed

+26
-34
lines changed

mongodbatlas/resource_mongodbatlas_advanced_cluster.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ func resourceMongoDBAtlasAdvancedCluster() *schema.Resource {
7272
"retain_backups_enabled": {
7373
Type: schema.TypeBool,
7474
Optional: true,
75-
Default: false,
7675
Description: "Flag that indicates whether to retain backup snapshots for the deleted dedicated cluster",
7776
},
7877
"bi_connector": {
@@ -787,13 +786,11 @@ func resourceMongoDBAtlasAdvancedClusterDelete(ctx context.Context, d *schema.Re
787786
projectID := ids["project_id"]
788787
clusterName := ids["cluster_name"]
789788

790-
retainBackup := pointy.Bool(false)
791-
if v, ok := d.Get("retain_backups_enabled").(bool); ok {
792-
retainBackup = pointy.Bool(v)
793-
}
794-
795-
options := &matlas.DeleteAdvanceClusterOptions{
796-
RetainBackups: retainBackup,
789+
var options *matlas.DeleteAdvanceClusterOptions
790+
if v, ok := d.GetOkExists("retain_backups_enabled"); ok {
791+
options = &matlas.DeleteAdvanceClusterOptions{
792+
RetainBackups: pointy.Bool(v.(bool)),
793+
}
797794
}
798795

799796
_, err := conn.AdvancedClusters.Delete(ctx, projectID, clusterName, options)
@@ -842,10 +839,6 @@ func resourceMongoDBAtlasAdvancedClusterImportState(ctx context.Context, d *sche
842839
log.Printf(errorClusterAdvancedSetting, "name", u.ID, err)
843840
}
844841

845-
if err := d.Set("retain_backups_enabled", false); err != nil {
846-
return nil, fmt.Errorf(errorClusterAdvancedSetting, "retain_backups_enabled", u.ID, err)
847-
}
848-
849842
d.SetId(encodeStateID(map[string]string{
850843
"cluster_id": u.ID,
851844
"project_id": *projectID,

mongodbatlas/resource_mongodbatlas_advanced_cluster_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func TestAccClusterAdvancedCluster_singleProvider(t *testing.T) {
9898
testAccCheckMongoDBAtlasAdvancedClusterAttributes(&cluster, rName),
9999
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
100100
resource.TestCheckResourceAttr(resourceName, "name", rName),
101+
resource.TestCheckResourceAttr(resourceName, "retain_backups_enabled", "true"),
101102
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"),
102103
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.region_configs.#"),
103104
),
@@ -109,6 +110,7 @@ func TestAccClusterAdvancedCluster_singleProvider(t *testing.T) {
109110
testAccCheckMongoDBAtlasAdvancedClusterAttributes(&cluster, rName),
110111
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
111112
resource.TestCheckResourceAttr(resourceName, "name", rName),
113+
resource.TestCheckResourceAttr(resourceName, "retain_backups_enabled", "false"),
112114
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"),
113115
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.region_configs.#"),
114116
),
@@ -118,7 +120,7 @@ func TestAccClusterAdvancedCluster_singleProvider(t *testing.T) {
118120
ImportStateIdFunc: testAccCheckMongoDBAtlasClusterImportStateIDFunc(resourceName),
119121
ImportState: true,
120122
ImportStateVerify: true,
121-
ImportStateVerifyIgnore: []string{"replication_specs"},
123+
ImportStateVerifyIgnore: []string{"replication_specs", "retain_backups_enabled"},
122124
},
123125
},
124126
})
@@ -148,6 +150,7 @@ func TestAccClusterAdvancedCluster_multicloud(t *testing.T) {
148150
testAccCheckMongoDBAtlasAdvancedClusterAttributes(&cluster, rName),
149151
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
150152
resource.TestCheckResourceAttr(resourceName, "name", rName),
153+
resource.TestCheckResourceAttr(resourceName, "retain_backups_enabled", "false"),
151154
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"),
152155
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.region_configs.#"),
153156
resource.TestCheckResourceAttrSet(dataSourceClustersName, "results.#"),
@@ -163,6 +166,7 @@ func TestAccClusterAdvancedCluster_multicloud(t *testing.T) {
163166
testAccCheckMongoDBAtlasAdvancedClusterAttributes(&cluster, rNameUpdated),
164167
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
165168
resource.TestCheckResourceAttr(resourceName, "name", rNameUpdated),
169+
resource.TestCheckResourceAttr(resourceName, "retain_backups_enabled", "false"),
166170
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"),
167171
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.region_configs.#"),
168172
resource.TestCheckResourceAttrSet(dataSourceClustersName, "results.#"),
@@ -176,7 +180,7 @@ func TestAccClusterAdvancedCluster_multicloud(t *testing.T) {
176180
ImportStateIdFunc: testAccCheckMongoDBAtlasClusterImportStateIDFunc(resourceName),
177181
ImportState: true,
178182
ImportStateVerify: true,
179-
ImportStateVerifyIgnore: []string{"replication_specs"},
183+
ImportStateVerifyIgnore: []string{"replication_specs", "retain_backups_enabled"},
180184
},
181185
},
182186
})
@@ -660,7 +664,6 @@ resource "mongodbatlas_advanced_cluster" "test" {
660664
project_id = mongodbatlas_project.cluster_project.id
661665
name = %[3]q
662666
cluster_type = "REPLICASET"
663-
retain_backups_enabled = "false"
664667
665668
replication_specs {
666669
region_configs {
@@ -696,7 +699,7 @@ resource "mongodbatlas_advanced_cluster" "test" {
696699
project_id = mongodbatlas_project.cluster_project.id
697700
name = %[3]q
698701
cluster_type = "REPLICASET"
699-
retain_backups_enabled = "false"
702+
retain_backups_enabled = "true"
700703
701704
replication_specs {
702705
region_configs {
@@ -732,6 +735,7 @@ resource "mongodbatlas_advanced_cluster" "test" {
732735
project_id = mongodbatlas_project.cluster_project.id
733736
name = %[3]q
734737
cluster_type = "REPLICASET"
738+
retain_backups_enabled = false
735739
736740
replication_specs {
737741
region_configs {

mongodbatlas/resource_mongodbatlas_cluster.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ func resourceMongoDBAtlasCluster() *schema.Resource {
8585
"retain_backups_enabled": {
8686
Type: schema.TypeBool,
8787
Optional: true,
88-
Default: false,
8988
Description: "Flag that indicates whether to retain backup snapshots for the deleted dedicated cluster",
9089
},
9190
"bi_connector": {
@@ -1022,16 +1021,14 @@ func resourceMongoDBAtlasClusterDelete(ctx context.Context, d *schema.ResourceDa
10221021
projectID := ids["project_id"]
10231022
clusterName := ids["cluster_name"]
10241023

1025-
retainBackup := pointy.Bool(false)
1026-
if v, ok := d.Get("retain_backups_enabled").(bool); ok {
1027-
retainBackup = pointy.Bool(v)
1024+
var options *matlas.DeleteAdvanceClusterOptions
1025+
if v, ok := d.GetOkExists("retain_backups_enabled"); ok {
1026+
options = &matlas.DeleteAdvanceClusterOptions{
1027+
RetainBackups: pointy.Bool(v.(bool)),
1028+
}
10281029
}
10291030

1030-
options := &matlas.DeleteAdvanceClusterOptions{
1031-
RetainBackups: retainBackup,
1032-
}
10331031
_, err := conn.Clusters.Delete(ctx, projectID, clusterName, options)
1034-
10351032
if err != nil {
10361033
return diag.FromErr(fmt.Errorf(errorClusterDelete, clusterName, err))
10371034
}
@@ -1081,10 +1078,6 @@ func resourceMongoDBAtlasClusterImportState(ctx context.Context, d *schema.Resou
10811078
return nil, fmt.Errorf("couldn't import cluster backup configuration %s in project %s, error: %s", *name, *projectID, err)
10821079
}
10831080

1084-
if err := d.Set("retain_backups_enabled", false); err != nil {
1085-
return nil, fmt.Errorf("couldn't import cluster backup configuration %s in project %s, error: %s", *name, *projectID, err)
1086-
}
1087-
10881081
d.SetId(encodeStateID(map[string]string{
10891082
"cluster_id": u.ID,
10901083
"project_id": *projectID,

mongodbatlas/resource_mongodbatlas_cluster_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func TestAccClusterRSCluster_basicAWS_simple(t *testing.T) {
4242
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"),
4343
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.regions_config.#"),
4444
resource.TestCheckResourceAttr(resourceName, "pit_enabled", "true"),
45+
resource.TestCheckResourceAttr(resourceName, "retain_backups_enabled", "true"),
4546
resource.TestCheckResourceAttr(resourceName, "version_release_system", "LTS"),
4647
),
4748
},
@@ -57,6 +58,7 @@ func TestAccClusterRSCluster_basicAWS_simple(t *testing.T) {
5758
resource.TestCheckResourceAttrSet(resourceName, "mongo_uri"),
5859
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"),
5960
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.regions_config.#"),
61+
resource.TestCheckResourceAttr(resourceName, "retain_backups_enabled", "true"),
6062
resource.TestCheckResourceAttr(resourceName, "version_release_system", "LTS"),
6163
),
6264
},
@@ -948,7 +950,7 @@ func TestAccClusterRSCluster_importBasic(t *testing.T) {
948950
resourceName = "mongodbatlas_cluster.test"
949951
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
950952
projectName = acctest.RandomWithPrefix("test-acc")
951-
clusterName = fmt.Sprintf("test-acc-%s", acctest.RandString(10))
953+
clusterName = acctest.RandomWithPrefix("test-acc")
952954
)
953955

954956
resource.ParallelTest(t, resource.TestCase{
@@ -964,7 +966,7 @@ func TestAccClusterRSCluster_importBasic(t *testing.T) {
964966
ImportStateIdFunc: testAccCheckMongoDBAtlasClusterImportStateIDFunc(resourceName),
965967
ImportState: true,
966968
ImportStateVerify: true,
967-
ImportStateVerifyIgnore: []string{"cloud_backup", "provider_backup_enabled"},
969+
ImportStateVerifyIgnore: []string{"cloud_backup", "provider_backup_enabled", "retain_backups_enabled"},
968970
},
969971
},
970972
})
@@ -976,7 +978,7 @@ func TestAccClusterRSCluster_tenant(t *testing.T) {
976978
resourceName = "mongodbatlas_cluster.tenant"
977979
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
978980
projectName = acctest.RandomWithPrefix("test-acc")
979-
name = fmt.Sprintf("test-acc-%s", acctest.RandString(10))
981+
name = acctest.RandomWithPrefix("test-acc")
980982
)
981983

982984
dbMajorVersion := testAccGetMongoDBAtlasMajorVersion()
@@ -1374,7 +1376,7 @@ func testAccMongoDBAtlasClusterConfigAWS(orgID, projectName, name string, backup
13741376
}
13751377
cloud_backup = %[4]t
13761378
pit_enabled = %[4]t
1377-
retain_backups_enabled = false
1379+
retain_backups_enabled = true
13781380
auto_scaling_disk_gb_enabled = %[5]t
13791381
// Provider Settings "block"
13801382

website/docs/r/advanced_cluster.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ Refer to the following for full privatelink endpoint connection string examples:
372372

373373
This parameter defaults to false.
374374

375-
* `retain_backups_enabled` - (Optional) Set to true to retain backup snapshots for the deleted cluster. This parameter defaults to false.
375+
* `retain_backups_enabled` - (Optional) Set to true to retain backup snapshots for the deleted cluster. M10 and above only.
376376

377377
**NOTE** Prior version of provider had parameter as `bi_connector` state will migrate it to new value you only need to update parameter in your terraform file
378378

website/docs/r/cluster.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ But in order to explicitly change `provider_instance_size_name` comment the `lif
324324
```
325325
* The default value is false. M10 and above only.
326326

327-
* `retain_backups_enabled` - (Optional) Set to true to retain backup snapshots for the deleted cluster. The default value is false. M10 and above only.
327+
* `retain_backups_enabled` - (Optional) Set to true to retain backup snapshots for the deleted cluster. M10 and above only.
328328
* `bi_connector` - (Optional) Specifies BI Connector for Atlas configuration on this cluster. BI Connector for Atlas is only available for M10+ clusters. See [BI Connector](#bi-connector) below for more details. **DEPRECATED** Use `bi_connector_config` instead.
329329
* `bi_connector_config` - (Optional) Specifies BI Connector for Atlas configuration on this cluster. BI Connector for Atlas is only available for M10+ clusters. See [BI Connector](#bi-connector) below for more details.
330330
* `cluster_type` - (Required) Specifies the type of the cluster that you want to modify. You cannot convert a sharded cluster deployment to a replica set deployment.

0 commit comments

Comments
 (0)