Skip to content

Commit

Permalink
feat: Supports config_server_type and `config_server_management_mod…
Browse files Browse the repository at this point in the history
…e` in advanced_cluster (#2670)

* feat: Supports `config_server_type` and `config_server_management_mode` in advanced_cluster

* test: Modifies test case for config_server_management_mode and config_server_type

* chore: add changelog entry

* fix: use config_server_management_mode and config_server_type in plural data source

* fix: supports updating both old cluster attributes and new attributes

* test: Use explicit depends_on to ensure reads happens after update

* refactor: simplify setter logic for new fields

* chore: Adds docs for new attributes `config_server_management_mode` and `config_server_type` (#2677)

* chore: add docs for `config_server_management_mode` and `config_server_type`

* Update docs/data-sources/advanced_cluster.md

Co-authored-by: kyuan-mongodb <[email protected]>

* Update docs/data-sources/advanced_clusters.md

Co-authored-by: kyuan-mongodb <[email protected]>

* Update docs/resources/advanced_cluster.md

Co-authored-by: kyuan-mongodb <[email protected]>

---------

Co-authored-by: kyuan-mongodb <[email protected]>

---------

Co-authored-by: kyuan-mongodb <[email protected]>
  • Loading branch information
EspenAlbert and kyuan-mongodb authored Oct 14, 2024
1 parent ab2f4f6 commit a0be718
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 17 deletions.
11 changes: 11 additions & 0 deletions .changelog/2670.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
resource/mongodbatlas_advanced_cluster: Adds new `config_server_management_mode` and `config_server_type` fields
```

```release-note:enhancement
data-source/mongodbatlas_advanced_cluster: Adds new `config_server_management_mode` and `config_server_type` fields
```

```release-note:enhancement
data-source/mongodbatlas_advanced_clusters: Adds new `config_server_management_mode` and `config_server_type` fields
```
2 changes: 2 additions & 0 deletions docs/data-sources/advanced_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ In addition to all arguments above, the following attributes are exported:
* `global_cluster_self_managed_sharding` - Flag that indicates if cluster uses Atlas-Managed Sharding (false) or Self-Managed Sharding (true).
* `replica_set_scaling_strategy` - (Optional) Replica set scaling mode for your cluster.
* `redact_client_log_data` - (Optional) Flag that enables or disables log redaction, see the [manual](https://www.mongodb.com/docs/manual/administration/monitoring/#log-redaction) for more info.
* `config_server_management_mode` - Config Server Management Mode for creating or updating a sharded cluster. Valid values are `ATLAS_MANAGED` (default) and `FIXED_TO_DEDICATED`. When configured as `ATLAS_MANAGED`, Atlas may automatically switch the cluster's config server type for optimal performance and savings. When configured as `FIXED_TO_DEDICATED`, the cluster will always use a dedicated config server. To learn more, see the [Sharded Cluster Config Servers documentation](https://dochub.mongodb.org/docs/manual/core/sharded-cluster-config-servers/).
* `config_server_type` Describes a sharded cluster's config server type. Valid values are `DEDICATED` and `EMBEDDED`. To learn more, see the [Sharded Cluster Config Servers documentation](https://dochub.mongodb.org/docs/manual/core/sharded-cluster-config-servers/).

### bi_connector_config

Expand Down
2 changes: 2 additions & 0 deletions docs/data-sources/advanced_clusters.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ In addition to all arguments above, the following attributes are exported:
* `global_cluster_self_managed_sharding` - Flag that indicates if cluster uses Atlas-Managed Sharding (false) or Self-Managed Sharding (true).
* `replica_set_scaling_strategy` - (Optional) Replica set scaling mode for your cluster.
* `redact_client_log_data` - (Optional) Flag that enables or disables log redaction, see the [manual](https://www.mongodb.com/docs/manual/administration/monitoring/#log-redaction) for more info.
* `config_server_management_mode` - Config Server Management Mode for creating or updating a sharded cluster. Valid values are `ATLAS_MANAGED` (default) and `FIXED_TO_DEDICATED`. When configured as `ATLAS_MANAGED`, Atlas may automatically switch the cluster's config server type for optimal performance and savings. When configured as `FIXED_TO_DEDICATED`, the cluster will always use a dedicated config server. To learn more, see the [Sharded Cluster Config Servers documentation](https://dochub.mongodb.org/docs/manual/core/sharded-cluster-config-servers/).
* `config_server_type` Describes a sharded cluster's config server type. Valid values are `DEDICATED` and `EMBEDDED`. To learn more, see the [Sharded Cluster Config Servers documentation](https://dochub.mongodb.org/docs/manual/core/sharded-cluster-config-servers/).

### bi_connector_config

Expand Down
3 changes: 3 additions & 0 deletions docs/resources/advanced_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ This parameter defaults to false.
* `global_cluster_self_managed_sharding` - (Optional) Flag that indicates if cluster uses Atlas-Managed Sharding (false, default) or Self-Managed Sharding (true). It can only be enabled for Global Clusters (`GEOSHARDED`). It cannot be changed once the cluster is created. Use this mode if you're an advanced user and the default configuration is too restrictive for your workload. If you select this option, you must manually configure the sharding strategy, more info [here](https://www.mongodb.com/docs/atlas/tutorial/create-global-cluster/#select-your-sharding-configuration).
* `replica_set_scaling_strategy` - (Optional) Replica set scaling mode for your cluster. Valid values are `WORKLOAD_TYPE`, `SEQUENTIAL` and `NODE_TYPE`. By default, Atlas scales under `WORKLOAD_TYPE`. This mode allows Atlas to scale your analytics nodes in parallel to your operational nodes. When configured as `SEQUENTIAL`, Atlas scales all nodes sequentially. This mode is intended for steady-state workloads and applications performing latency-sensitive secondary reads. When configured as `NODE_TYPE`, Atlas scales your electable nodes in parallel with your read-only and analytics nodes. This mode is intended for large, dynamic workloads requiring frequent and timely cluster tier scaling. This is the fastest scaling strategy, but it might impact latency of workloads when performing extensive secondary reads. [Modify the Replica Set Scaling Mode](https://dochub.mongodb.org/core/scale-nodes)
* `redact_client_log_data` - (Optional) Flag that enables or disables log redaction, see the [manual](https://www.mongodb.com/docs/manual/administration/monitoring/#log-redaction) for more info. Use this in conjunction with Encryption at Rest and TLS/SSL (Transport Encryption) to assist compliance with regulatory requirements. **Note**: Changing this setting on a cluster will trigger a rolling restart as soon as the cluster is updated.
* `config_server_management_mode` - (Optional) Config Server Management Mode for creating or updating a sharded cluster. Valid values are `ATLAS_MANAGED` (default) and `FIXED_TO_DEDICATED`. When configured as `ATLAS_MANAGED`, Atlas may automatically switch the cluster's config server type for optimal performance and savings. When configured as `FIXED_TO_DEDICATED`, the cluster will always use a dedicated config server. To learn more, see the [Sharded Cluster Config Servers documentation](https://dochub.mongodb.org/docs/manual/core/sharded-cluster-config-servers/).

### bi_connector_config

Expand Down Expand Up @@ -682,6 +683,8 @@ In addition to all arguments above, the following attributes are exported:
- DELETED
- REPAIRING
* `replication_specs.#.container_id` - A key-value map of the Network Peering Container ID(s) for the configuration specified in `region_configs`. The Container ID is the id of the container created when the first cluster in the region (AWS/Azure) or project (GCP) was created. The syntax is `"providerName:regionName" = "containerId"`. Example `AWS:US_EAST_1" = "61e0797dde08fb498ca11a71`.
* `config_server_type` Describes a sharded cluster's config server type. Valid values are `DEDICATED` and `EMBEDDED`. To learn more, see the [Sharded Cluster Config Servers documentation](https://dochub.mongodb.org/docs/manual/core/sharded-cluster-config-servers/).


## Import

Expand Down
13 changes: 12 additions & 1 deletion internal/service/advancedcluster/data_source_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ func DataSource() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"config_server_management_mode": {
Type: schema.TypeString,
Computed: true,
},
"config_server_type": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -310,7 +318,10 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "replication_specs", clusterName, err))
}

