Skip to content

INTMDB-363: [Updated Feature] Add serverless backup to mongodbatlas_serverless_instance #830

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 3 commits into from
Sep 9, 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.16.1-0.20220531163122-551edbfb2f27
go.mongodb.org/atlas v0.16.1-0.20220823081124-819fb5448bfe
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 @@ -1234,8 +1234,8 @@ go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQc
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
go.mongodb.org/atlas v0.12.0/go.mod h1:wVCnHcm/7/IfTjEB6K8K35PLG70yGz8BdkRwX0oK9/M=
go.mongodb.org/atlas v0.16.1-0.20220531163122-551edbfb2f27 h1:rGTb8CaE9ZKNjmdUJ58jFcHopLg6o6Kzfm9AIayq1Hw=
go.mongodb.org/atlas v0.16.1-0.20220531163122-551edbfb2f27/go.mod h1:lQhRHIxc6jQHEK3/q9WLu/SdBkPj2fQYhjLGUF6Z3U8=
go.mongodb.org/atlas v0.16.1-0.20220823081124-819fb5448bfe h1:jmRFnzQejpiVo7xsPSCUYOqIzltc9Z95UuLr5fy5+qM=
go.mongodb.org/atlas v0.16.1-0.20220823081124-819fb5448bfe/go.mod h1:GUuW7/ZrHzCO0o47aiqhokN0N6i0GM3yraRyHIBTykU=
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
9 changes: 9 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("continuous_backup_enabled", serverlessInstance.ServerlessBackupOptions.ServerlessContinuousBackupEnabled); err != nil {
return diag.Errorf("error setting `state_name` for serverless instance (%s): %s", d.Id(), err)
}

d.SetId(encodeStateID(map[string]string{
"project_id": projectID.(string),
"name": instanceName.(string),
Expand Down Expand Up @@ -133,5 +137,10 @@ func returnServerlessInstanceDSSchema() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"continuous_backup_enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestAccDataSourceMongoDBAtlasServerlessInstance_byName(t *testing.T) {
resource.TestCheckResourceAttrSet(datasourceName, "state_name"),
resource.TestCheckResourceAttrSet(datasourceName, "create_date"),
resource.TestCheckResourceAttrSet(datasourceName, "mongo_db_version"),
resource.TestCheckResourceAttrSet(datasourceName, "continuous_backup_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,
"continuous_backup_enabled": serverlessInstances[i].ServerlessBackupOptions.ServerlessContinuousBackupEnabled,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestAccDataSourceMongoDBAtlasServerlessInstances_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(datasourceName, "results.0.id"),
resource.TestCheckResourceAttrSet(datasourceName, "results.0.name"),
resource.TestCheckResourceAttrSet(datasourceName, "results.0.state_name"),
resource.TestCheckResourceAttrSet(datasourceName, "results.0.continuous_backup_enabled"),
),
},
},
Expand Down
10 changes: 5 additions & 5 deletions mongodbatlas/resource_mongodbatlas_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,13 +416,13 @@ func resourceMongoDBAtlasProjectDelete(ctx context.Context, d *schema.ResourceDa
}

/*
This assumes the project CRUD outcome will be the same for any non-zero number of dependents
This assumes the project CRUD outcome will be the same for any non-zero number of dependents

If all dependents are deleting, wait to try and delete
Else consider the aggregate dependents idle.
If all dependents are deleting, wait to try and delete
Else consider the aggregate dependents idle.

If we get a defined error response, return that right away
Else retry
If we get a defined error response, return that right away
Else retry
*/
func resourceProjectDependentsDeletingRefreshFunc(ctx context.Context, projectID string, client *matlas.Client) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
Expand Down
23 changes: 21 additions & 2 deletions mongodbatlas/resource_mongodbatlas_serverless_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/mwielbut/pointy"
matlas "go.mongodb.org/atlas/mongodbatlas"
)

Expand Down Expand Up @@ -93,6 +94,11 @@ func returnServerlessInstanceSchema() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"continuous_backup_enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
}
}

