Skip to content

Commit

Permalink
feat: Supports redact_client_log_data in `mongodbatlas_advanced_clu…
Browse files Browse the repository at this point in the history
…ster` (#2600)

* use SDK Preview

* add redact_client_log_data to schema

* plural ds

* resource

* tests

* changelog
  • Loading branch information
lantoli authored Sep 16, 2024
1 parent c20f162 commit b9e69e1
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 27 deletions.
11 changes: 11 additions & 0 deletions .changelog/2600.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
resource/mongodbatlas_advanced_cluster: Supports redact_client_log_data attribute
```

```release-note:enhancement
data-source/mongodbatlas_advanced_cluster: Supports redact_client_log_data attribute
```

```release-note:enhancement
data-source/mongodbatlas_advanced_clusters: Supports redact_client_log_data attribute
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/zclconf/go-cty v1.15.0
go.mongodb.org/atlas v0.37.0
go.mongodb.org/atlas-sdk/v20240530005 v20240530005.0.0
go.mongodb.org/atlas-sdk/v20240805004 v20240805004.0.0
go.mongodb.org/atlas-sdk/v20240805004 v20240805004.0.1-0.20240916083704-8a3aabd0d076
go.mongodb.org/realm v0.1.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,8 @@ go.mongodb.org/atlas v0.37.0 h1:zQnO1o5+bVP9IotpAYpres4UjMD2F4nwNEFTZhNL4ck=
go.mongodb.org/atlas v0.37.0/go.mod h1:DJYtM+vsEpPEMSkQzJnFHrT0sP7ev6cseZc/GGjJYG8=
go.mongodb.org/atlas-sdk/v20240530005 v20240530005.0.0 h1:d/gbYJ+obR0EM/3DZf7+ZMi2QWISegm3mid7Or708cc=
go.mongodb.org/atlas-sdk/v20240530005 v20240530005.0.0/go.mod h1:O47ZrMMfcWb31wznNIq2PQkkdoFoK0ea2GlmRqGJC2s=
go.mongodb.org/atlas-sdk/v20240805004 v20240805004.0.0 h1:yUu17LEWoqCw1+Us5I+DGXF3Z3mEgsZDpswB1iSnWWU=
go.mongodb.org/atlas-sdk/v20240805004 v20240805004.0.0/go.mod h1:64cvOvwsE0TTi9nAl16XlVkHzT0gFLGcZeG7HnnXxtE=
go.mongodb.org/atlas-sdk/v20240805004 v20240805004.0.1-0.20240916083704-8a3aabd0d076 h1:m8TUh8wCzHVbRDvXkAN5btZCy2LOn0fUbjkX8AkVqn0=
go.mongodb.org/atlas-sdk/v20240805004 v20240805004.0.1-0.20240916083704-8a3aabd0d076/go.mod h1:64cvOvwsE0TTi9nAl16XlVkHzT0gFLGcZeG7HnnXxtE=
go.mongodb.org/realm v0.1.0 h1:zJiXyLaZrznQ+Pz947ziSrDKUep39DO4SfA0Fzx8M4M=
go.mongodb.org/realm v0.1.0/go.mod h1:4Vj6iy+Puo1TDERcoh4XZ+pjtwbOzPpzqy3Cwe8ZmDM=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
Expand Down
10 changes: 10 additions & 0 deletions internal/service/advancedcluster/data_source_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ func DataSource() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"redact_client_log_data": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -294,6 +298,9 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.
if err := d.Set("replica_set_scaling_strategy", clusterDescNew.GetReplicaSetScalingStrategy()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "replica_set_scaling_strategy", clusterName, err))
}
if err := d.Set("redact_client_log_data", clusterDescNew.GetRedactClientLogData()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "redact_client_log_data", clusterName, err))
}

