Skip to content

INTMDB-444: Add support for termination protection enabled feature #912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/mwielbut/pointy v1.1.0
github.com/spf13/cast v1.5.0
github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20210625132053-af2d5c0ad54f
go.mongodb.org/atlas v0.18.1-0.20221026132354-ca26a1fdb0a6
go.mongodb.org/atlas v0.18.1-0.20221109142841-f9f8ebe7b9b9
go.mongodb.org/realm v0.1.0
)

Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,16 @@ go.mongodb.org/atlas v0.16.1-0.20220922005646-8a86dd63e243 h1:KkZ900dLCu2U3D+qoY
go.mongodb.org/atlas v0.16.1-0.20220922005646-8a86dd63e243/go.mod h1:GUuW7/ZrHzCO0o47aiqhokN0N6i0GM3yraRyHIBTykU=
go.mongodb.org/atlas v0.18.1-0.20221026132354-ca26a1fdb0a6 h1:lGmbUUTcdfXt0O1QN2z65B3mAYrUXUerqj3RZWg7Aao=
go.mongodb.org/atlas v0.18.1-0.20221026132354-ca26a1fdb0a6/go.mod h1:PFk1IGhiGjFXHGVspOK7i1U2nnPjK8wAjYwQf6FoVf4=
go.mongodb.org/atlas v0.18.1-0.20221108205600-df069600ea0e h1:2tJAuArFEru/aH3eZhfq8ZU7qv1DzgWp0FTYOYO9X0E=
go.mongodb.org/atlas v0.18.1-0.20221108205600-df069600ea0e/go.mod h1:PFk1IGhiGjFXHGVspOK7i1U2nnPjK8wAjYwQf6FoVf4=
go.mongodb.org/atlas v0.18.1-0.20221109004135-a08842cb4521 h1:gWLG7xNkgiFEw3PQo/0Jnp2MkDwDbYu6svMEET8IBFs=
go.mongodb.org/atlas v0.18.1-0.20221109004135-a08842cb4521/go.mod h1:PFk1IGhiGjFXHGVspOK7i1U2nnPjK8wAjYwQf6FoVf4=
go.mongodb.org/atlas v0.18.1-0.20221109012729-5270d3048e93 h1:i8sFIUYNTakDMxvtak2NEGVnqEWyfB5DYt1aW33IJ2M=
go.mongodb.org/atlas v0.18.1-0.20221109012729-5270d3048e93/go.mod h1:PFk1IGhiGjFXHGVspOK7i1U2nnPjK8wAjYwQf6FoVf4=
go.mongodb.org/atlas v0.18.1-0.20221109025158-49b06badf4a1 h1:sebMdTAFJSPMXidhUg/9D48xFzsHvvNrF3A2plPymmA=
go.mongodb.org/atlas v0.18.1-0.20221109025158-49b06badf4a1/go.mod h1:PFk1IGhiGjFXHGVspOK7i1U2nnPjK8wAjYwQf6FoVf4=
go.mongodb.org/atlas v0.18.1-0.20221109142841-f9f8ebe7b9b9 h1:9m35o4kyRYjwbsIb/lPrjxJ6afPpn9zwOF5i3SIY5Lg=
go.mongodb.org/atlas v0.18.1-0.20221109142841-f9f8ebe7b9b9/go.mod h1:PFk1IGhiGjFXHGVspOK7i1U2nnPjK8wAjYwQf6FoVf4=
go.mongodb.org/realm v0.1.0 h1:zJiXyLaZrznQ+Pz947ziSrDKUep39DO4SfA0Fzx8M4M=
go.mongodb.org/realm v0.1.0/go.mod h1:4Vj6iy+Puo1TDERcoh4XZ+pjtwbOzPpzqy3Cwe8ZmDM=
go.mozilla.org/mozlog v0.0.0-20170222151521-4bb13139d403/go.mod h1:jHoPAGnDrCy6kaI2tAze5Prf0Nr0w/oNkROt2lw3n3o=
Expand Down
8 changes: 7 additions & 1 deletion mongodbatlas/data_source_mongodbatlas_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ func dataSourceMongoDBAtlasAdvancedCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"termination_protection_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"version_release_system": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -276,7 +280,9 @@ func dataSourceMongoDBAtlasAdvancedClusterRead(ctx context.Context, d *schema.Re
if err := d.Set("state_name", cluster.StateName); err != nil {
return diag.FromErr(fmt.Errorf(errorClusterAdvancedSetting, "state_name", clusterName, err))
}