Expand All @@ -117,6 +123,10 @@ func resourceMongoDBAtlasServerlessInstanceImportState(ctx context.Context, d *s
log.Printf(errorClusterSetting, "name", u.ID, err)
}

if err := d.Set("continuous_backup_enabled", u.ServerlessBackupOptions.ServerlessContinuousBackupEnabled); err != nil {
log.Printf(errorClusterSetting, "continuous_backup_enabled", u.ID, err)
}

d.SetId(encodeStateID(map[string]string{
"project_id": *projectID,
"name": u.Name,
Expand Down Expand Up @@ -215,6 +225,10 @@ func resourceMongoDBAtlasServerlessInstanceRead(ctx context.Context, d *schema.R
return diag.Errorf("error setting `state_name` 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 `continuous_backup_enabled` for serverless instance (%s): %s", d.Id(), err)
}

return nil
}

Expand All @@ -231,9 +245,14 @@ func resourceMongoDBAtlasServerlessInstanceCreate(ctx context.Context, d *schema
RegionName: d.Get("provider_settings_region_name").(string),
}

serverlessBackupOptions := &matlas.ServerlessBackupOptions{
ServerlessContinuousBackupEnabled: pointy.Bool(d.Get("continuous_backup_enabled").(bool)),
}

serverlessInstanceRequest := &matlas.ServerlessCreateRequestParams{
Name: name,
ProviderSettings: serverlessProviderSettings,
Name: name,
ProviderSettings: serverlessProviderSettings,
ServerlessBackupOptions: serverlessBackupOptions,
}

_, _, err := conn.ServerlessInstances.Create(ctx, projectID, serverlessInstanceRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func testAccMongoDBAtlasServerlessInstanceConfig(projectID, name string) string
provider_settings_backing_provider_name = "AWS"
provider_settings_provider_name = "SERVERLESS"
provider_settings_region_name = "US_EAST_1"
continuous_backup_enabled = true
}

`, projectID, name)
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/serverless_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ data "mongodbatlas_serverless_instance" "test_two" {
* `provider_settings_provider_name` - Cloud service provider that applies to the provisioned the serverless instance.
* `provider_settings_region_name` - Human-readable label that identifies the physical location of your MongoDB serverless instance. The region you choose can affect network latency for clients accessing your databases.
* `state_name` - Stage of deployment of this serverless instance when the resource made its request.
* `continuous_backup_enabled` - Flag that indicates whether the serverless instance uses Serverless Continuous Backup.

For more information see: [MongoDB Atlas API - Serverless Instance](https://docs.atlas.mongodb.com/reference/api/serverless-instances/) Documentation.
1 change: 1 addition & 0 deletions website/docs/d/serverless_instances.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ data "mongodbatlas_serverless_instances" "data_serverless" {
* `provider_settings_provider_name` - Cloud service provider that applies to the provisioned the serverless instance.
* `provider_settings_region_name` - Human-readable label that identifies the physical location of your MongoDB serverless instance. The region you choose can affect network latency for clients accessing your databases.
* `state_name` - Stage of deployment of this serverless instance when the resource made its request.
* `continuous_backup_enabled` - Flag that indicates whether the serverless instance uses Serverless Continuous Backup.



Expand Down
1 change: 1 addition & 0 deletions website/docs/r/serverless_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ resource "mongodbatlas_serverless_instance" "test" {
* `provider_settings_provider_name` - (Required) Cloud service provider that applies to the provisioned the serverless instance.
* `provider_settings_region_name` - (Required)
Human-readable label that identifies the physical location of your MongoDB serverless instance. The region you choose can affect network latency for clients accessing your databases.
* `continuous_backup_enabled` - (Optional) Flag that indicates whether the serverless instance uses [Serverless Continuous Backup](https://www.mongodb.com/docs/atlas/configure-serverless-backup). If this parameter is false or not used, the serverless instance uses [Basic Backup](https://www.mongodb.com/docs/atlas/configure-serverless-backup).

## Attributes Reference

Expand Down