zoneNameToZoneIDs, err := getZoneIDsFromNewAPI(clusterDescNew)
if err != nil {
Expand Down Expand Up @@ -327,6 +334,9 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.
if err := d.Set("replica_set_scaling_strategy", clusterDescLatest.GetReplicaSetScalingStrategy()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "replica_set_scaling_strategy", clusterName, err))
}
if err := d.Set("redact_client_log_data", clusterDescLatest.GetRedactClientLogData()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "redact_client_log_data", clusterName, err))
}

zoneNameToOldReplicationSpecIDs, err := getReplicationSpecIDsFromOldAPI(ctx, projectID, clusterName, connV220240530)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ func PluralDataSource() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"redact_client_log_data": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -362,6 +366,7 @@ func flattenAdvancedClusters(ctx context.Context, connV220240530 *admin20240530.
"version_release_system": cluster.GetVersionReleaseSystem(),
"global_cluster_self_managed_sharding": cluster.GetGlobalClusterSelfManagedSharding(),
"replica_set_scaling_strategy": cluster.GetReplicaSetScalingStrategy(),
"redact_client_log_data": cluster.GetRedactClientLogData(),
}
results = append(results, result)
}
Expand Down Expand Up @@ -418,6 +423,7 @@ func flattenAdvancedClustersOldSDK(ctx context.Context, connV20240530 *admin2024
"version_release_system": cluster.GetVersionReleaseSystem(),
"global_cluster_self_managed_sharding": cluster.GetGlobalClusterSelfManagedSharding(),
"replica_set_scaling_strategy": clusterDescNew.GetReplicaSetScalingStrategy(),
"redact_client_log_data": clusterDescNew.GetRedactClientLogData(),
}
results = append(results, result)
}
Expand Down
28 changes: 25 additions & 3 deletions internal/service/advancedcluster/resource_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ func Resource() *schema.Resource {
Optional: true,
Computed: true,
},
"redact_client_log_data": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(3 * time.Hour),
Expand Down Expand Up @@ -450,6 +455,9 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.
if v, ok := d.GetOk("replica_set_scaling_strategy"); ok {
params.ReplicaSetScalingStrategy = conversion.StringPtr(v.(string))
}
if v, ok := d.GetOk("redact_client_log_data"); ok {
params.RedactClientLogData = conversion.Pointer(v.(bool))
}

// Validate oplog_size_mb to show the error before the cluster is created.
if oplogSizeMB, ok := d.GetOkExists("advanced_configuration.0.oplog_size_mb"); ok {
Expand Down Expand Up @@ -550,6 +558,9 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di
if err := d.Set("replica_set_scaling_strategy", cluster.GetReplicaSetScalingStrategy()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "replica_set_scaling_strategy", clusterName, err))
}
if err := d.Set("redact_client_log_data", cluster.GetRedactClientLogData()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "redact_client_log_data", clusterName, err))
}

zoneNameToZoneIDs, err := getZoneIDsFromNewAPI(cluster)
if err != nil {
Expand Down Expand Up @@ -579,6 +590,9 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di
if err := d.Set("replica_set_scaling_strategy", cluster.GetReplicaSetScalingStrategy()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "replica_set_scaling_strategy", clusterName, err))
}
if err := d.Set("redact_client_log_data", cluster.GetRedactClientLogData()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "redact_client_log_data", clusterName, err))
}