if err := d.Set("termination_protection_enabled", cluster.TerminationProtectionEnabled); err != nil {
return diag.FromErr(fmt.Errorf(errorClusterAdvancedSetting, "termination_protection_enabled", clusterName, err))
}
if err := d.Set("version_release_system", cluster.VersionReleaseSystem); err != nil {
return diag.FromErr(fmt.Errorf(errorClusterAdvancedSetting, "version_release_system", clusterName, err))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestAccDataSourceMongoDBAtlasAdvancedCluster_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.region_configs.#"),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(dataSourceName, "name", name),
resource.TestCheckResourceAttr(dataSourceName, "termination_protection_enabled", "false"),
),
},
},
Expand Down
41 changes: 23 additions & 18 deletions mongodbatlas/data_source_mongodbatlas_advanced_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ func dataSourceMongoDBAtlasAdvancedClusters() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"termination_protection_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"version_release_system": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -240,24 +244,25 @@ func flattenAdvancedClusters(ctx context.Context, conn *matlas.Client, clusters
}

result := map[string]interface{}{
"advanced_configuration": flattenProcessArgs(processArgs),
"backup_enabled": clusters[i].BackupEnabled,
"bi_connector": flattenBiConnectorConfig(clusters[i].BiConnector),
"cluster_type": clusters[i].ClusterType,
"create_date": clusters[i].CreateDate,
"connection_strings": flattenConnectionStrings(clusters[i].ConnectionStrings),
"disk_size_gb": clusters[i].DiskSizeGB,
"encryption_at_rest_provider": clusters[i].EncryptionAtRestProvider,
"labels": flattenLabels(clusters[i].Labels),
"mongo_db_major_version": clusters[i].MongoDBMajorVersion,
"mongo_db_version": clusters[i].MongoDBVersion,
"name": clusters[i].Name,
"paused": clusters[i].Paused,
"pit_enabled": clusters[i].PitEnabled,
"replication_specs": replicationSpecs,
"root_cert_type": clusters[i].RootCertType,
"state_name": clusters[i].StateName,
"version_release_system": clusters[i].VersionReleaseSystem,
"advanced_configuration": flattenProcessArgs(processArgs),
"backup_enabled": clusters[i].BackupEnabled,
"bi_connector": flattenBiConnectorConfig(clusters[i].BiConnector),
"cluster_type": clusters[i].ClusterType,
"create_date": clusters[i].CreateDate,
"connection_strings": flattenConnectionStrings(clusters[i].ConnectionStrings),
"disk_size_gb": clusters[i].DiskSizeGB,
"encryption_at_rest_provider": clusters[i].EncryptionAtRestProvider,
"labels": flattenLabels(clusters[i].Labels),
"mongo_db_major_version": clusters[i].MongoDBMajorVersion,
"mongo_db_version": clusters[i].MongoDBVersion,
"name": clusters[i].Name,
"paused": clusters[i].Paused,
"pit_enabled": clusters[i].PitEnabled,
"replication_specs": replicationSpecs,
"root_cert_type": clusters[i].RootCertType,
"state_name": clusters[i].StateName,
"termination_protection_enabled": clusters[i].TerminationProtectionEnabled,
"version_release_system": clusters[i].VersionReleaseSystem,
}
results = append(results, result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestAccDataSourceMongoDBAtlasAdvancedClusters_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(dataSourceName, "results.#"),
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.replication_specs.#"),
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.name"),
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.termination_protection_enabled"),
),
},
},
Expand Down
8 changes: 8 additions & 0 deletions mongodbatlas/data_source_mongodbatlas_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ func dataSourceMongoDBAtlasCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"termination_protection_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"version_release_system": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -442,6 +446,10 @@ func dataSourceMongoDBAtlasClusterRead(ctx context.Context, d *schema.ResourceDa
return diag.FromErr(fmt.Errorf(errorClusterSetting, "labels", clusterName, err))
}

if err := d.Set("termination_protection_enabled", cluster.TerminationProtectionEnabled); err != nil {
return diag.FromErr(fmt.Errorf(errorClusterSetting, "termination_protection_enabled", clusterName, err))
}

