Skip to content

Commit

Permalink
[AlloyDB] Maintenance Windows Support (#10499)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmiglani authored Apr 24, 2024
1 parent 1a466f7 commit 3b74011
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 0 deletions.
50 changes: 50 additions & 0 deletions mmv1/products/alloydb/Cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,56 @@ properties:
description: |
Name of the primary cluster must be in the format
'projects/{project}/locations/{location}/clusters/{cluster_id}'
- !ruby/object:Api::Type::NestedObject
name: 'maintenanceUpdatePolicy'
description: |
MaintenanceUpdatePolicy defines the policy for system updates.
properties:
- !ruby/object:Api::Type::Array
name: 'maintenanceWindows'
description: |
Preferred windows to perform maintenance. Currently limited to 1.
item_type: !ruby/object:Api::Type::NestedObject
name: 'maintenanceWindow'
description: |
specifies a preferred day and time for maintenance.
properties:
- !ruby/object:Api::Type::Enum
name: 'day'
required: true
description: |
Preferred day of the week for maintenance, e.g. MONDAY, TUESDAY, etc.
values:
- :MONDAY
- :TUESDAY
- :WEDNESDAY
- :THURSDAY
- :FRIDAY
- :SATURDAY
- :SUNDAY
- !ruby/object:Api::Type::NestedObject
name: 'startTime'
required: true
description: |
Preferred time to start the maintenance operation on the specified day. Maintenance will start within 1 hour of this time.
properties:
- !ruby/object:Api::Type::Integer
name: hours
required: true
description: |
Hours of day in 24 hour format. Should be from 0 to 23.
- !ruby/object:Api::Type::Integer
name: minutes
description: |
Minutes of hour of day. Currently, only the value 0 is supported.
- !ruby/object:Api::Type::Integer
name: seconds
description: |
Seconds of minutes of the time. Currently, only the value 0 is supported.
- !ruby/object:Api::Type::Integer
name: nanos
description: |
Fractions of seconds in nanoseconds. Currently, only the value 0 is supported.
virtual_fields:
- !ruby/object:Api::Type::Enum
name: 'deletion_policy'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package alloydb_test

import (
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -1167,3 +1168,130 @@ resource "google_compute_global_address" "private_ip_alloc" {
`, context)
}

// Ensures cluster creation works with correctly specified maintenance update policy.
func TestAccAlloydbCluster_withMaintenanceWindows(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckAlloydbClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccAlloydbCluster_withMaintenanceWindows(context),
},
{
ResourceName: "google_alloydb_cluster.default",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccAlloydbCluster_withMaintenanceWindows(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_alloydb_cluster" "default" {
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
location = "us-central1"
network_config {
network = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.default.name}"
}
maintenance_update_policy {
maintenance_windows {
day = "WEDNESDAY"
start_time {
hours = 12
minutes = 0
seconds = 0
nanos = 0
}
}
}
}
data "google_project" "project" {}
resource "google_compute_network" "default" {
name = "tf-test-alloydb-cluster%{random_suffix}"
}
`, context)
}

// Ensures cluster creation throws expected errors for incorrect configurations of maintenance update policy.
func TestAccAlloydbCluster_withMaintenanceWindowsMissingFields(t *testing.T) {
t.Parallel()
acctest.SkipIfVcr(t)

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckAlloydbClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccAlloydbCluster_withMaintenanceWindowMissingStartTime(context),
ExpectError: regexp.MustCompile("Error: Insufficient start_time blocks"),
},
{
Config: testAccAlloydbCluster_withMaintenanceWindowMissingDay(context),
ExpectError: regexp.MustCompile("Error: Missing required argument"),
},
},
})
}

func testAccAlloydbCluster_withMaintenanceWindowMissingStartTime(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_alloydb_cluster" "default" {
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
location = "us-central1"
network = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.default.name}"
maintenance_update_policy {
maintenance_windows {
day = "WEDNESDAY"
}
}
}
resource "google_compute_network" "default" {
name = "tf-test-alloydb-cluster%{random_suffix}"
}
data "google_project" "project" {}
`, context)
}

func testAccAlloydbCluster_withMaintenanceWindowMissingDay(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_alloydb_cluster" "default" {
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
location = "us-central1"
network = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.default.name}"
maintenance_update_policy {
maintenance_windows {
start_time {
hours = 12
minutes = 0
seconds = 0
nanos = 0
}
}
}
}
resource "google_compute_network" "default" {
name = "tf-test-alloydb-cluster%{random_suffix}"
}
data "google_project" "project" {}
`, context)
}

0 comments on commit 3b74011

Please sign in to comment.