diags := setRootFields(d, convertClusterDescToLatestExcludeRepSpecs(clusterDescOld), false)
clusterDesc := convertClusterDescToLatestExcludeRepSpecs(clusterDescOld)
clusterDesc.ConfigServerManagementMode = clusterDescNew.ConfigServerManagementMode
clusterDesc.ConfigServerType = clusterDescNew.ConfigServerType
diags := setRootFields(d, clusterDesc, false)
if diags.HasError() {
return diags
}
Expand Down
12 changes: 12 additions & 0 deletions internal/service/advancedcluster/data_source_advanced_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ func PluralDataSource() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"config_server_management_mode": {
Type: schema.TypeString,
Computed: true,
},
"config_server_type": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -365,6 +373,8 @@ func flattenAdvancedClusters(ctx context.Context, connV220240530 *admin20240530.
"global_cluster_self_managed_sharding": cluster.GetGlobalClusterSelfManagedSharding(),
"replica_set_scaling_strategy": cluster.GetReplicaSetScalingStrategy(),
"redact_client_log_data": cluster.GetRedactClientLogData(),
"config_server_management_mode": cluster.GetConfigServerManagementMode(),
"config_server_type": cluster.GetConfigServerType(),
}
results = append(results, result)
}
Expand Down Expand Up @@ -422,6 +432,8 @@ func flattenAdvancedClustersOldSDK(ctx context.Context, connV20240530 *admin2024
"global_cluster_self_managed_sharding": cluster.GetGlobalClusterSelfManagedSharding(),
"replica_set_scaling_strategy": clusterDescNew.GetReplicaSetScalingStrategy(),
"redact_client_log_data": clusterDescNew.GetRedactClientLogData(),
"config_server_management_mode": clusterDescNew.GetConfigServerManagementMode(),
"config_server_type": clusterDescNew.GetConfigServerType(),
}
results = append(results, result)
}
Expand Down
39 changes: 34 additions & 5 deletions internal/service/advancedcluster/resource_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,15 @@ func Resource() *schema.Resource {
Optional: true,
Computed: true,
},
"config_server_management_mode": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"config_server_type": {
Type: schema.TypeString,
Computed: true,
},
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(3 * time.Hour),
Expand Down Expand Up @@ -457,6 +466,9 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.
if v, ok := d.GetOk("redact_client_log_data"); ok {
params.RedactClientLogData = conversion.Pointer(v.(bool))
}
if v, ok := d.GetOk("config_server_management_mode"); ok {
params.ConfigServerManagementMode = conversion.StringPtr(v.(string))
}