if err := d.Set("version_release_system", cluster.VersionReleaseSystem); err != nil {
return diag.FromErr(fmt.Errorf(errorClusterSetting, "version_release_system", clusterName, err))
}
Expand Down
1 change: 1 addition & 0 deletions mongodbatlas/data_source_mongodbatlas_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestAccDataSourceMongoDBAtlasCluster_basic(t *testing.T) {
resource.TestCheckResourceAttr(dataSourceName, "provider_auto_scaling_compute_min_instance_size", minSizeInstance),
resource.TestCheckResourceAttr(dataSourceName, "provider_auto_scaling_compute_max_instance_size", maxSizeInstance),
resource.TestCheckResourceAttr(dataSourceName, "version_release_system", "LTS"),
resource.TestCheckResourceAttr(dataSourceName, "termination_protection_enabled", "false"),
),
},
},
Expand Down
5 changes: 5 additions & 0 deletions mongodbatlas/data_source_mongodbatlas_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ func dataSourceMongoDBAtlasClusters() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"termination_protection_enabled": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -403,6 +407,7 @@ func flattenClusters(ctx context.Context, d *schema.ResourceData, conn *matlas.C
"replication_specs": flattenReplicationSpecs(clusters[i].ReplicationSpecs),
"labels": flattenLabels(clusters[i].Labels),
"snapshot_backup_policy": snapshotBackupPolicy,
"termination_protection_enabled": clusters[i].TerminationProtectionEnabled,
"version_release_system": clusters[i].VersionReleaseSystem,
"container_id": containerID,
}
Expand Down
1 change: 1 addition & 0 deletions mongodbatlas/data_source_mongodbatlas_clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestAccDataSourceMongoDBAtlasClusters_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.replication_specs.#"),
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.name"),
resource.TestCheckResourceAttr(dataSourceName, "results.0.version_release_system", "LTS"),
resource.TestCheckResourceAttr(dataSourceName, "results.0.termination_protection_enabled", "false"),
),
},
},
Expand Down
8 changes: 8 additions & 0 deletions mongodbatlas/data_source_mongodbatlas_serverless_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func dataSourceMongoDBAtlasServerlessInstanceRead(ctx context.Context, d *schema
return diag.Errorf("error setting `state_name` for serverless instance (%s): %s", d.Id(), err)
}

if err := d.Set("termination_protection_enabled", serverlessInstance.TerminationProtectionEnabled); err != nil {
return diag.Errorf("error setting `termination_protection_enabled` for serverless instance (%s): %s", d.Id(), err)
}

if err := d.Set("continuous_backup_enabled", serverlessInstance.ServerlessBackupOptions.ServerlessContinuousBackupEnabled); err != nil {
return diag.Errorf("error setting `state_name` for serverless instance (%s): %s", d.Id(), err)
}
Expand Down Expand Up @@ -137,6 +141,10 @@ func returnServerlessInstanceDSSchema() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"termination_protection_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"continuous_backup_enabled": {
Type: schema.TypeBool,
Optional: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestAccDataSourceMongoDBAtlasServerlessInstance_byName(t *testing.T) {
resource.TestCheckResourceAttrSet(datasourceName, "create_date"),
resource.TestCheckResourceAttrSet(datasourceName, "mongo_db_version"),
resource.TestCheckResourceAttrSet(datasourceName, "continuous_backup_enabled"),
resource.TestCheckResourceAttrSet(datasourceName, "termination_protection_enabled"),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func flattenServerlessInstances(serverlessInstances []*matlas.Cluster) []map[str
"provider_settings_region_name": serverlessInstances[i].ProviderSettings.RegionName,
"provider_settings_provider_name": serverlessInstances[i].ProviderSettings.ProviderName,
"state_name": serverlessInstances[i].StateName,
"termination_protection_enabled": serverlessInstances[i].TerminationProtectionEnabled,
"continuous_backup_enabled": serverlessInstances[i].ServerlessBackupOptions.ServerlessContinuousBackupEnabled,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestAccDataSourceMongoDBAtlasServerlessInstances_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(datasourceName, "results.0.name"),
resource.TestCheckResourceAttrSet(datasourceName, "results.0.state_name"),
resource.TestCheckResourceAttrSet(datasourceName, "results.0.continuous_backup_enabled"),
resource.TestCheckResourceAttrSet(datasourceName, "results.0.termination_protection_enabled"),
),
},
},
Expand Down
16 changes: 16 additions & 0 deletions mongodbatlas/resource_mongodbatlas_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ func resourceMongoDBAtlasAdvancedCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"termination_protection_enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"version_release_system": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -333,6 +338,9 @@ func resourceMongoDBAtlasAdvancedClusterCreate(ctx context.Context, d *schema.Re
if v, ok := d.GetOk("root_cert_type"); ok {
request.RootCertType = v.(string)
}
if v, ok := d.GetOk("termination_protection_enabled"); ok {
request.TerminationProtectionEnabled = pointy.Bool(v.(bool))
}
if v, ok := d.GetOk("version_release_system"); ok {
request.VersionReleaseSystem = v.(string)
}
Expand Down Expand Up @@ -494,6 +502,10 @@ func resourceMongoDBAtlasAdvancedClusterRead(ctx context.Context, d *schema.Reso
return diag.FromErr(fmt.Errorf(errorClusterAdvancedSetting, "state_name", clusterName, err))
}

