Skip to content

Commit 3b31e66

Browse files
authored
INTMDB-444: Add support for termination protection enabled feature (#912)
* Initial commit of termination_protection_enabled support * Lint dead code removal
1 parent bbf72f0 commit 3b31e66

28 files changed

+164
-27
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/mwielbut/pointy v1.1.0
1212
github.com/spf13/cast v1.5.0
1313
github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20210625132053-af2d5c0ad54f
14-
go.mongodb.org/atlas v0.18.1-0.20221026132354-ca26a1fdb0a6
14+
go.mongodb.org/atlas v0.18.1-0.20221109142841-f9f8ebe7b9b9
1515
go.mongodb.org/realm v0.1.0
1616
)
1717

go.sum

+10
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,16 @@ go.mongodb.org/atlas v0.16.1-0.20220922005646-8a86dd63e243 h1:KkZ900dLCu2U3D+qoY
933933
go.mongodb.org/atlas v0.16.1-0.20220922005646-8a86dd63e243/go.mod h1:GUuW7/ZrHzCO0o47aiqhokN0N6i0GM3yraRyHIBTykU=
934934
go.mongodb.org/atlas v0.18.1-0.20221026132354-ca26a1fdb0a6 h1:lGmbUUTcdfXt0O1QN2z65B3mAYrUXUerqj3RZWg7Aao=
935935
go.mongodb.org/atlas v0.18.1-0.20221026132354-ca26a1fdb0a6/go.mod h1:PFk1IGhiGjFXHGVspOK7i1U2nnPjK8wAjYwQf6FoVf4=
936+
go.mongodb.org/atlas v0.18.1-0.20221108205600-df069600ea0e h1:2tJAuArFEru/aH3eZhfq8ZU7qv1DzgWp0FTYOYO9X0E=
937+
go.mongodb.org/atlas v0.18.1-0.20221108205600-df069600ea0e/go.mod h1:PFk1IGhiGjFXHGVspOK7i1U2nnPjK8wAjYwQf6FoVf4=
938+
go.mongodb.org/atlas v0.18.1-0.20221109004135-a08842cb4521 h1:gWLG7xNkgiFEw3PQo/0Jnp2MkDwDbYu6svMEET8IBFs=
939+
go.mongodb.org/atlas v0.18.1-0.20221109004135-a08842cb4521/go.mod h1:PFk1IGhiGjFXHGVspOK7i1U2nnPjK8wAjYwQf6FoVf4=
940+
go.mongodb.org/atlas v0.18.1-0.20221109012729-5270d3048e93 h1:i8sFIUYNTakDMxvtak2NEGVnqEWyfB5DYt1aW33IJ2M=
941+
go.mongodb.org/atlas v0.18.1-0.20221109012729-5270d3048e93/go.mod h1:PFk1IGhiGjFXHGVspOK7i1U2nnPjK8wAjYwQf6FoVf4=
942+
go.mongodb.org/atlas v0.18.1-0.20221109025158-49b06badf4a1 h1:sebMdTAFJSPMXidhUg/9D48xFzsHvvNrF3A2plPymmA=
943+
go.mongodb.org/atlas v0.18.1-0.20221109025158-49b06badf4a1/go.mod h1:PFk1IGhiGjFXHGVspOK7i1U2nnPjK8wAjYwQf6FoVf4=
944+
go.mongodb.org/atlas v0.18.1-0.20221109142841-f9f8ebe7b9b9 h1:9m35o4kyRYjwbsIb/lPrjxJ6afPpn9zwOF5i3SIY5Lg=
945+
go.mongodb.org/atlas v0.18.1-0.20221109142841-f9f8ebe7b9b9/go.mod h1:PFk1IGhiGjFXHGVspOK7i1U2nnPjK8wAjYwQf6FoVf4=
936946
go.mongodb.org/realm v0.1.0 h1:zJiXyLaZrznQ+Pz947ziSrDKUep39DO4SfA0Fzx8M4M=
937947
go.mongodb.org/realm v0.1.0/go.mod h1:4Vj6iy+Puo1TDERcoh4XZ+pjtwbOzPpzqy3Cwe8ZmDM=
938948
go.mozilla.org/mozlog v0.0.0-20170222151521-4bb13139d403/go.mod h1:jHoPAGnDrCy6kaI2tAze5Prf0Nr0w/oNkROt2lw3n3o=