// 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 @@ -563,7 +575,6 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di
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 {
return diag.FromErr(err)
Expand All @@ -575,6 +586,8 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di
}

clusterResp = convertClusterDescToLatestExcludeRepSpecs(clusterOldSDK)
clusterResp.ConfigServerManagementMode = cluster.ConfigServerManagementMode
clusterResp.ConfigServerType = cluster.ConfigServerType
} else {
cluster, resp, err := connV2.ClustersApi.GetCluster(ctx, projectID, clusterName).Execute()
if err != nil {
Expand Down Expand Up @@ -748,6 +761,13 @@ func setRootFields(d *schema.ResourceData, cluster *admin.ClusterDescription2024
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "global_cluster_self_managed_sharding", clusterName, err))
}

if err := d.Set("config_server_type", cluster.GetConfigServerType()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "config_server_type", clusterName, err))
}

if err := d.Set("config_server_management_mode", cluster.GetConfigServerManagementMode()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "config_server_management_mode", clusterName, err))
}
return nil
}

Expand Down Expand Up @@ -814,27 +834,33 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.
return diags
}
clusterChangeDetect := new(admin20240530.AdvancedClusterDescription)
var waitOnUpdate bool
if !reflect.DeepEqual(req, clusterChangeDetect) {
if err := CheckRegionConfigsPriorityOrderOld(req.GetReplicationSpecs()); err != nil {
return diag.FromErr(err)
}
if _, _, err := connV220240530.ClustersApi.UpdateCluster(ctx, projectID, clusterName, req).Execute(); err != nil {
return diag.FromErr(fmt.Errorf(errorUpdate, clusterName, err))
}
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") || d.HasChange("redact_client_log_data") {
waitOnUpdate = true
}
if d.HasChange("replica_set_scaling_strategy") || d.HasChange("redact_client_log_data") || d.HasChange("config_server_management_mode") {
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 d.HasChange("config_server_management_mode") {
request.ConfigServerManagementMode = conversion.StringPtr(d.Get("config_server_management_mode").(string))
}
if _, _, err := connV2.ClustersApi.UpdateCluster(ctx, projectID, clusterName, request).Execute(); err != nil {
return diag.FromErr(fmt.Errorf(errorUpdate, clusterName, err))
}
waitOnUpdate = true
}
if waitOnUpdate {
if err := waitForUpdateToFinish(ctx, connV2, projectID, clusterName, timeout); err != nil {
return diag.FromErr(fmt.Errorf(errorUpdate, clusterName, err))
}
Expand Down Expand Up @@ -992,6 +1018,9 @@ func updateRequest(ctx context.Context, d *schema.ResourceData, projectID, clust
if d.HasChange("redact_client_log_data") {
cluster.RedactClientLogData = conversion.Pointer(d.Get("redact_client_log_data").(bool))
}
if d.HasChange("config_server_management_mode") {
cluster.ConfigServerManagementMode = conversion.StringPtr(d.Get("config_server_management_mode").(string))
}

return cluster, nil
}
Expand Down
54 changes: 43 additions & 11 deletions internal/service/advancedcluster/resource_advanced_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const (
dataSourcePluralName = "data.mongodbatlas_advanced_clusters.test"
)

var (
configServerManagementModeFixedToDedicated = "FIXED_TO_DEDICATED"
configServerManagementModeAtlasManaged = "ATLAS_MANAGED"
)

func TestAccClusterAdvancedCluster_basicTenant(t *testing.T) {
var (
projectID = acc.ProjectIDExecution(t)
Expand Down Expand Up @@ -142,12 +147,12 @@ func singleShardedMultiCloudTestCase(t *testing.T) resource.TestCase {
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Config: configShardedOldSchemaMultiCloud(orgID, projectName, clusterName, 1, "M10"),
Check: checkShardedOldSchemaMultiCloud(clusterName, 1, "M10", true),
Config: configShardedOldSchemaMultiCloud(orgID, projectName, clusterName, 1, "M10", nil),
Check: checkShardedOldSchemaMultiCloud(clusterName, 1, "M10", true, nil),
},
{
Config: configShardedOldSchemaMultiCloud(orgID, projectName, clusterNameUpdated, 1, "M10"),
Check: checkShardedOldSchemaMultiCloud(clusterNameUpdated, 1, "M10", true),
Config: configShardedOldSchemaMultiCloud(orgID, projectName, clusterNameUpdated, 1, "M10", nil),
Check: checkShardedOldSchemaMultiCloud(clusterNameUpdated, 1, "M10", true, nil),
},
{
ResourceName: resourceName,
Expand Down Expand Up @@ -555,12 +560,12 @@ func TestAccClusterAdvancedClusterConfig_symmetricShardedOldSchema(t *testing.T)
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Config: configShardedOldSchemaMultiCloud(orgID, projectName, clusterName, 2, "M10"),
Check: checkShardedOldSchemaMultiCloud(clusterName, 2, "M10", false),
Config: configShardedOldSchemaMultiCloud(orgID, projectName, clusterName, 2, "M10", &configServerManagementModeFixedToDedicated),
Check: checkShardedOldSchemaMultiCloud(clusterName, 2, "M10", false, &configServerManagementModeFixedToDedicated),
},
{
Config: configShardedOldSchemaMultiCloud(orgID, projectName, clusterName, 2, "M20"),
Check: checkShardedOldSchemaMultiCloud(clusterName, 2, "M20", false),
Config: configShardedOldSchemaMultiCloud(orgID, projectName, clusterName, 2, "M20", &configServerManagementModeAtlasManaged),
Check: checkShardedOldSchemaMultiCloud(clusterName, 2, "M20", false, &configServerManagementModeAtlasManaged),
},
},
})
Expand Down Expand Up @@ -1181,7 +1186,17 @@ func checkReplicaSetMultiCloud(name string, regionConfigs int) resource.TestChec
)
}