if err := d.Set("termination_protection_enabled", cluster.TerminationProtectionEnabled); err != nil {
return diag.FromErr(fmt.Errorf(errorClusterAdvancedSetting, "termination_protection_enabled", clusterName, err))
}

if err := d.Set("version_release_system", cluster.VersionReleaseSystem); err != nil {
return diag.FromErr(fmt.Errorf(errorClusterAdvancedSetting, "version_release_system", clusterName, err))
}
Expand Down Expand Up @@ -602,6 +614,10 @@ func resourceMongoDBAtlasAdvancedClusterUpdate(ctx context.Context, d *schema.Re
cluster.RootCertType = d.Get("root_cert_type").(string)
}

if d.HasChange("termination_protection_enabled") {
cluster.TerminationProtectionEnabled = pointy.Bool(d.Get("termination_protection_enabled").(bool))
}

if d.HasChange("version_release_system") {
cluster.VersionReleaseSystem = d.Get("version_release_system").(string)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestAccResourceMongoDBAtlasAdvancedCluster_basicTenant(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"),
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.region_configs.#"),
resource.TestCheckResourceAttrSet(resourceName, "termination_protection_enabled"),
),
},
{
Expand Down
17 changes: 17 additions & 0 deletions mongodbatlas/resource_mongodbatlas_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ func resourceMongoDBAtlasCluster() *schema.Resource {
},
},
"snapshot_backup_policy": computedCloudProviderSnapshotBackupPolicySchema(),
"termination_protection_enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"container_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -528,6 +533,10 @@ func resourceMongoDBAtlasClusterCreate(ctx context.Context, d *schema.ResourceDa
clusterRequest.NumShards = pointy.Int64(cast.ToInt64(n))
}

if v, ok := d.GetOk("termination_protection_enabled"); ok {
clusterRequest.TerminationProtectionEnabled = pointy.Bool(v.(bool))
}

if v, ok := d.GetOk("version_release_system"); ok {
clusterRequest.VersionReleaseSystem = v.(string)
}
Expand Down Expand Up @@ -705,6 +714,10 @@ func resourceMongoDBAtlasClusterRead(ctx context.Context, d *schema.ResourceData
return diag.FromErr(fmt.Errorf(errorClusterSetting, "state_name", clusterName, err))
}

if err := d.Set("termination_protection_enabled", cluster.TerminationProtectionEnabled); err != nil {
return diag.FromErr(fmt.Errorf(errorClusterSetting, "termination_protection_enabled", clusterName, err))
}

if _, ok := d.GetOk("bi_connector"); ok {
if err = d.Set("bi_connector", flattenBiConnector(cluster.BiConnector)); err != nil {
return diag.FromErr(fmt.Errorf(errorClusterSetting, "bi_connector", clusterName, err))
Expand Down Expand Up @@ -882,6 +895,10 @@ func resourceMongoDBAtlasClusterUpdate(ctx context.Context, d *schema.ResourceDa
cluster.VersionReleaseSystem = d.Get("version_release_system").(string)
}

if d.HasChange("termination_protection_enabled") {
cluster.TerminationProtectionEnabled = pointy.Bool(d.Get("termination_protection_enabled").(bool))
}

if d.HasChange("labels") {
if containsLabelOrKey(expandLabelSliceFromSetSchema(d), defaultLabel) {
return diag.FromErr(fmt.Errorf("you should not set `Infrastructure Tool` label, it is used for internal purposes"))
Expand Down
Loading