mongodbatlas/data_source_mongodbatlas_advanced_cluster.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ func dataSourceMongoDBAtlasAdvancedCluster() *schema.Resource {
185185
Type: schema.TypeString,
186186
Computed: true,
187187
},
188+
"termination_protection_enabled": {
189+
Type: schema.TypeBool,
190+
Computed: true,
191+
},
188192
"version_release_system": {
189193
Type: schema.TypeString,
190194
Computed: true,
@@ -276,7 +280,9 @@ func dataSourceMongoDBAtlasAdvancedClusterRead(ctx context.Context, d *schema.Re
276280
if err := d.Set("state_name", cluster.StateName); err != nil {
277281
return diag.FromErr(fmt.Errorf(errorClusterAdvancedSetting, "state_name", clusterName, err))
278282
}
279-
283+
if err := d.Set("termination_protection_enabled", cluster.TerminationProtectionEnabled); err != nil {
284+
return diag.FromErr(fmt.Errorf(errorClusterAdvancedSetting, "termination_protection_enabled", clusterName, err))
285+
}
280286
if err := d.Set("version_release_system", cluster.VersionReleaseSystem); err != nil {
281287
return diag.FromErr(fmt.Errorf(errorClusterAdvancedSetting, "version_release_system", clusterName, err))
282288
}

mongodbatlas/data_source_mongodbatlas_advanced_cluster_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func TestAccDataSourceMongoDBAtlasAdvancedCluster_basic(t *testing.T) {
3636
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.region_configs.#"),
3737
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
3838
resource.TestCheckResourceAttr(dataSourceName, "name", name),
39+
resource.TestCheckResourceAttr(dataSourceName, "termination_protection_enabled", "false"),
3940
),
4041
},
4142
},

mongodbatlas/data_source_mongodbatlas_advanced_clusters.go

+23-18
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ func dataSourceMongoDBAtlasAdvancedClusters() *schema.Resource {
193193
Type: schema.TypeString,
194194
Computed: true,
195195
},
196+
"termination_protection_enabled": {
197+
Type: schema.TypeBool,
198+
Computed: true,
199+
},
196200
"version_release_system": {
197201
Type: schema.TypeString,
198202
Computed: true,
@@ -240,24 +244,25 @@ func flattenAdvancedClusters(ctx context.Context, conn *matlas.Client, clusters
240244
}
241245

242246
result := map[string]interface{}{
243-
"advanced_configuration": flattenProcessArgs(processArgs),
244-
"backup_enabled": clusters[i].BackupEnabled,
245-
"bi_connector": flattenBiConnectorConfig(clusters[i].BiConnector),
246-
"cluster_type": clusters[i].ClusterType,
247-
"create_date": clusters[i].CreateDate,
248-
"connection_strings": flattenConnectionStrings(clusters[i].ConnectionStrings),
249-
"disk_size_gb": clusters[i].DiskSizeGB,
250-
"encryption_at_rest_provider": clusters[i].EncryptionAtRestProvider,
251-
"labels": flattenLabels(clusters[i].Labels),
252-
"mongo_db_major_version": clusters[i].MongoDBMajorVersion,
253-
"mongo_db_version": clusters[i].MongoDBVersion,
254-
"name": clusters[i].Name,
255-
"paused": clusters[i].Paused,
256-
"pit_enabled": clusters[i].PitEnabled,
257-
"replication_specs": replicationSpecs,
258-
"root_cert_type": clusters[i].RootCertType,
259-
"state_name": clusters[i].StateName,
260-
"version_release_system": clusters[i].VersionReleaseSystem,
247+
"advanced_configuration": flattenProcessArgs(processArgs),
248+
"backup_enabled": clusters[i].BackupEnabled,
249+
"bi_connector": flattenBiConnectorConfig(clusters[i].BiConnector),
250+
"cluster_type": clusters[i].ClusterType,
251+
"create_date": clusters[i].CreateDate,
252+
"connection_strings": flattenConnectionStrings(clusters[i].ConnectionStrings),
253+
"disk_size_gb": clusters[i].DiskSizeGB,
254+
"encryption_at_rest_provider": clusters[i].EncryptionAtRestProvider,
255+
"labels": flattenLabels(clusters[i].Labels),
256+
"mongo_db_major_version": clusters[i].MongoDBMajorVersion,
257+
"mongo_db_version": clusters[i].MongoDBVersion,
258+
"name": clusters[i].Name,
259+
"paused": clusters[i].Paused,
260+
"pit_enabled": clusters[i].PitEnabled,
261+
"replication_specs": replicationSpecs,
262+
"root_cert_type": clusters[i].RootCertType,
263+
"state_name": clusters[i].StateName,
264+
"termination_protection_enabled": clusters[i].TerminationProtectionEnabled,
265+
"version_release_system": clusters[i].VersionReleaseSystem,
261266
}
262267
results = append(results, result)
263268
}

