Skip to content
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

Adding autodefer parameter to automatically defer any maintenance #499

Merged
merged 1 commit into from
Jul 29, 2021
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 @@ -13,6 +13,6 @@ require (
github.com/mwielbut/pointy v1.1.0
github.com/spf13/cast v1.3.1
github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20210625132053-af2d5c0ad54f
go.mongodb.org/atlas v0.10.0
go.mongodb.org/realm v0.0.0-20210618220639-e70c919266f2
go.mongodb.org/atlas v0.10.2-0.20210727120023-4db32e8a2854
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -997,8 +997,8 @@ go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
go.etcd.io/etcd v0.0.0-20200513171258-e048e166ab9c/go.mod h1:xCI7ZzBfRuGgBXyXO6yfWfDmlWd35khcWpUa4L0xI/k=
go.mongodb.org/atlas v0.8.0/go.mod h1:MMWDsc2akjTDSG4tVQrxv/82p3QbBnqeELbtTl45sbg=
go.mongodb.org/atlas v0.10.0 h1:kmwgoNjb2bEj4MmupkUmEx5G29BP01O59+Yd/O5Pf/k=
go.mongodb.org/atlas v0.10.0/go.mod h1:MMWDsc2akjTDSG4tVQrxv/82p3QbBnqeELbtTl45sbg=
go.mongodb.org/atlas v0.10.2-0.20210727120023-4db32e8a2854 h1:Ghz/RL5s1d1U0Va6fSrbbm8z/L5q4UPRSXEngOeYDDw=
go.mongodb.org/atlas v0.10.2-0.20210727120023-4db32e8a2854/go.mod h1:MMWDsc2akjTDSG4tVQrxv/82p3QbBnqeELbtTl45sbg=
go.mongodb.org/realm v0.0.0-20210618220639-e70c919266f2 h1:3ukcBKIOun3QRMZzdVRCU/7uVhjR7XQsdD/cCH5V8So=
go.mongodb.org/realm v0.0.0-20210618220639-e70c919266f2/go.mod h1:Tru1+aHka6+4uXYigPKoNySbNWgtkfsanVddwmcqvOM=
go.mozilla.org/mozlog v0.0.0-20170222151521-4bb13139d403/go.mod h1:jHoPAGnDrCy6kaI2tAze5Prf0Nr0w/oNkROt2lw3n3o=
Expand Down
30 changes: 25 additions & 5 deletions mongodbatlas/resource_mongodbatlas_maintenance_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import (
)

const (
errorMaintenanceCreate = "error creating the MongoDB Atlas Maintenance Window (%s): %s"
errorMaintenanceUpdate = "error updating the MongoDB Atlas Maintenance Window (%s): %s"
errorMaintenanceRead = "error reading the MongoDB Atlas Maintenance Window (%s): %s"
errorMaintenanceDelete = "error deleting the MongoDB Atlas Maintenance Window (%s): %s"
errorMaintenanceDefer = "error deferring the MongoDB Atlas Maintenance Window (%s): %s"
errorMaintenanceCreate = "error creating the MongoDB Atlas Maintenance Window (%s): %s"
errorMaintenanceUpdate = "error updating the MongoDB Atlas Maintenance Window (%s): %s"
errorMaintenanceRead = "error reading the MongoDB Atlas Maintenance Window (%s): %s"
errorMaintenanceDelete = "error deleting the MongoDB Atlas Maintenance Window (%s): %s"
errorMaintenanceDefer = "error deferring the MongoDB Atlas Maintenance Window (%s): %s"
errorMaintenanceAutoDefer = "error auto deferring the MongoDB Atlas Maintenance Window (%s): %s"
)

func resourceMongoDBAtlasMaintenanceWindow() *schema.Resource {
Expand Down Expand Up @@ -73,6 +74,11 @@ func resourceMongoDBAtlasMaintenanceWindow() *schema.Resource {
Optional: true,
Computed: true,
},
"auto_defer": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
}
}
Expand All @@ -90,6 +96,13 @@ func resourceMongoDBAtlasMaintenanceWindowCreate(ctx context.Context, d *schema.
}
}

if autoDeferValue := d.Get("auto_defer").(bool); autoDeferValue {
_, err := conn.MaintenanceWindows.AutoDefer(ctx, projectID)
if err != nil {
return diag.FromErr(fmt.Errorf(errorMaintenanceAutoDefer, projectID, err))
}
}

maintenanceWindowReq := &matlas.MaintenanceWindow{}

if dayOfWeek, ok := d.GetOk("day_of_week"); ok {
Expand Down Expand Up @@ -166,6 +179,13 @@ func resourceMongoDBAtlasMaintenanceWindowUpdate(ctx context.Context, d *schema.
}
}

if d.HasChange("auto_defer") {
_, err := conn.MaintenanceWindows.AutoDefer(ctx, d.Id())
if err != nil {
return diag.FromErr(fmt.Errorf(errorMaintenanceAutoDefer, d.Id(), err))
}
}

if d.HasChange("day_of_week") {
maintenanceWindowReq.DayOfWeek = cast.ToInt(d.Get("day_of_week"))
}
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/maintenance_window.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Once maintenance is scheduled for your cluster, you cannot change your maintenan
* `start_asap` - Flag indicating whether project maintenance has been directed to start immediately. If you request that maintenance begin immediately, this field returns true from the time the request was made until the time the maintenance event completes.
* `number_of_deferrals` - Number of times the current maintenance event for this project has been deferred, you can set a maximum of 2 deferrals.
* `defer` - Defer maintenance for the given project for one week.
* `auto_defer` - Automatically defer any maintenance for the given project for one week.

-> **NOTE:** The `start_asap` attribute can't be used because of breaks the Terraform flow, but you can enable via API.

Expand All @@ -57,4 +58,4 @@ Maintenance Window entries can be imported using project project_id, in the form
$ terraform import mongodbatlas_maintenance_window.test 5d0f1f73cf09a29120e173cf
```

For more information see: [MongoDB Atlas API Reference.](https://docs.atlas.mongodb.com/reference/api/maintenance-windows/)
For more information see: [MongoDB Atlas API Reference.](https://docs.atlas.mongodb.com/reference/api/maintenance-windows/)