zoneNameToOldReplicationSpecIDs, err := getReplicationSpecIDsFromOldAPI(ctx, projectID, clusterName, connV220240530)
if err != nil {
Expand Down Expand Up @@ -805,9 +819,13 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.
if err := waitForUpdateToFinish(ctx, connV2, projectID, clusterName, timeout); err != nil {
return diag.FromErr(fmt.Errorf(errorUpdate, clusterName, err))
}
} else if d.HasChange("replica_set_scaling_strategy") {
request := &admin.ClusterDescription20240805{
ReplicaSetScalingStrategy: conversion.Pointer(d.Get("replica_set_scaling_strategy").(string)),
} else if d.HasChange("replica_set_scaling_strategy") || d.HasChange("redact_client_log_data") {
request := new(admin.ClusterDescription20240805)
if d.HasChange("replica_set_scaling_strategy") {
request.ReplicaSetScalingStrategy = conversion.Pointer(d.Get("replica_set_scaling_strategy").(string))
}
if d.HasChange("redact_client_log_data") {
request.RedactClientLogData = conversion.Pointer(d.Get("redact_client_log_data").(bool))
}
if _, _, err := connV2.ClustersApi.UpdateCluster(ctx, projectID, clusterName, request).Execute(); err != nil {
return diag.FromErr(fmt.Errorf(errorUpdate, clusterName, err))
Expand Down Expand Up @@ -958,6 +976,10 @@ func updateRequest(ctx context.Context, d *schema.ResourceData, projectID, clust
if d.HasChange("replica_set_scaling_strategy") {
cluster.ReplicaSetScalingStrategy = conversion.Pointer(d.Get("replica_set_scaling_strategy").(string))
}
if d.HasChange("redact_client_log_data") {
cluster.RedactClientLogData = conversion.Pointer(d.Get("redact_client_log_data").(bool))
}

return cluster, nil
}

Expand Down
46 changes: 25 additions & 21 deletions internal/service/advancedcluster/resource_advanced_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ func TestAccClusterAdvancedClusterConfig_geoShardedTransitionFromOldToNewSchema(
})
}

func TestAccAdvancedCluster_replicaSetScalingStrategy(t *testing.T) {
func TestAccAdvancedCluster_replicaSetScalingStrategyAndRedactClientLogData(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
Expand All @@ -729,22 +729,22 @@ func TestAccAdvancedCluster_replicaSetScalingStrategy(t *testing.T) {
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Config: configReplicaSetScalingStrategy(orgID, projectName, clusterName, "WORKLOAD_TYPE"),
Check: checkReplicaSetScalingStrategy("WORKLOAD_TYPE"),
Config: configReplicaSetScalingStrategyAndRedactClientLogData(orgID, projectName, clusterName, "WORKLOAD_TYPE", true),
Check: checkReplicaSetScalingStrategyAndRedactClientLogData("WORKLOAD_TYPE", true),
},
{
Config: configReplicaSetScalingStrategy(orgID, projectName, clusterName, "SEQUENTIAL"),
Check: checkReplicaSetScalingStrategy("SEQUENTIAL"),
Config: configReplicaSetScalingStrategyAndRedactClientLogData(orgID, projectName, clusterName, "SEQUENTIAL", false),
Check: checkReplicaSetScalingStrategyAndRedactClientLogData("SEQUENTIAL", false),
},
{
Config: configReplicaSetScalingStrategy(orgID, projectName, clusterName, "NODE_TYPE"),
Check: checkReplicaSetScalingStrategy("NODE_TYPE"),
Config: configReplicaSetScalingStrategyAndRedactClientLogData(orgID, projectName, clusterName, "NODE_TYPE", true),
Check: checkReplicaSetScalingStrategyAndRedactClientLogData("NODE_TYPE", true),
},
},
})
}

func TestAccAdvancedCluster_replicaSetScalingStrategyOldSchema(t *testing.T) {
func TestAccAdvancedCluster_replicaSetScalingStrategyAndRedactClientLogDataOldSchema(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
Expand All @@ -757,16 +757,16 @@ func TestAccAdvancedCluster_replicaSetScalingStrategyOldSchema(t *testing.T) {
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Config: configReplicaSetScalingStrategyOldSchema(orgID, projectName, clusterName, "WORKLOAD_TYPE"),
Check: checkReplicaSetScalingStrategy("WORKLOAD_TYPE"),
Config: configReplicaSetScalingStrategyAndRedactClientLogDataOldSchema(orgID, projectName, clusterName, "WORKLOAD_TYPE", false),
Check: checkReplicaSetScalingStrategyAndRedactClientLogData("WORKLOAD_TYPE", false),
},
{
Config: configReplicaSetScalingStrategyOldSchema(orgID, projectName, clusterName, "SEQUENTIAL"),
Check: checkReplicaSetScalingStrategy("SEQUENTIAL"),
Config: configReplicaSetScalingStrategyAndRedactClientLogDataOldSchema(orgID, projectName, clusterName, "SEQUENTIAL", true),
Check: checkReplicaSetScalingStrategyAndRedactClientLogData("SEQUENTIAL", true),
},
{
Config: configReplicaSetScalingStrategyOldSchema(orgID, projectName, clusterName, "NODE_TYPE"),
Check: checkReplicaSetScalingStrategy("NODE_TYPE"),
Config: configReplicaSetScalingStrategyAndRedactClientLogDataOldSchema(orgID, projectName, clusterName, "NODE_TYPE", false),
Check: checkReplicaSetScalingStrategyAndRedactClientLogData("NODE_TYPE", false),
},
},
})
Expand Down Expand Up @@ -1980,7 +1980,7 @@ func checkGeoShardedTransitionOldToNewSchema(useNewSchema bool) resource.TestChe
)
}

