From a5d21d2b2d086c4bd0ff71bebba10c7ade711827 Mon Sep 17 00:00:00 2001 From: Moritz Reinhardt <154784+moreinhardt@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:58:38 +0100 Subject: [PATCH] Add maintenance day validation for database and kubernetes clusters (#1293) * database: Add validation to maintenance window and improve docs * kubernetes: Add validation to maintenance_policy * k8s: wrap ValidateFunc --------- Co-authored-by: Andrew Starr-Bochicchio Co-authored-by: Andrew Starr-Bochicchio --- digitalocean/database/resource_database_cluster.go | 5 +++-- .../kubernetes/resource_kubernetes_cluster.go | 11 +++++++++++ docs/resources/database_cluster.md | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/digitalocean/database/resource_database_cluster.go b/digitalocean/database/resource_database_cluster.go index 8331dea22..2ef9c803b 100644 --- a/digitalocean/database/resource_database_cluster.go +++ b/digitalocean/database/resource_database_cluster.go @@ -96,8 +96,9 @@ func ResourceDigitalOceanDatabaseCluster() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "day": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.IsDayOfTheWeek(true), }, "hour": { Type: schema.TypeString, diff --git a/digitalocean/kubernetes/resource_kubernetes_cluster.go b/digitalocean/kubernetes/resource_kubernetes_cluster.go index 9abb46df8..2b548b3bd 100644 --- a/digitalocean/kubernetes/resource_kubernetes_cluster.go +++ b/digitalocean/kubernetes/resource_kubernetes_cluster.go @@ -124,6 +124,17 @@ func ResourceDigitalOceanKubernetesCluster() *schema.Resource { Type: schema.TypeString, Optional: true, Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + "any", + "monday", + "tuesday", + "wednesday", + "thursday", + "friday", + "saturday", + "sunday"}, + true, + ), }, "start_time": { Type: schema.TypeString, diff --git a/docs/resources/database_cluster.md b/docs/resources/database_cluster.md index e5b7da774..7e89253a8 100644 --- a/docs/resources/database_cluster.md +++ b/docs/resources/database_cluster.md @@ -133,8 +133,8 @@ The following arguments are supported: `maintenance_window` supports the following: -* `day` - (Required) The day of the week on which to apply maintenance updates. -* `hour` - (Required) The hour in UTC at which maintenance updates will be applied in 24 hour format. +* `day` - (Required) The day of the week on which to apply maintenance updates. May be one of `monday` through `sunday`. +* `hour` - (Required) The hour in UTC at which maintenance updates will be applied as a string in 24 hour format, e.g. `13:00`. * `backup_restore` - (Optional) Create a new database cluster based on a backup of an existing cluster.