mongodbatlas/data_source_mongodbatlas_advanced_clusters_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func TestAccDataSourceMongoDBAtlasAdvancedClusters_basic(t *testing.T) {
3838
resource.TestCheckResourceAttrSet(dataSourceName, "results.#"),
3939
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.replication_specs.#"),
4040
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.name"),
41+
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.termination_protection_enabled"),
4142
),
4243
},
4344
},

mongodbatlas/data_source_mongodbatlas_cluster.go

+8
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ func dataSourceMongoDBAtlasCluster() *schema.Resource {
308308
Type: schema.TypeString,
309309
Computed: true,
310310
},
311+
"termination_protection_enabled": {
312+
Type: schema.TypeBool,
313+
Computed: true,
314+
},
311315
"version_release_system": {
312316
Type: schema.TypeString,
313317
Computed: true,
@@ -442,6 +446,10 @@ func dataSourceMongoDBAtlasClusterRead(ctx context.Context, d *schema.ResourceDa
442446
return diag.FromErr(fmt.Errorf(errorClusterSetting, "labels", clusterName, err))
443447
}
444448

449+
if err := d.Set("termination_protection_enabled", cluster.TerminationProtectionEnabled); err != nil {
450+
return diag.FromErr(fmt.Errorf(errorClusterSetting, "termination_protection_enabled", clusterName, err))
451+
}
452+
445453
if err := d.Set("version_release_system", cluster.VersionReleaseSystem); err != nil {
446454
return diag.FromErr(fmt.Errorf(errorClusterSetting, "version_release_system", clusterName, err))
447455
}

mongodbatlas/data_source_mongodbatlas_cluster_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func TestAccDataSourceMongoDBAtlasCluster_basic(t *testing.T) {
5252
resource.TestCheckResourceAttr(dataSourceName, "provider_auto_scaling_compute_min_instance_size", minSizeInstance),
5353
resource.TestCheckResourceAttr(dataSourceName, "provider_auto_scaling_compute_max_instance_size", maxSizeInstance),
5454
resource.TestCheckResourceAttr(dataSourceName, "version_release_system", "LTS"),
55+
resource.TestCheckResourceAttr(dataSourceName, "termination_protection_enabled", "false"),
5556
),
5657
},
5758
},

mongodbatlas/data_source_mongodbatlas_clusters.go

+5
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ func dataSourceMongoDBAtlasClusters() *schema.Resource {
315315
Type: schema.TypeString,
316316
Computed: true,
317317
},
318+
"termination_protection_enabled": {
319+
Type: schema.TypeBool,
320+
Computed: true,
321+
},
318322
},
319323
},
320324
},
@@ -403,6 +407,7 @@ func flattenClusters(ctx context.Context, d *schema.ResourceData, conn *matlas.C
403407
"replication_specs": flattenReplicationSpecs(clusters[i].ReplicationSpecs),
404408
"labels": flattenLabels(clusters[i].Labels),
405409
"snapshot_backup_policy": snapshotBackupPolicy,
410+
"termination_protection_enabled": clusters[i].TerminationProtectionEnabled,
406411
"version_release_system": clusters[i].VersionReleaseSystem,
407412
"container_id": containerID,
408413
}

mongodbatlas/data_source_mongodbatlas_clusters_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func TestAccDataSourceMongoDBAtlasClusters_basic(t *testing.T) {
4343
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.replication_specs.#"),
4444
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.name"),
4545
resource.TestCheckResourceAttr(dataSourceName, "results.0.version_release_system", "LTS"),
46+
resource.TestCheckResourceAttr(dataSourceName, "results.0.termination_protection_enabled", "false"),
4647
),
4748
},
4849
},