func configReplicaSetScalingStrategy(orgID, projectName, name, replicaSetScalingStrategy string) string {
func configReplicaSetScalingStrategyAndRedactClientLogData(orgID, projectName, name, replicaSetScalingStrategy string, redactClientLogData bool) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "cluster_project" {
org_id = %[1]q
Expand All @@ -1993,6 +1993,7 @@ func configReplicaSetScalingStrategy(orgID, projectName, name, replicaSetScaling
backup_enabled = false
cluster_type = "SHARDED"
replica_set_scaling_strategy = %[4]q
redact_client_log_data = %[5]t
replication_specs {
region_configs {
Expand Down Expand Up @@ -2023,10 +2024,10 @@ func configReplicaSetScalingStrategy(orgID, projectName, name, replicaSetScaling
project_id = mongodbatlas_advanced_cluster.test.project_id
use_replication_spec_per_shard = true
}
`, orgID, projectName, name, replicaSetScalingStrategy)
`, orgID, projectName, name, replicaSetScalingStrategy, redactClientLogData)
}

func configReplicaSetScalingStrategyOldSchema(orgID, projectName, name, replicaSetScalingStrategy string) string {
func configReplicaSetScalingStrategyAndRedactClientLogDataOldSchema(orgID, projectName, name, replicaSetScalingStrategy string, redactClientLogData bool) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "cluster_project" {
org_id = %[1]q
Expand All @@ -2039,6 +2040,7 @@ func configReplicaSetScalingStrategyOldSchema(orgID, projectName, name, replicaS
backup_enabled = false
cluster_type = "SHARDED"
replica_set_scaling_strategy = %[4]q
redact_client_log_data = %[5]t
replication_specs {
num_shards = 2
Expand Down Expand Up @@ -2068,16 +2070,18 @@ func configReplicaSetScalingStrategyOldSchema(orgID, projectName, name, replicaS
data "mongodbatlas_advanced_clusters" "test" {
project_id = mongodbatlas_advanced_cluster.test.project_id
}
`, orgID, projectName, name, replicaSetScalingStrategy)
`, orgID, projectName, name, replicaSetScalingStrategy, redactClientLogData)
}

func checkReplicaSetScalingStrategy(replicaSetScalingStrategy string) resource.TestCheckFunc {
func checkReplicaSetScalingStrategyAndRedactClientLogData(replicaSetScalingStrategy string, redactClientLogData bool) resource.TestCheckFunc {
clusterChecks := map[string]string{
"replica_set_scaling_strategy": replicaSetScalingStrategy}
"replica_set_scaling_strategy": replicaSetScalingStrategy,
"redact_client_log_data": strconv.FormatBool(redactClientLogData),
}

// plural data source checks
additionalChecks := acc.AddAttrSetChecks(dataSourcePluralName, nil,
[]string{"results.#", "results.0.replica_set_scaling_strategy"}...)
[]string{"results.#", "results.0.replica_set_scaling_strategy", "results.0.redact_client_log_data"}...)
return checkAggr(
[]string{},
clusterChecks,
Expand Down

0 comments on commit b9e69e1

Please sign in to comment.