From c24907e91bf20bcc1f15f97f5685a7e0e4e81d1b Mon Sep 17 00:00:00 2001 From: Alexey Wasilyev Date: Fri, 26 Mar 2021 15:09:46 +0100 Subject: [PATCH] fix for support for maintenance start time (15331) --- aws/resource_aws_storagegateway_gateway.go | 36 ++++++++++++++----- ...esource_aws_storagegateway_gateway_test.go | 19 +++++----- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/aws/resource_aws_storagegateway_gateway.go b/aws/resource_aws_storagegateway_gateway.go index b57856585a7..521e4ae8134 100644 --- a/aws/resource_aws_storagegateway_gateway.go +++ b/aws/resource_aws_storagegateway_gateway.go @@ -223,28 +223,43 @@ func resourceAwsStorageGatewayGateway() *schema.Resource { "ipv4_address": { Type: schema.TypeString, Computed: true, + }, + }, + }, + }, "maintenance_start_time": { Type: schema.TypeList, Optional: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "hour": { + "hour_of_day": { Type: schema.TypeInt, Required: true, ValidateFunc: validation.IntBetween(0, 23), + Default: 0, + Computed: true, }, - "minute": { + "minute_of_hour": { Type: schema.TypeInt, Optional: true, ValidateFunc: validation.IntBetween(0, 59), Default: 0, + Computed: true, }, "day_of_week": { Type: schema.TypeInt, Optional: true, ValidateFunc: validation.IntBetween(0, 6), Default: 0, + Computed: true, + }, + "day_of_month": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(1, 28), + Default: 0, + Computed: true, }, }, }, @@ -405,9 +420,10 @@ func resourceAwsStorageGatewayGatewayCreate(d *schema.ResourceData, meta interfa input := &storagegateway.UpdateMaintenanceStartTimeInput{ DayOfWeek: aws.Int64(int64(m["day_of_week"].(int))), + DayOfMonth: aws.Int64(int64(m["day_of_month"].(int))), GatewayARN: aws.String(d.Id()), - HourOfDay: aws.Int64(int64(m["hour"].(int))), - MinuteOfHour: aws.Int64(int64(m["minute"].(int))), + HourOfDay: aws.Int64(int64(m["hour_of_day"].(int))), + MinuteOfHour: aws.Int64(int64(m["minute_of_hour"].(int))), } log.Printf("[DEBUG] Storage Gateway Gateway %q updating maintenance start time", d.Id()) @@ -582,9 +598,10 @@ func resourceAwsStorageGatewayGatewayRead(d *schema.ResourceData, meta interface } if err == nil { m := map[string]interface{}{ - "hour": aws.Int64Value(maintenanceStartTimeOutput.HourOfDay), - "minute": aws.Int64Value(maintenanceStartTimeOutput.MinuteOfHour), - "day_of_week": aws.Int64Value(maintenanceStartTimeOutput.DayOfWeek), + "hour_of_day": aws.Int64Value(maintenanceStartTimeOutput.HourOfDay), + "minute_of_hour": aws.Int64Value(maintenanceStartTimeOutput.MinuteOfHour), + "day_of_week": aws.Int64Value(maintenanceStartTimeOutput.DayOfWeek), + "day_of_month": aws.Int64Value(maintenanceStartTimeOutput.DayOfMonth), } if err := d.Set("maintenance_start_time", []map[string]interface{}{m}); err != nil { return fmt.Errorf("error setting maintenance_start_time: %w", err) @@ -727,9 +744,10 @@ func resourceAwsStorageGatewayGatewayUpdate(d *schema.ResourceData, meta interfa input := &storagegateway.UpdateMaintenanceStartTimeInput{ DayOfWeek: aws.Int64(int64(m["day_of_week"].(int))), + DayOfMonth: aws.Int64(int64(m["day_of_month"].(int))), GatewayARN: aws.String(d.Id()), - HourOfDay: aws.Int64(int64(m["hour"].(int))), - MinuteOfHour: aws.Int64(int64(m["minute"].(int))), + HourOfDay: aws.Int64(int64(m["hour_of_day"].(int))), + MinuteOfHour: aws.Int64(int64(m["minute_of_month"].(int))), } log.Printf("[DEBUG] Storage Gateway Gateway %q updating maintenance start time", d.Id()) diff --git a/aws/resource_aws_storagegateway_gateway_test.go b/aws/resource_aws_storagegateway_gateway_test.go index 20e87d65434..255ba0d1d76 100644 --- a/aws/resource_aws_storagegateway_gateway_test.go +++ b/aws/resource_aws_storagegateway_gateway_test.go @@ -1215,18 +1215,19 @@ resource "aws_storagegateway_gateway" "test" { `, rName, rate) } -func testAccAWSStorageGatewayGatewayMaintenanceStartTimeConfig(rName string, hour int, minute int, day_of_week int) string { +func testAccAWSStorageGatewayGatewayMaintenanceStartTimeConfig(rName string, hour_of_day int, minute_of_hour int, day_of_week int, day_of_month int) string { return testAccAWSStorageGateway_TapeAndVolumeGatewayBase(rName) + fmt.Sprintf(` resource "aws_storagegateway_gateway" "test" { - gateway_ip_address = aws_instance.test.public_ip - gateway_name = %[1]q - gateway_timezone = "GMT" - gateway_type = "CACHED" + gateway_ip_address = aws_instance.test.public_ip + gateway_name = %[1]q + gateway_timezone = "GMT" + gateway_type = "CACHED" maintenance_start_time { - hour = %[2]d - minute = %[3]d - day_of_week = %[4]d + hour_of_day = %[2]d + minute_of_hour = %[3]d + day_of_week = %[4]d + day_of_month = %[5]d } } -`, rName, hour, minute, day_of_week) +`, rName, hour_of_day, minute_of_hour, day_of_week, day_of_month) }