mongodbatlas/data_source_mongodbatlas_serverless_instance.go

+8
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ func dataSourceMongoDBAtlasServerlessInstanceRead(ctx context.Context, d *schema
6666
return diag.Errorf("error setting `state_name` for serverless instance (%s): %s", d.Id(), err)
6767
}
6868

69+
if err := d.Set("termination_protection_enabled", serverlessInstance.TerminationProtectionEnabled); err != nil {
70+
return diag.Errorf("error setting `termination_protection_enabled` for serverless instance (%s): %s", d.Id(), err)
71+
}
72+
6973
if err := d.Set("continuous_backup_enabled", serverlessInstance.ServerlessBackupOptions.ServerlessContinuousBackupEnabled); err != nil {
7074
return diag.Errorf("error setting `state_name` for serverless instance (%s): %s", d.Id(), err)
7175
}
@@ -137,6 +141,10 @@ func returnServerlessInstanceDSSchema() map[string]*schema.Schema {
137141
Optional: true,
138142
Computed: true,
139143
},
144+
"termination_protection_enabled": {
145+
Type: schema.TypeBool,
146+
Computed: true,
147+
},
140148
"continuous_backup_enabled": {
141149
Type: schema.TypeBool,
142150
Optional: true,

mongodbatlas/data_source_mongodbatlas_serverless_instance_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestAccDataSourceMongoDBAtlasServerlessInstance_byName(t *testing.T) {
3030
resource.TestCheckResourceAttrSet(datasourceName, "create_date"),
3131
resource.TestCheckResourceAttrSet(datasourceName, "mongo_db_version"),
3232
resource.TestCheckResourceAttrSet(datasourceName, "continuous_backup_enabled"),
33+
resource.TestCheckResourceAttrSet(datasourceName, "termination_protection_enabled"),
3334
),
3435
},
3536
},

mongodbatlas/data_source_mongodbatlas_serverless_instances.go

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func flattenServerlessInstances(serverlessInstances []*matlas.Cluster) []map[str
102102
"provider_settings_region_name": serverlessInstances[i].ProviderSettings.RegionName,
103103
"provider_settings_provider_name": serverlessInstances[i].ProviderSettings.ProviderName,
104104
"state_name": serverlessInstances[i].StateName,
105+
"termination_protection_enabled": serverlessInstances[i].TerminationProtectionEnabled,
105106
"continuous_backup_enabled": serverlessInstances[i].ServerlessBackupOptions.ServerlessContinuousBackupEnabled,
106107
}
107108
}

mongodbatlas/data_source_mongodbatlas_serverless_instances_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestAccDataSourceMongoDBAtlasServerlessInstances_basic(t *testing.T) {
3030
resource.TestCheckResourceAttrSet(datasourceName, "results.0.name"),
3131
resource.TestCheckResourceAttrSet(datasourceName, "results.0.state_name"),
3232
resource.TestCheckResourceAttrSet(datasourceName, "results.0.continuous_backup_enabled"),
33+
resource.TestCheckResourceAttrSet(datasourceName, "results.0.termination_protection_enabled"),
3334
),
3435
},
3536
},

mongodbatlas/resource_mongodbatlas_advanced_cluster.go

