Skip to content

Commit b670961

Browse files
authored
feat: Adds acceptDataRisksAndForceReplicaSetReconfig parameter in mongodbatlas_cluster and mongodbatlas_advanced_cluster (#1575)
* update HTTP SDK * go mod tidy * add accept_data_risks_and_force_replica_set_reconfig in cluster resource * add accept_data_risks_and_force_replica_set_reconfig in advanced_cluster resource * doc * fix doc
1 parent f7eb77b commit b670961

File tree

6 files changed

+43
-7
lines changed

6 files changed

+43
-7
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/mwielbut/pointy v1.1.0
2424
github.com/spf13/cast v1.5.1
2525
github.com/zclconf/go-cty v1.14.1
26-
go.mongodb.org/atlas v0.34.0
26+
go.mongodb.org/atlas v0.35.0
2727
go.mongodb.org/atlas-sdk/v20231001001 v20231001001.1.0
2828
go.mongodb.org/realm v0.1.0
2929
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,8 @@ github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRK
755755
github.com/zclconf/go-cty-yaml v1.0.2 h1:dNyg4QLTrv2IfJpm7Wtxi55ed5gLGOlPrZ6kMd51hY0=
756756
github.com/zclconf/go-cty-yaml v1.0.2/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgKa8XhiVHura0=
757757
go.mongodb.org/atlas v0.12.0/go.mod h1:wVCnHcm/7/IfTjEB6K8K35PLG70yGz8BdkRwX0oK9/M=
758-
go.mongodb.org/atlas v0.34.0 h1:C6pDYjKWbjSZCsNoZpgNO6I5e/jH7OVwoQ0OXcoAFCg=
759-
go.mongodb.org/atlas v0.34.0/go.mod h1:L4BKwVx/OeEhOVjCSdgo90KJm4469iv7ZLzQms/EPTg=
758+
go.mongodb.org/atlas v0.35.0 h1:fLSPEyv+QcrG5djPWMekaM+BEVfEVBKQO4yEUQl4CQ4=
759+
go.mongodb.org/atlas v0.35.0/go.mod h1:nfPldE9dSama6G2IbIzmEza02Ly7yFZjMMVscaM0uEc=
760760
go.mongodb.org/atlas-sdk/v20231001001 v20231001001.1.0 h1:CT+kpV9xzrxHnOieTn+DfT2B4K48SnEIsoQ48kVrylY=
761761
go.mongodb.org/atlas-sdk/v20231001001 v20231001001.1.0/go.mod h1:2DismEF/fnloT92wjCkA1hpbBGrjQ5fPNAbC48mkRD4=
762762
go.mongodb.org/realm v0.1.0 h1:zJiXyLaZrznQ+Pz947ziSrDKUep39DO4SfA0Fzx8M4M=

mongodbatlas/resource_mongodbatlas_advanced_cluster.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ func resourceMongoDBAtlasAdvancedCluster() *schema.Resource {
310310
ValidateFunc: validation.StringInSlice([]string{"LTS", "CONTINUOUS"}, false),
311311
},
312312
"advanced_configuration": clusterAdvancedConfigurationSchema(),
313+
"accept_data_risks_and_force_replica_set_reconfig": {
314+
Type: schema.TypeString,
315+
Optional: true,
316+
Description: "Submit this field alongside your topology reconfiguration to request a new regional outage resistant topology",
317+
},
313318
},
314319
Timeouts: &schema.ResourceTimeout{
315320
Create: schema.DefaultTimeout(3 * time.Hour),
@@ -373,7 +378,12 @@ func advancedClusterRegionConfigsSpecsSchema() *schema.Schema {
373378
}
374379

375380
func resourceMongoDBAtlasAdvancedClusterCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
376-
// Get client connection.
381+
if v, ok := d.GetOk("accept_data_risks_and_force_replica_set_reconfig"); ok {
382+
if v.(string) != "" {
383+
return diag.FromErr(fmt.Errorf("accept_data_risks_and_force_replica_set_reconfig can not be set in creation, only in update"))
384+
}
385+
}
386+
377387
conn := meta.(*MongoDBClient).Atlas
378388

379389
projectID := d.Get("project_id").(string)
@@ -409,7 +419,6 @@ func resourceMongoDBAtlasAdvancedClusterCreate(ctx context.Context, d *schema.Re
409419
if _, ok := d.GetOk("tags"); ok {
410420
request.Tags = expandTagSliceFromSetSchema(d)
411421
}
412-
413422
if v, ok := d.GetOk("mongo_db_major_version"); ok {
414423
request.MongoDBMajorVersion = formatMongoDBMajorVersion(v.(string))
415424
}
@@ -596,6 +605,10 @@ func resourceMongoDBAtlasAdvancedClusterRead(ctx context.Context, d *schema.Reso
596605
return diag.FromErr(fmt.Errorf(errorClusterAdvancedSetting, "version_release_system", clusterName, err))
597606
}
598607

608+
if err := d.Set("accept_data_risks_and_force_replica_set_reconfig", cluster.AcceptDataRisksAndForceReplicaSetReconfig); err != nil {
609+
return diag.FromErr(fmt.Errorf(errorClusterAdvancedSetting, "accept_data_risks_and_force_replica_set_reconfig", clusterName, err))
610+
}
611+
599612
/*
600613
Get the advaced configuration options and set up to the terraform state
601614
*/
@@ -713,6 +726,10 @@ func resourceMongoDBAtlasAdvancedClusterUpdate(ctx context.Context, d *schema.Re
713726
cluster.VersionReleaseSystem = d.Get("version_release_system").(string)
714727
}
715728

729+
if d.HasChange("accept_data_risks_and_force_replica_set_reconfig") {
730+
cluster.AcceptDataRisksAndForceReplicaSetReconfig = d.Get("accept_data_risks_and_force_replica_set_reconfig").(string)
731+
}
732+
716733
if d.HasChange("paused") && !d.Get("paused").(bool) {
717734
cluster.Paused = pointy.Bool(d.Get("paused").(bool))
718735
}

mongodbatlas/resource_mongodbatlas_cluster.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ func resourceMongoDBAtlasCluster() *schema.Resource {
340340
Computed: true,
341341
ValidateFunc: validation.StringInSlice([]string{"LTS", "CONTINUOUS"}, false),
342342
},
343+
"accept_data_risks_and_force_replica_set_reconfig": {
344+
Type: schema.TypeString,
345+
Optional: true,
346+
Description: "Submit this field alongside your topology reconfiguration to request a new regional outage resistant topology",
347+
},
343348
},
344349
CustomizeDiff: resourceClusterCustomizeDiff,
345350
Timeouts: &schema.ResourceTimeout{
@@ -351,7 +356,12 @@ func resourceMongoDBAtlasCluster() *schema.Resource {
351356
}
352357

353358
func resourceMongoDBAtlasClusterCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
354-
// Get client connection.
359+
if v, ok := d.GetOk("accept_data_risks_and_force_replica_set_reconfig"); ok {
360+
if v.(string) != "" {
361+
return diag.FromErr(fmt.Errorf("accept_data_risks_and_force_replica_set_reconfig can not be set in creation, only in update"))
362+
}
363+
}
364+
355365
conn := meta.(*MongoDBClient).Atlas
356366

357367
projectID := d.Get("project_id").(string)
@@ -710,6 +720,10 @@ func resourceMongoDBAtlasClusterRead(ctx context.Context, d *schema.ResourceData
710720
return diag.FromErr(fmt.Errorf(errorClusterSetting, "version_release_system", clusterName, err))
711721
}
712722

723+
if err := d.Set("accept_data_risks_and_force_replica_set_reconfig", cluster.AcceptDataRisksAndForceReplicaSetReconfig); err != nil {
724+
return diag.FromErr(fmt.Errorf(errorClusterSetting, "accept_data_risks_and_force_replica_set_reconfig", clusterName, err))
725+
}
726+
713727
if providerName != "TENANT" {
714728
containers, _, err := conn.Containers.List(ctx, projectID,
715729
&matlas.ContainersListOptions{ProviderName: providerName})
@@ -850,6 +864,10 @@ func resourceMongoDBAtlasClusterUpdate(ctx context.Context, d *schema.ResourceDa
850864
cluster.VersionReleaseSystem = d.Get("version_release_system").(string)
851865
}
852866

867+
if d.HasChange("accept_data_risks_and_force_replica_set_reconfig") {
868+
cluster.AcceptDataRisksAndForceReplicaSetReconfig = d.Get("accept_data_risks_and_force_replica_set_reconfig").(string)
869+
}
870+
853871
if d.HasChange("termination_protection_enabled") {
854872
cluster.TerminationProtectionEnabled = pointy.Bool(d.Get("termination_protection_enabled").(bool))
855873
}

website/docs/r/advanced_cluster.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ This parameter defaults to false.
404404
ignore_changes = [paused]
405405
}`
406406
* `timeouts`- (Optional) The duration of time to wait for Cluster to be created, updated, or deleted. The timeout value is defined by a signed sequence of decimal numbers with an time unit suffix such as: `1h45m`, `300s`, `10m`, .... The valid time units are: `ns`, `us` (or `µs`), `ms`, `s`, `m`, `h`. The default timeout for Advanced Cluster create & delete is `3h`. Learn more about timeouts [here](https://www.terraform.io/plugin/sdkv2/resources/retries-and-customizable-timeouts).
407-
407+
* `accept_data_risks_and_force_replica_set_reconfig`- (Optional) If reconfiguration is necessary to regain a primary due to a regional outage, submit this field alongside your topology reconfiguration to request a new regional outage resistant topology. Forced reconfigurations during an outage of the majority of electable nodes carry a risk of data loss if replicated writes (even majority committed writes) have not been replicated to the new primary node. MongoDB Atlas docs contain more information. To proceed with an operation which carries that risk, set `accept_data_risks_and_force_replica_set_reconfig` to the current date. Learn more about Reconfiguring a Replica Set during a regional outage [here](https://dochub.mongodb.org/core/regional-outage-reconfigure-replica-set).
408408

409409
### bi_connector_config
410410

website/docs/r/cluster.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ But in order to explicitly change `provider_instance_size_name` comment the `lif
391391
- `CONTINUOUS`: Atlas creates your cluster using the most recent MongoDB release. Atlas automatically updates your cluster to the latest major and rapid MongoDB releases as they become available.
392392
- `LTS`: Atlas creates your cluster using the latest patch release of the MongoDB version that you specify in the mongoDBMajorVersion field. Atlas automatically updates your cluster to subsequent patch releases of this MongoDB version. Atlas doesn't update your cluster to newer rapid or major MongoDB releases as they become available.
393393
* `timeouts`- (Optional) The duration of time to wait for Cluster to be created, updated, or deleted. The timeout value is defined by a signed sequence of decimal numbers with an time unit suffix such as: `1h45m`, `300s`, `10m`, .... The valid time units are: `ns`, `us` (or `µs`), `ms`, `s`, `m`, `h`. The default timeout for Cluster create & delete is `3h`. Learn more about timeouts [here](https://www.terraform.io/plugin/sdkv2/resources/retries-and-customizable-timeouts).
394+
* `accept_data_risks_and_force_replica_set_reconfig`- (Optional) If reconfiguration is necessary to regain a primary due to a regional outage, submit this field alongside your topology reconfiguration to request a new regional outage resistant topology. Forced reconfigurations during an outage of the majority of electable nodes carry a risk of data loss if replicated writes (even majority committed writes) have not been replicated to the new primary node. MongoDB Atlas docs contain more information. To proceed with an operation which carries that risk, set `accept_data_risks_and_force_replica_set_reconfig` to the current date. Learn more about Reconfiguring a Replica Set during a regional outage [here](https://dochub.mongodb.org/core/regional-outage-reconfigure-replica-set).
394395

395396
### Multi-Region Cluster
396397

0 commit comments

Comments
 (0)