Skip to content

Commit

Permalink
fix for support for maintenance start time (15331)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Wasilyev committed Mar 26, 2021
1 parent 598099a commit c24907e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
36 changes: 27 additions & 9 deletions aws/resource_aws_storagegateway_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
19 changes: 10 additions & 9 deletions aws/resource_aws_storagegateway_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit c24907e

Please sign in to comment.