func configShardedOldSchemaMultiCloud(orgID, projectName, name string, numShards int, analyticsSize string) string {
func configShardedOldSchemaMultiCloud(orgID, projectName, name string, numShards int, analyticsSize string, configServerManagementMode *string) string {
var rootConfig string
if configServerManagementMode != nil {
// valid values: FIXED_TO_DEDICATED or ATLAS_MANAGED (default)
// only valid for Major version 8 and later
// cluster must be SHARDED
rootConfig = fmt.Sprintf(`
mongo_db_major_version = "8"
config_server_management_mode = %[1]q
`, *configServerManagementMode)
}
return fmt.Sprintf(`
resource "mongodbatlas_project" "cluster_project" {
org_id = %[1]q
Expand All @@ -1192,6 +1207,7 @@ func configShardedOldSchemaMultiCloud(orgID, projectName, name string, numShards
project_id = mongodbatlas_project.cluster_project.id
name = %[3]q
cluster_type = "SHARDED"
%[6]s
replication_specs {
num_shards = %[4]d
Expand Down Expand Up @@ -1223,11 +1239,16 @@ func configShardedOldSchemaMultiCloud(orgID, projectName, name string, numShards
data "mongodbatlas_advanced_cluster" "test" {
project_id = mongodbatlas_advanced_cluster.test.project_id
name = mongodbatlas_advanced_cluster.test.name
depends_on = [mongodbatlas_advanced_cluster.test]
}
data "mongodbatlas_advanced_clusters" "test" {
project_id = mongodbatlas_advanced_cluster.test.project_id
depends_on = [mongodbatlas_advanced_cluster.test]
}
`, orgID, projectName, name, numShards, analyticsSize)
`, orgID, projectName, name, numShards, analyticsSize, rootConfig)
}

func checkShardedOldSchemaMultiCloud(name string, numShards int, analyticsSize string, verifyExternalID bool) resource.TestCheckFunc {
func checkShardedOldSchemaMultiCloud(name string, numShards int, analyticsSize string, verifyExternalID bool, configServerManagementMode *string) resource.TestCheckFunc {
additionalChecks := []resource.TestCheckFunc{
resource.TestCheckResourceAttrWith(resourceName, "replication_specs.0.region_configs.0.electable_specs.0.disk_iops", acc.IntGreatThan(0)),
resource.TestCheckResourceAttrWith(resourceName, "replication_specs.0.region_configs.0.analytics_specs.0.disk_iops", acc.IntGreatThan(0)),
Expand All @@ -1242,6 +1263,17 @@ func checkShardedOldSchemaMultiCloud(name string, numShards int, analyticsSize s
additionalChecks,
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.external_id"))
}
if configServerManagementMode != nil {
additionalChecks = append(
additionalChecks,
resource.TestCheckResourceAttr(resourceName, "config_server_management_mode", *configServerManagementMode),
resource.TestCheckResourceAttrSet(resourceName, "config_server_type"),
resource.TestCheckResourceAttr(dataSourceName, "config_server_management_mode", *configServerManagementMode),
resource.TestCheckResourceAttrSet(dataSourceName, "config_server_type"),
resource.TestCheckResourceAttr(dataSourcePluralName, "results.0.config_server_management_mode", *configServerManagementMode),
resource.TestCheckResourceAttrSet(dataSourcePluralName, "results.0.config_server_type"),
)
}

return checkAggr(
[]string{"project_id", "replication_specs.#", "replication_specs.0.id", "replication_specs.0.region_configs.#"},
Expand Down

0 comments on commit a0be718

Please sign in to comment.