Skip to content

Commit c55ad0d

Browse files
authored
feat(datastore): Add support for maintenance window (#19)
* feat(datastore): Add support for maintenance window * feat(datastore): fix issues and make it work * follow existing pattern * remove computed true * remove build * set to null otherwise
1 parent 7cdb720 commit c55ad0d

File tree

3 files changed

+71
-10
lines changed

3 files changed

+71
-10
lines changed

internal/provider/datastore.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,24 @@ func (r *datastoreResource) Schema(_ context.Context, _ resource.SchemaRequest,
158158
},
159159
},
160160
},
161+
"maintenance_window": schema.SingleNestedAttribute{
162+
MarkdownDescription: "The maintenance window configuration for the datastore.",
163+
Optional: true,
164+
Attributes: map[string]schema.Attribute{
165+
"weekday": schema.Int64Attribute{
166+
MarkdownDescription: "The day of the week to start the maintenance window. 0-6, 0 is Sunday.",
167+
Optional: true,
168+
},
169+
"hour": schema.Int64Attribute{
170+
MarkdownDescription: "The hour of the day to start the maintenance window. 0-23.",
171+
Optional: true,
172+
},
173+
"duration_hours": schema.Int64Attribute{
174+
MarkdownDescription: "DurationHours is the duration of the maintenance window in hours. 0 means maintenance is always allowed.",
175+
Optional: true,
176+
},
177+
},
178+
},
161179
},
162180
}
163181
}

internal/resource_model/datastore.go

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ import (
1212

1313
// Datastore maps the resource schema data.
1414
type Datastore struct {
15-
ID types.String `tfsdk:"id"`
16-
Name types.String `tfsdk:"name"`
17-
NetworkId types.String `tfsdk:"network_id"`
18-
Location DatastoreLocation `tfsdk:"location"`
19-
Tier DatastoreTier `tfsdk:"tier"`
20-
Dragonfly types.Object `tfsdk:"dragonfly"`
21-
CreatedAt types.Int64 `tfsdk:"created_at"`
22-
Password types.String `tfsdk:"password"`
23-
Addr types.String `tfsdk:"addr"`
24-
DisablePassKey types.Bool `tfsdk:"disable_pass_key"`
15+
ID types.String `tfsdk:"id"`
16+
Name types.String `tfsdk:"name"`
17+
NetworkId types.String `tfsdk:"network_id"`
18+
Location DatastoreLocation `tfsdk:"location"`
19+
Tier DatastoreTier `tfsdk:"tier"`
20+
Dragonfly types.Object `tfsdk:"dragonfly"`
21+
CreatedAt types.Int64 `tfsdk:"created_at"`
22+
Password types.String `tfsdk:"password"`
23+
Addr types.String `tfsdk:"addr"`
24+
DisablePassKey types.Bool `tfsdk:"disable_pass_key"`
25+
MaintenanceWindow types.Object `tfsdk:"maintenance_window"`
2526
}
2627

2728
type DatastoreLocation struct {
@@ -50,6 +51,24 @@ func (d *Datastore) FromConfig(ctx context.Context, in *dfcloud.Datastore) {
5051
d.Tier.PerformanceTier = types.StringValue(string(in.Config.Tier.PerformanceTier))
5152
d.Tier.Replicas = types.Int64Value(int64(*in.Config.Tier.Replicas))
5253

54+
if in.Config.MaintenanceWindow.DurationHours != nil || in.Config.MaintenanceWindow.Hour != nil || in.Config.MaintenanceWindow.Weekday != nil {
55+
d.MaintenanceWindow = types.ObjectValueMust(map[string]attr.Type{
56+
"weekday": types.Int64Type,
57+
"hour": types.Int64Type,
58+
"duration_hours": types.Int64Type,
59+
}, map[string]attr.Value{
60+
"weekday": types.Int64Value(int64(lo.FromPtr(in.Config.MaintenanceWindow.Weekday))),
61+
"hour": types.Int64Value(int64(lo.FromPtr(in.Config.MaintenanceWindow.Hour))),
62+
"duration_hours": types.Int64Value(int64(lo.FromPtr(in.Config.MaintenanceWindow.DurationHours))),
63+
})
64+
} else {
65+
d.MaintenanceWindow = types.ObjectNull(map[string]attr.Type{
66+
"weekday": types.Int64Type,
67+
"hour": types.Int64Type,
68+
"duration_hours": types.Int64Type,
69+
})
70+
}
71+
5372
aclRules, _ := types.ListValueFrom(ctx, types.StringType, in.Config.Dragonfly.AclRules)
5473
d.Dragonfly = types.ObjectValueMust(map[string]attr.Type{
5574
"cache_mode": types.BoolType,
@@ -135,6 +154,18 @@ func IntoDatastoreConfig(in Datastore) *dfcloud.Datastore {
135154
datastore.Config.Dragonfly.AclRules = &rules
136155
}
137156

157+
if in.MaintenanceWindow.Attributes()["weekday"] != nil {
158+
datastore.Config.MaintenanceWindow.Weekday = lo.ToPtr(int(in.MaintenanceWindow.Attributes()["weekday"].(types.Int64).ValueInt64()))
159+
}
160+
161+
if in.MaintenanceWindow.Attributes()["hour"] != nil {
162+
datastore.Config.MaintenanceWindow.Hour = lo.ToPtr(int(in.MaintenanceWindow.Attributes()["hour"].(types.Int64).ValueInt64()))
163+
}
164+
165+
if in.MaintenanceWindow.Attributes()["duration_hours"] != nil {
166+
datastore.Config.MaintenanceWindow.DurationHours = lo.ToPtr(int(in.MaintenanceWindow.Attributes()["duration_hours"].(types.Int64).ValueInt64()))
167+
}
168+
138169
return datastore
139170
}
140171

internal/sdk/datastore.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,21 @@ type DatastoreConfig struct {
7575

7676
Restore RestoreBackup `json:"restore"`
7777

78+
MaintenanceWindow MaintenanceWindow `json:"maintenance_window,omitempty"`
79+
7880
DisablePasskey bool `json:"disable_passkey"`
7981
}
8082

83+
type MaintenanceWindow struct {
84+
// Weekday is the day of the week to start the maintenance window. 0-6, 0 is Sunday.
85+
Weekday *int `json:"weekday"`
86+
// Hour is the hour of the day to start the maintenance window. 0-23.
87+
Hour *int `json:"hour"`
88+
// DurationHours is the duration of the maintenance window in hours.
89+
// 0 means maintenance is always allowed.
90+
DurationHours *int `json:"duration_hours"`
91+
}
92+
8193
type RestoreBackup struct {
8294
// Backup contains the ID of the backup to restore.
8395
BackupId string `json:"backup_id"`

0 commit comments

Comments
 (0)