Skip to content

Commit 7f6ab7c

Browse files
authored
Adding autodefer parameter to automatically defer any maintenance (#499)
1 parent d461d37 commit 7f6ab7c

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ require (
1313
github.com/mwielbut/pointy v1.1.0
1414
github.com/spf13/cast v1.3.1
1515
github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20210625132053-af2d5c0ad54f
16-
go.mongodb.org/atlas v0.10.0
1716
go.mongodb.org/realm v0.0.0-20210618220639-e70c919266f2
17+
go.mongodb.org/atlas v0.10.2-0.20210727120023-4db32e8a2854
1818
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -963,8 +963,8 @@ go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
963963
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
964964
go.etcd.io/etcd v0.0.0-20200513171258-e048e166ab9c/go.mod h1:xCI7ZzBfRuGgBXyXO6yfWfDmlWd35khcWpUa4L0xI/k=
965965
go.mongodb.org/atlas v0.8.0/go.mod h1:MMWDsc2akjTDSG4tVQrxv/82p3QbBnqeELbtTl45sbg=
966-
go.mongodb.org/atlas v0.10.0 h1:kmwgoNjb2bEj4MmupkUmEx5G29BP01O59+Yd/O5Pf/k=
967-
go.mongodb.org/atlas v0.10.0/go.mod h1:MMWDsc2akjTDSG4tVQrxv/82p3QbBnqeELbtTl45sbg=
966+
go.mongodb.org/atlas v0.10.2-0.20210727120023-4db32e8a2854 h1:Ghz/RL5s1d1U0Va6fSrbbm8z/L5q4UPRSXEngOeYDDw=
967+
go.mongodb.org/atlas v0.10.2-0.20210727120023-4db32e8a2854/go.mod h1:MMWDsc2akjTDSG4tVQrxv/82p3QbBnqeELbtTl45sbg=
968968
go.mongodb.org/realm v0.0.0-20210618220639-e70c919266f2 h1:3ukcBKIOun3QRMZzdVRCU/7uVhjR7XQsdD/cCH5V8So=
969969
go.mongodb.org/realm v0.0.0-20210618220639-e70c919266f2/go.mod h1:Tru1+aHka6+4uXYigPKoNySbNWgtkfsanVddwmcqvOM=
970970
go.mozilla.org/mozlog v0.0.0-20170222151521-4bb13139d403/go.mod h1:jHoPAGnDrCy6kaI2tAze5Prf0Nr0w/oNkROt2lw3n3o=

mongodbatlas/resource_mongodbatlas_maintenance_window.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import (
1313
)
1414

1515
const (
16-
errorMaintenanceCreate = "error creating the MongoDB Atlas Maintenance Window (%s): %s"
17-
errorMaintenanceUpdate = "error updating the MongoDB Atlas Maintenance Window (%s): %s"
18-
errorMaintenanceRead = "error reading the MongoDB Atlas Maintenance Window (%s): %s"
19-
errorMaintenanceDelete = "error deleting the MongoDB Atlas Maintenance Window (%s): %s"
20-
errorMaintenanceDefer = "error deferring the MongoDB Atlas Maintenance Window (%s): %s"
16+
errorMaintenanceCreate = "error creating the MongoDB Atlas Maintenance Window (%s): %s"
17+
errorMaintenanceUpdate = "error updating the MongoDB Atlas Maintenance Window (%s): %s"
18+
errorMaintenanceRead = "error reading the MongoDB Atlas Maintenance Window (%s): %s"
19+
errorMaintenanceDelete = "error deleting the MongoDB Atlas Maintenance Window (%s): %s"
20+
errorMaintenanceDefer = "error deferring the MongoDB Atlas Maintenance Window (%s): %s"
21+
errorMaintenanceAutoDefer = "error auto deferring the MongoDB Atlas Maintenance Window (%s): %s"
2122
)
2223

2324
func resourceMongoDBAtlasMaintenanceWindow() *schema.Resource {
@@ -73,6 +74,11 @@ func resourceMongoDBAtlasMaintenanceWindow() *schema.Resource {
7374
Optional: true,
7475
Computed: true,
7576
},
77+
"auto_defer": {
78+
Type: schema.TypeBool,
79+
Optional: true,
80+
Computed: true,
81+
},
7682
},
7783
}
7884
}
@@ -90,6 +96,13 @@ func resourceMongoDBAtlasMaintenanceWindowCreate(ctx context.Context, d *schema.
9096
}
9197
}
9298

99+
if autoDeferValue := d.Get("auto_defer").(bool); autoDeferValue {
100+
_, err := conn.MaintenanceWindows.AutoDefer(ctx, projectID)
101+
if err != nil {
102+
return diag.FromErr(fmt.Errorf(errorMaintenanceAutoDefer, projectID, err))
103+
}
104+
}
105+
93106
maintenanceWindowReq := &matlas.MaintenanceWindow{}
94107

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

182+
if d.HasChange("auto_defer") {
183+
_, err := conn.MaintenanceWindows.AutoDefer(ctx, d.Id())
184+
if err != nil {
185+
return diag.FromErr(fmt.Errorf(errorMaintenanceAutoDefer, d.Id(), err))
186+
}
187+
}
188+
169189
if d.HasChange("day_of_week") {
170190
maintenanceWindowReq.DayOfWeek = cast.ToInt(d.Get("day_of_week"))
171191
}

website/docs/r/maintenance_window.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Once maintenance is scheduled for your cluster, you cannot change your maintenan
4646
* `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.
4747
* `number_of_deferrals` - Number of times the current maintenance event for this project has been deferred, you can set a maximum of 2 deferrals.
4848
* `defer` - Defer maintenance for the given project for one week.
49+
* `auto_defer` - Automatically defer any maintenance for the given project for one week.
4950

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

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

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

0 commit comments

Comments
 (0)