Skip to content

Commit f91f46c

Browse files
authored
feat: Changes hour_of_day in mongodbatlas_maintenance_window to Required (#3499)
* change hour_of_day to required * correct start_asap * changelong * test
1 parent df86e19 commit f91f46c

File tree

6 files changed

+24
-48
lines changed

6 files changed

+24
-48
lines changed

.changelog/3499.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:breaking-change
2+
resource/mongodbatlas_maintenance_window: Changes `hour_of_day` to Required
3+
```
4+
5+
```release-note:breaking-change
6+
resource/mongodbatlas_maintenance_window: Changes `start_asap` to Computed only
7+
```

docs/data-sources/maintenance_window.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ In addition to all arguments above, the following attributes are exported:
4141

4242
* `day_of_week` - Day of the week when you would like the maintenance window to start as a 1-based integer: Su=1, M=2, T=3, W=4, T=5, F=6, Sa=7.
4343
* `hour_of_day` - Hour of the day when you would like the maintenance window to start. This parameter uses the 24-hour clock, where midnight is 0, noon is 12 (Time zone is UTC).
44-
* `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.
44+
* `start_asap` - Flag indicating whether project maintenance has been directed to start immediately. If requested, this field returns true from the time the request was made until the time the maintenance event completes.
4545
* `number_of_deferrals` - Number of times the current maintenance event for this project has been deferred, there can be a maximum of 2 deferrals.
4646
* `auto_defer_once_enabled` - Flag that indicates whether you want to defer all maintenance windows one week they would be triggered.
4747
* `protected_hours` - (Optional) Defines the time period during which there will be no standard updates to the clusters. See [Protected Hours](#protected-hours).
@@ -52,4 +52,4 @@ In addition to all arguments above, the following attributes are exported:
5252
* `end_hour_of_day` - Zero-based integer that represents the end hour of the day for the protected hours window.
5353

5454

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

docs/resources/maintenance_window.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,12 @@ Once maintenance is scheduled for your cluster, you cannot change your maintenan
4141

4242
* `project_id` - The unique identifier of the project for the Maintenance Window.
4343
* `day_of_week` - (Required) Day of the week when you would like the maintenance window to start as a 1-based integer: Su=1, M=2, T=3, W=4, T=5, F=6, Sa=7.
44-
* `hour_of_day` - Hour of the day when you would like the maintenance window to start. This parameter uses the 24-hour clock, where midnight is 0, noon is 12 (Time zone is UTC). Defaults to 0.
45-
* `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.
44+
* `hour_of_day` - (Required) Hour of the day when you would like the maintenance window to start. This parameter uses the 24-hour clock, where midnight is 0, noon is 12 (Time zone is UTC).
4645
* `defer` - Defer the next scheduled maintenance for the given project for one week.
4746
* `auto_defer` - Defer any scheduled maintenance for the given project for one week.
4847
* `auto_defer_once_enabled` - Flag that indicates whether you want to defer all maintenance windows one week they would be triggered.
4948
* `protected_hours` - (Optional) Defines the time period during which there will be no standard updates to the clusters. See [Protected Hours](#protected-hours).
5049

51-
-> **NOTE:** The `start_asap` attribute can't be used because of breaks the Terraform flow, but you can enable via API.
52-
5350
### Protected Hours
5451
* `start_hour_of_day` - Zero-based integer that represents the beginning hour of the day for the protected hours window.
5552
- `end_hour_of_day` - Zero-based integer that represents the end hour of the day for the protected hours window.
@@ -60,6 +57,9 @@ In addition to all arguments above, the following attributes are exported:
6057

6158
* `number_of_deferrals` - Number of times the current maintenance event for this project has been deferred, there can be a maximum of 2 deferrals.
6259
* `time_zone_id` - Identifier for the current time zone of the maintenance window. This can only be updated via the Project Settings UI.
60+
* `start_asap` - Flag indicating whether project maintenance has been directed to start immediately. If requested, this field returns true from the time the request was made until the time the maintenance event completes.
61+
62+
-> **NOTE:** The `start_asap` attribute can only be enabled via API.
6363

6464
## Import
6565

internal/service/maintenancewindow/resource_maintenance_window.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ func Resource() *schema.Resource {
4949
},
5050
},
5151
"hour_of_day": {
52-
Type: schema.TypeInt,
53-
Optional: true,
54-
Computed: true,
55-
ConflictsWith: []string{"start_asap"},
52+
Type: schema.TypeInt,
53+
Required: true,
5654
ValidateFunc: func(val any, key string) (warns []string, errs []error) {
5755
v := val.(int)
5856
if v < 0 || v > 23 {
@@ -63,7 +61,6 @@ func Resource() *schema.Resource {
6361
},
6462
"start_asap": {
6563
Type: schema.TypeBool,
66-
Optional: true,
6764
Computed: true,
6865
},
6966
"number_of_deferrals": {
@@ -124,9 +121,7 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.
124121
params := new(admin.GroupMaintenanceWindow)
125122

126123
params.DayOfWeek = cast.ToInt(d.Get("day_of_week"))
127-
128-
hourOfDay := d.Get("hour_of_day")
129-
params.HourOfDay = conversion.Pointer(cast.ToInt(hourOfDay)) // during creation of maintenance window hourOfDay needs to be set in PATCH to avoid errors, 0 value is sent when absent
124+
params.HourOfDay = conversion.Pointer(cast.ToInt(d.Get("hour_of_day")))
130125

131126
if autoDeferOnceEnabled, ok := d.GetOk("auto_defer_once_enabled"); ok {
132127
params.AutoDeferOnceEnabled = conversion.Pointer(autoDeferOnceEnabled.(bool))

internal/service/maintenancewindow/resource_maintenance_window_migration_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"testing"
66

77
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
8-
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
98
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
109
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
1110
"github.com/spf13/cast"
@@ -17,7 +16,7 @@ func TestMigConfigMaintenanceWindow_basic(t *testing.T) {
1716
projectName = acc.RandomProjectName()
1817
dayOfWeek = 7
1918
hourOfDay = 3
20-
config = configBasic(orgID, projectName, dayOfWeek, conversion.Pointer(hourOfDay), nil)
19+
config = configBasic(orgID, projectName, dayOfWeek, hourOfDay, nil)
2120
)
2221

2322
resource.ParallelTest(t, resource.TestCase{

internal/service/maintenancewindow/resource_maintenance_window_test.go

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,19 @@ func TestAccConfigRSMaintenanceWindow_basic(t *testing.T) {
4545
CheckDestroy: checkDestroy,
4646
Steps: []resource.TestStep{
4747
{
48-
// testing hour_of_day set to 0 during creation phase does not return errors
49-
Config: configBasic(orgID, projectName, dayOfWeek, conversion.Pointer(hourOfDay), defaultProtectedHours),
48+
Config: configBasic(orgID, projectName, dayOfWeek, hourOfDay, defaultProtectedHours),
5049
Check: checkBasic(dayOfWeek, hourOfDay, defaultProtectedHours),
5150
},
5251
{
53-
Config: configBasic(orgID, projectName, dayOfWeek, conversion.Pointer(hourOfDayUpdated), updatedProtectedHours),
52+
Config: configBasic(orgID, projectName, dayOfWeek, hourOfDayUpdated, updatedProtectedHours),
5453
Check: checkBasic(dayOfWeek, hourOfDayUpdated, updatedProtectedHours),
5554
},
5655
{
57-
Config: configBasic(orgID, projectName, dayOfWeekUpdated, conversion.Pointer(hourOfDay), nil),
56+
Config: configBasic(orgID, projectName, dayOfWeekUpdated, hourOfDay, nil),
5857
Check: checkBasic(dayOfWeekUpdated, hourOfDay, nil),
5958
},
6059
{
61-
Config: configBasic(orgID, projectName, dayOfWeek, conversion.Pointer(hourOfDay), defaultProtectedHours),
60+
Config: configBasic(orgID, projectName, dayOfWeek, hourOfDay, defaultProtectedHours),
6261
Check: checkBasic(dayOfWeek, hourOfDay, defaultProtectedHours),
6362
},
6463
{
@@ -71,26 +70,6 @@ func TestAccConfigRSMaintenanceWindow_basic(t *testing.T) {
7170
})
7271
}
7372

74-
func TestAccConfigRSMaintenanceWindow_emptyHourOfDay(t *testing.T) {
75-
var (
76-
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
77-
projectName = acc.RandomProjectName()
78-
dayOfWeek = 7
79-
)
80-
81-
resource.ParallelTest(t, resource.TestCase{
82-
PreCheck: func() { acc.PreCheckBasic(t) },
83-
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
84-
CheckDestroy: checkDestroy,
85-
Steps: []resource.TestStep{
86-
{
87-
Config: configBasic(orgID, projectName, dayOfWeek, nil, defaultProtectedHours),
88-
Check: checkBasic(dayOfWeek, 0, defaultProtectedHours),
89-
},
90-
},
91-
})
92-
}
93-
9473
func TestAccConfigRSMaintenanceWindow_autoDeferActivated(t *testing.T) {
9574
var (
9675
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
@@ -167,11 +146,7 @@ func importStateIDFunc(resourceName string) resource.ImportStateIdFunc {
167146
}
168147
}
169148

170-
func configBasic(orgID, projectName string, dayOfWeek int, hourOfDay *int, protectedHours *admin.ProtectedHours) string {
171-
hourOfDayAttr := ""
172-
if hourOfDay != nil {
173-
hourOfDayAttr = fmt.Sprintf("hour_of_day = %d", *hourOfDay)
174-
}
149+
func configBasic(orgID, projectName string, dayOfWeek, hourOfDay int, protectedHours *admin.ProtectedHours) string {
175150
protectedHoursStr := ""
176151
if protectedHours != nil {
177152
protectedHoursStr = fmt.Sprintf(`
@@ -189,10 +164,10 @@ func configBasic(orgID, projectName string, dayOfWeek int, hourOfDay *int, prote
189164
resource "mongodbatlas_maintenance_window" "test" {
190165
project_id = mongodbatlas_project.test.id
191166
day_of_week = %[3]d
192-
%[4]s
167+
hour_of_day = %[4]d
193168
%[5]s
194169
195-
}`, orgID, projectName, dayOfWeek, hourOfDayAttr, protectedHoursStr)
170+
}`, orgID, projectName, dayOfWeek, hourOfDay, protectedHoursStr)
196171
}
197172

198173
func configWithAutoDeferEnabled(orgID, projectName string, dayOfWeek, hourOfDay int) string {

0 commit comments

Comments
 (0)