+16
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ func resourceMongoDBAtlasAdvancedCluster() *schema.Resource {
251251
Type: schema.TypeString,
252252
Computed: true,
253253
},
254+
"termination_protection_enabled": {
255+
Type: schema.TypeBool,
256+
Optional: true,
257+
Computed: true,
258+
},
254259
"version_release_system": {
255260
Type: schema.TypeString,
256261
Optional: true,
@@ -333,6 +338,9 @@ func resourceMongoDBAtlasAdvancedClusterCreate(ctx context.Context, d *schema.Re
333338
if v, ok := d.GetOk("root_cert_type"); ok {
334339
request.RootCertType = v.(string)
335340
}
341+
if v, ok := d.GetOk("termination_protection_enabled"); ok {
342+
request.TerminationProtectionEnabled = pointy.Bool(v.(bool))
343+
}
336344
if v, ok := d.GetOk("version_release_system"); ok {
337345
request.VersionReleaseSystem = v.(string)
338346
}
@@ -494,6 +502,10 @@ func resourceMongoDBAtlasAdvancedClusterRead(ctx context.Context, d *schema.Reso
494502
return diag.FromErr(fmt.Errorf(errorClusterAdvancedSetting, "state_name", clusterName, err))
495503
}
496504

505+
if err := d.Set("termination_protection_enabled", cluster.TerminationProtectionEnabled); err != nil {
506+
return diag.FromErr(fmt.Errorf(errorClusterAdvancedSetting, "termination_protection_enabled", clusterName, err))
507+
}
508+
497509
if err := d.Set("version_release_system", cluster.VersionReleaseSystem); err != nil {
498510
return diag.FromErr(fmt.Errorf(errorClusterAdvancedSetting, "version_release_system", clusterName, err))
499511
}
@@ -602,6 +614,10 @@ func resourceMongoDBAtlasAdvancedClusterUpdate(ctx context.Context, d *schema.Re
602614
cluster.RootCertType = d.Get("root_cert_type").(string)
603615
}
604616

617+
if d.HasChange("termination_protection_enabled") {
618+
cluster.TerminationProtectionEnabled = pointy.Bool(d.Get("termination_protection_enabled").(bool))
619+
}
620+
605621
if d.HasChange("version_release_system") {
606622
cluster.VersionReleaseSystem = d.Get("version_release_system").(string)
607623
}

mongodbatlas/resource_mongodbatlas_advanced_cluster_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func TestAccResourceMongoDBAtlasAdvancedCluster_basicTenant(t *testing.T) {
3737
resource.TestCheckResourceAttr(resourceName, "name", rName),
3838
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"),
3939
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.region_configs.#"),
40+
resource.TestCheckResourceAttrSet(resourceName, "termination_protection_enabled"),
4041
),
4142
},
4243
{

mongodbatlas/resource_mongodbatlas_cluster.go

+17
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ func resourceMongoDBAtlasCluster() *schema.Resource {
341341
},
342342
},
343343
"snapshot_backup_policy": computedCloudProviderSnapshotBackupPolicySchema(),
344+
"termination_protection_enabled": {
345+
Type: schema.TypeBool,
346+
Optional: true,
347+
Computed: true,
348+
},
344349
"container_id": {
345350
Type: schema.TypeString,
346351
Computed: true,
@@ -528,6 +533,10 @@ func resourceMongoDBAtlasClusterCreate(ctx context.Context, d *schema.ResourceDa
528533
clusterRequest.NumShards = pointy.Int64(cast.ToInt64(n))
529534
}
530535

536+
if v, ok := d.GetOk("termination_protection_enabled"); ok {
537+
clusterRequest.TerminationProtectionEnabled = pointy.Bool(v.(bool))
538+
}
539+
531540
if v, ok := d.GetOk("version_release_system"); ok {
532541
clusterRequest.VersionReleaseSystem = v.(string)
533542
}
@@ -705,6 +714,10 @@ func resourceMongoDBAtlasClusterRead(ctx context.Context, d *schema.ResourceData
705714
return diag.FromErr(fmt.Errorf(errorClusterSetting, "state_name", clusterName, err))
706715
}
707716

717+
if err := d.Set("termination_protection_enabled", cluster.TerminationProtectionEnabled); err != nil {
718+
return diag.FromErr(fmt.Errorf(errorClusterSetting, "termination_protection_enabled", clusterName, err))
719+
}
720+
708721
if _, ok := d.GetOk("bi_connector"); ok {
709722
if err = d.Set("bi_connector", flattenBiConnector(cluster.BiConnector)); err != nil {
710723
return diag.FromErr(fmt.Errorf(errorClusterSetting, "bi_connector", clusterName, err))
@@ -882,6 +895,10 @@ func resourceMongoDBAtlasClusterUpdate(ctx context.Context, d *schema.ResourceDa
882895
cluster.VersionReleaseSystem = d.Get("version_release_system").(string)
883896
}
884897

898+
if d.HasChange("termination_protection_enabled") {
899+
cluster.TerminationProtectionEnabled = pointy.Bool(d.Get("termination_protection_enabled").(bool))
900+
}
901+
885902
if d.HasChange("labels") {
886903
if containsLabelOrKey(expandLabelSliceFromSetSchema(d), defaultLabel) {
887904
return diag.FromErr(fmt.Errorf("you should not set `Infrastructure Tool` label, it is used for internal purposes"))

0 commit comments

Comments
 (0)