From b8a705d5aaa17fc317359dfa57faec0d8d89b7c5 Mon Sep 17 00:00:00 2001 From: yaput <12031370+yaput@users.noreply.github.com> Date: Mon, 2 Oct 2023 14:17:54 +0700 Subject: [PATCH 1/6] Initialize start time and end time value avoid null override --- .../appautoscaling/scheduled_action.go | 4 + .../appautoscaling/scheduled_action_test.go | 166 +++++++++++++++++- 2 files changed, 167 insertions(+), 3 deletions(-) diff --git a/internal/service/appautoscaling/scheduled_action.go b/internal/service/appautoscaling/scheduled_action.go index 73bfed9f874..6077aba624c 100644 --- a/internal/service/appautoscaling/scheduled_action.go +++ b/internal/service/appautoscaling/scheduled_action.go @@ -112,12 +112,16 @@ func ResourceScheduledAction() *schema.Resource { func resourceScheduledActionPut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).AppAutoScalingConn(ctx) + currentStartTime, _ := time.Parse(time.RFC3339, d.Get("start_time").(string)) + currentEndTime, _ := time.Parse(time.RFC3339, d.Get("end_time").(string)) input := &applicationautoscaling.PutScheduledActionInput{ ScheduledActionName: aws.String(d.Get("name").(string)), ServiceNamespace: aws.String(d.Get("service_namespace").(string)), ResourceId: aws.String(d.Get("resource_id").(string)), ScalableDimension: aws.String(d.Get("scalable_dimension").(string)), + StartTime: aws.Time(currentStartTime), + EndTime: aws.Time(currentEndTime), } needsPut := true diff --git a/internal/service/appautoscaling/scheduled_action_test.go b/internal/service/appautoscaling/scheduled_action_test.go index ee6afdec26f..31f8ab2e884 100644 --- a/internal/service/appautoscaling/scheduled_action_test.go +++ b/internal/service/appautoscaling/scheduled_action_test.go @@ -20,6 +20,120 @@ import ( tfappautoscaling "github.com/hashicorp/terraform-provider-aws/internal/service/appautoscaling" ) +func TestAccAppAutoScalingScheduledAction_UpdateScheduleRetainStartAndEndTime_ecs(t *testing.T) { + ctx := acctest.Context(t) + var sa applicationautoscaling.ScheduledAction + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + ts := time.Now().AddDate(0, 0, 1).Format("2006-01-02T15:04:05") + tsUpdate := time.Now().AddDate(0, 0, 2).Format("2006-01-02T15:04:05") + resourceName := "aws_appautoscaling_scheduled_action.test" + autoscalingTargetResourceName := "aws_appautoscaling_target.test" + startTime := time.Now().AddDate(0, 0, 2).Format("2006-01-02T15:04:05Z") + endTime := time.Now().AddDate(0, 0, 8).Format("2006-01-02T15:04:05Z") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, applicationautoscaling.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckScheduledActionDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccScheduledActionConfig_ecs(rName, ts, startTime, endTime), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScheduledActionExistsAndContainStartTimeEndTime(ctx, resourceName, &sa, startTime, endTime), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttrPair(resourceName, "service_namespace", autoscalingTargetResourceName, "service_namespace"), + resource.TestCheckResourceAttrPair(resourceName, "resource_id", autoscalingTargetResourceName, "resource_id"), + resource.TestCheckResourceAttrPair(resourceName, "scalable_dimension", autoscalingTargetResourceName, "scalable_dimension"), + resource.TestCheckResourceAttr(resourceName, "schedule", fmt.Sprintf("at(%s)", ts)), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.#", "1"), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.0.min_capacity", "1"), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.0.max_capacity", "5"), + resource.TestCheckResourceAttr(resourceName, "timezone", "UTC"), + resource.TestCheckResourceAttr(resourceName, "start_time", startTime), + resource.TestCheckResourceAttr(resourceName, "end_time", endTime), + acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "autoscaling", regexache.MustCompile(fmt.Sprintf("scheduledAction:.+:scheduledActionName/%s$", rName))), + ), + }, + { + Config: testAccScheduledActionConfig_ecs(rName, tsUpdate, startTime, endTime), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScheduledActionExistsAndContainStartTimeEndTime(ctx, resourceName, &sa, startTime, endTime), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttrPair(resourceName, "service_namespace", autoscalingTargetResourceName, "service_namespace"), + resource.TestCheckResourceAttrPair(resourceName, "resource_id", autoscalingTargetResourceName, "resource_id"), + resource.TestCheckResourceAttrPair(resourceName, "scalable_dimension", autoscalingTargetResourceName, "scalable_dimension"), + resource.TestCheckResourceAttr(resourceName, "schedule", fmt.Sprintf("at(%s)", tsUpdate)), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.#", "1"), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.0.min_capacity", "1"), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.0.max_capacity", "5"), + resource.TestCheckResourceAttr(resourceName, "timezone", "UTC"), + acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "autoscaling", regexache.MustCompile(fmt.Sprintf("scheduledAction:.+:scheduledActionName/%s$", rName))), + ), + }, + }, + }) +} + +func TestAccAppAutoScalingScheduledAction_UpdateStartAndEndTime_ecs(t *testing.T) { + ctx := acctest.Context(t) + var sa applicationautoscaling.ScheduledAction + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + ts := time.Now().AddDate(0, 0, 1).Format("2006-01-02T15:04:05") + tsUpdate := time.Now().AddDate(0, 0, 2).Format("2006-01-02T15:04:05") + resourceName := "aws_appautoscaling_scheduled_action.test" + autoscalingTargetResourceName := "aws_appautoscaling_target.test" + startTime := time.Now().AddDate(0, 0, 2).Format("2006-01-02T15:04:05Z") + endTime := time.Now().AddDate(0, 0, 8).Format("2006-01-02T15:04:05Z") + startTimeUpdate := time.Now().AddDate(0, 0, 4).Format("2006-01-02T15:04:05Z") + endTimeUpdate := time.Now().AddDate(0, 0, 10).Format("2006-01-02T15:04:05Z") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, applicationautoscaling.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckScheduledActionDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccScheduledActionConfig_ecs(rName, ts, startTime, endTime), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScheduledActionExistsAndContainStartTimeEndTime(ctx, resourceName, &sa, startTime, endTime), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttrPair(resourceName, "service_namespace", autoscalingTargetResourceName, "service_namespace"), + resource.TestCheckResourceAttrPair(resourceName, "resource_id", autoscalingTargetResourceName, "resource_id"), + resource.TestCheckResourceAttrPair(resourceName, "scalable_dimension", autoscalingTargetResourceName, "scalable_dimension"), + resource.TestCheckResourceAttr(resourceName, "schedule", fmt.Sprintf("at(%s)", ts)), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.#", "1"), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.0.min_capacity", "1"), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.0.max_capacity", "5"), + resource.TestCheckResourceAttr(resourceName, "timezone", "UTC"), + resource.TestCheckResourceAttr(resourceName, "start_time", startTime), + resource.TestCheckResourceAttr(resourceName, "end_time", endTime), + acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "autoscaling", regexache.MustCompile(fmt.Sprintf("scheduledAction:.+:scheduledActionName/%s$", rName))), + ), + }, + { + Config: testAccScheduledActionConfig_ecs(rName, tsUpdate, startTimeUpdate, endTimeUpdate), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScheduledActionExistsAndContainStartTimeEndTime(ctx, resourceName, &sa, startTimeUpdate, endTimeUpdate), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttrPair(resourceName, "service_namespace", autoscalingTargetResourceName, "service_namespace"), + resource.TestCheckResourceAttrPair(resourceName, "resource_id", autoscalingTargetResourceName, "resource_id"), + resource.TestCheckResourceAttrPair(resourceName, "scalable_dimension", autoscalingTargetResourceName, "scalable_dimension"), + resource.TestCheckResourceAttr(resourceName, "schedule", fmt.Sprintf("at(%s)", tsUpdate)), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.#", "1"), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.0.min_capacity", "1"), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.0.max_capacity", "5"), + resource.TestCheckResourceAttr(resourceName, "timezone", "UTC"), + resource.TestCheckResourceAttr(resourceName, "start_time", startTimeUpdate), + resource.TestCheckResourceAttr(resourceName, "end_time", endTimeUpdate), + acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "autoscaling", regexache.MustCompile(fmt.Sprintf("scheduledAction:.+:scheduledActionName/%s$", rName))), + ), + }, + }, + }) +} + func TestAccAppAutoScalingScheduledAction_dynamoDB(t *testing.T) { ctx := acctest.Context(t) var sa1, sa2 applicationautoscaling.ScheduledAction @@ -92,7 +206,7 @@ func TestAccAppAutoScalingScheduledAction_ecs(t *testing.T) { CheckDestroy: testAccCheckScheduledActionDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccScheduledActionConfig_ecs(rName, ts), + Config: testAccScheduledActionConfig_ecs(rName, ts, "", ""), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckScheduledActionExists(ctx, resourceName, &sa), resource.TestCheckResourceAttr(resourceName, "name", rName), @@ -593,6 +707,49 @@ func testAccCheckScheduledActionDestroy(ctx context.Context) resource.TestCheckF } } +func testAccCheckScheduledActionExistsAndContainStartTimeEndTime(ctx context.Context, name string, obj *applicationautoscaling.ScheduledAction, expectedStartTime, expectedEndTime string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("Application Autoscaling scheduled action (%s) ID not set", name) + } + + conn := acctest.Provider.Meta().(*conns.AWSClient).AppAutoScalingConn(ctx) + + sa, err := tfappautoscaling.FindScheduledAction(ctx, conn, rs.Primary.Attributes["name"], rs.Primary.Attributes["service_namespace"], rs.Primary.Attributes["resource_id"]) + if err != nil { + return err + } + + if sa.StartTime == nil && len(expectedStartTime) != 0 { + return fmt.Errorf("Unexpected empty Start Time value for scheduled action (%s)", name) + } + + st := sa.StartTime.Format("2006-01-02T15:04:05Z") + + if st != expectedStartTime { + return fmt.Errorf("Unexpected stored start time, expected %s, got %s", expectedStartTime, st) + } + + if sa.EndTime == nil && len(expectedEndTime) != 0 { + return fmt.Errorf("Unexpected empty End Time value for scheduled action (%s)", name) + } + + et := sa.EndTime.Format("2006-01-02T15:04:05Z") + if et != expectedEndTime { + return fmt.Errorf("Unexpected stored end time, expected %s, got %s", expectedEndTime, et) + } + + *obj = *sa + + return nil + } +} + func testAccCheckScheduledActionExists(ctx context.Context, name string, obj *applicationautoscaling.ScheduledAction) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] @@ -704,7 +861,7 @@ resource "aws_dynamodb_table" "test" { `, rName, ts, timezone) } -func testAccScheduledActionConfig_ecs(rName, ts string) string { +func testAccScheduledActionConfig_ecs(rName, ts, startTime, endTime string) string { return fmt.Sprintf(` resource "aws_appautoscaling_scheduled_action" "test" { name = %[1]q @@ -712,6 +869,9 @@ resource "aws_appautoscaling_scheduled_action" "test" { resource_id = aws_appautoscaling_target.test.resource_id scalable_dimension = aws_appautoscaling_target.test.scalable_dimension schedule = "at(%[2]s)" + + start_time = %[3]q + end_time = %[4]q scalable_target_action { min_capacity = 1 @@ -756,7 +916,7 @@ resource "aws_ecs_service" "test" { deployment_maximum_percent = 200 deployment_minimum_healthy_percent = 50 } -`, rName, ts) +`, rName, ts, startTime, endTime) } func testAccScheduledActionConfig_emr(rName, ts string) string { From c5064fb4d9e13be8d8f9194f4195ab720e60355e Mon Sep 17 00:00:00 2001 From: yaput <12031370+yaput@users.noreply.github.com> Date: Mon, 2 Oct 2023 14:33:16 +0700 Subject: [PATCH 2/6] Update CHANGELOG --- .changelog/33713.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/33713.txt diff --git a/.changelog/33713.txt b/.changelog/33713.txt new file mode 100644 index 00000000000..13c32256890 --- /dev/null +++ b/.changelog/33713.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_appautoscaling_scheduled_action: Avoid missing `StartTime` and `EndTime` when update scheduled action +``` \ No newline at end of file From 3bc9b1e00ab89dd04e7fa202819ab892d1a372f9 Mon Sep 17 00:00:00 2001 From: yaput <12031370+yaput@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:28:57 +0700 Subject: [PATCH 3/6] Adjust logic to retain default empty start or end time, not assigning default value --- .../appautoscaling/scheduled_action.go | 22 +++- .../appautoscaling/scheduled_action_test.go | 124 +++++++++++++++++- 2 files changed, 136 insertions(+), 10 deletions(-) diff --git a/internal/service/appautoscaling/scheduled_action.go b/internal/service/appautoscaling/scheduled_action.go index 6077aba624c..ee1642aedc1 100644 --- a/internal/service/appautoscaling/scheduled_action.go +++ b/internal/service/appautoscaling/scheduled_action.go @@ -112,16 +112,21 @@ func ResourceScheduledAction() *schema.Resource { func resourceScheduledActionPut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).AppAutoScalingConn(ctx) - currentStartTime, _ := time.Parse(time.RFC3339, d.Get("start_time").(string)) - currentEndTime, _ := time.Parse(time.RFC3339, d.Get("end_time").(string)) input := &applicationautoscaling.PutScheduledActionInput{ ScheduledActionName: aws.String(d.Get("name").(string)), ServiceNamespace: aws.String(d.Get("service_namespace").(string)), ResourceId: aws.String(d.Get("resource_id").(string)), ScalableDimension: aws.String(d.Get("scalable_dimension").(string)), - StartTime: aws.Time(currentStartTime), - EndTime: aws.Time(currentEndTime), + } + + currentStartTime := getTimeIfExist(d, "start_time") + if currentStartTime != nil { + input.StartTime = aws.Time(currentStartTime.(time.Time)) + } + currentEndTime := getTimeIfExist(d, "end_time") + if currentEndTime != nil { + input.EndTime = aws.Time(currentEndTime.(time.Time)) } needsPut := true @@ -300,3 +305,12 @@ func flattenScalableTargetAction(cfg *applicationautoscaling.ScalableTargetActio return []interface{}{m} } + +func getTimeIfExist(d *schema.ResourceData, timeKey string) interface{} { + val, ok := d.GetOk(timeKey) + if !ok { + return nil + } + timeVal, _ := time.Parse(time.RFC3339, val.(string)) + return timeVal +} diff --git a/internal/service/appautoscaling/scheduled_action_test.go b/internal/service/appautoscaling/scheduled_action_test.go index 31f8ab2e884..2e8d87d8c9d 100644 --- a/internal/service/appautoscaling/scheduled_action_test.go +++ b/internal/service/appautoscaling/scheduled_action_test.go @@ -38,7 +38,7 @@ func TestAccAppAutoScalingScheduledAction_UpdateScheduleRetainStartAndEndTime_ec CheckDestroy: testAccCheckScheduledActionDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccScheduledActionConfig_ecs(rName, ts, startTime, endTime), + Config: testAccScheduledActionConfigWithStartAndEndTime_ecs(rName, ts, startTime, endTime), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckScheduledActionExistsAndContainStartTimeEndTime(ctx, resourceName, &sa, startTime, endTime), resource.TestCheckResourceAttr(resourceName, "name", rName), @@ -56,7 +56,7 @@ func TestAccAppAutoScalingScheduledAction_UpdateScheduleRetainStartAndEndTime_ec ), }, { - Config: testAccScheduledActionConfig_ecs(rName, tsUpdate, startTime, endTime), + Config: testAccScheduledActionConfigWithStartAndEndTime_ecs(rName, tsUpdate, startTime, endTime), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckScheduledActionExistsAndContainStartTimeEndTime(ctx, resourceName, &sa, startTime, endTime), resource.TestCheckResourceAttr(resourceName, "name", rName), @@ -95,7 +95,7 @@ func TestAccAppAutoScalingScheduledAction_UpdateStartAndEndTime_ecs(t *testing.T CheckDestroy: testAccCheckScheduledActionDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccScheduledActionConfig_ecs(rName, ts, startTime, endTime), + Config: testAccScheduledActionConfigWithStartAndEndTime_ecs(rName, ts, startTime, endTime), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckScheduledActionExistsAndContainStartTimeEndTime(ctx, resourceName, &sa, startTime, endTime), resource.TestCheckResourceAttr(resourceName, "name", rName), @@ -113,7 +113,7 @@ func TestAccAppAutoScalingScheduledAction_UpdateStartAndEndTime_ecs(t *testing.T ), }, { - Config: testAccScheduledActionConfig_ecs(rName, tsUpdate, startTimeUpdate, endTimeUpdate), + Config: testAccScheduledActionConfigWithStartAndEndTime_ecs(rName, tsUpdate, startTimeUpdate, endTimeUpdate), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckScheduledActionExistsAndContainStartTimeEndTime(ctx, resourceName, &sa, startTimeUpdate, endTimeUpdate), resource.TestCheckResourceAttr(resourceName, "name", rName), @@ -134,6 +134,63 @@ func TestAccAppAutoScalingScheduledAction_UpdateStartAndEndTime_ecs(t *testing.T }) } +func TestAccAppAutoScalingScheduledAction_AddStartTimeAndEndTimeAfterResourceCreated_ecs(t *testing.T) { + ctx := acctest.Context(t) + var sa applicationautoscaling.ScheduledAction + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + ts := time.Now().AddDate(0, 0, 1).Format("2006-01-02T15:04:05") + tsUpdate := time.Now().AddDate(0, 0, 2).Format("2006-01-02T15:04:05") + resourceName := "aws_appautoscaling_scheduled_action.test" + autoscalingTargetResourceName := "aws_appautoscaling_target.test" + startTime := time.Now().AddDate(0, 0, 2).Format("2006-01-02T15:04:05Z") + endTime := time.Now().AddDate(0, 0, 8).Format("2006-01-02T15:04:05Z") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, applicationautoscaling.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckScheduledActionDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccScheduledActionConfig_ecs(rName, ts), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScheduledActionExists(ctx, resourceName, &sa), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttrPair(resourceName, "service_namespace", autoscalingTargetResourceName, "service_namespace"), + resource.TestCheckResourceAttrPair(resourceName, "resource_id", autoscalingTargetResourceName, "resource_id"), + resource.TestCheckResourceAttrPair(resourceName, "scalable_dimension", autoscalingTargetResourceName, "scalable_dimension"), + resource.TestCheckResourceAttr(resourceName, "schedule", fmt.Sprintf("at(%s)", ts)), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.#", "1"), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.0.min_capacity", "1"), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.0.max_capacity", "5"), + resource.TestCheckResourceAttr(resourceName, "timezone", "UTC"), + resource.TestCheckNoResourceAttr(resourceName, "start_time"), + resource.TestCheckNoResourceAttr(resourceName, "end_time"), + acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "autoscaling", regexache.MustCompile(fmt.Sprintf("scheduledAction:.+:scheduledActionName/%s$", rName))), + ), + }, + { + Config: testAccScheduledActionConfigWithStartAndEndTime_ecs(rName, tsUpdate, startTime, endTime), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScheduledActionExistsAndContainStartTimeEndTime(ctx, resourceName, &sa, startTime, endTime), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttrPair(resourceName, "service_namespace", autoscalingTargetResourceName, "service_namespace"), + resource.TestCheckResourceAttrPair(resourceName, "resource_id", autoscalingTargetResourceName, "resource_id"), + resource.TestCheckResourceAttrPair(resourceName, "scalable_dimension", autoscalingTargetResourceName, "scalable_dimension"), + resource.TestCheckResourceAttr(resourceName, "schedule", fmt.Sprintf("at(%s)", tsUpdate)), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.#", "1"), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.0.min_capacity", "1"), + resource.TestCheckResourceAttr(resourceName, "scalable_target_action.0.max_capacity", "5"), + resource.TestCheckResourceAttr(resourceName, "timezone", "UTC"), + resource.TestCheckResourceAttr(resourceName, "start_time", startTime), + resource.TestCheckResourceAttr(resourceName, "end_time", endTime), + acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "autoscaling", regexache.MustCompile(fmt.Sprintf("scheduledAction:.+:scheduledActionName/%s$", rName))), + ), + }, + }, + }) +} + func TestAccAppAutoScalingScheduledAction_dynamoDB(t *testing.T) { ctx := acctest.Context(t) var sa1, sa2 applicationautoscaling.ScheduledAction @@ -206,7 +263,7 @@ func TestAccAppAutoScalingScheduledAction_ecs(t *testing.T) { CheckDestroy: testAccCheckScheduledActionDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccScheduledActionConfig_ecs(rName, ts, "", ""), + Config: testAccScheduledActionConfig_ecs(rName, ts), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckScheduledActionExists(ctx, resourceName, &sa), resource.TestCheckResourceAttr(resourceName, "name", rName), @@ -861,7 +918,62 @@ resource "aws_dynamodb_table" "test" { `, rName, ts, timezone) } -func testAccScheduledActionConfig_ecs(rName, ts, startTime, endTime string) string { +func testAccScheduledActionConfig_ecs(rName, ts string) string { + return fmt.Sprintf(` +resource "aws_appautoscaling_scheduled_action" "test" { + name = %[1]q + service_namespace = aws_appautoscaling_target.test.service_namespace + resource_id = aws_appautoscaling_target.test.resource_id + scalable_dimension = aws_appautoscaling_target.test.scalable_dimension + schedule = "at(%[2]s)" + + scalable_target_action { + min_capacity = 1 + max_capacity = 5 + } +} + +resource "aws_appautoscaling_target" "test" { + service_namespace = "ecs" + resource_id = "service/${aws_ecs_cluster.test.name}/${aws_ecs_service.test.name}" + scalable_dimension = "ecs:service:DesiredCount" + min_capacity = 1 + max_capacity = 3 +} + +resource "aws_ecs_cluster" "test" { + name = %[1]q +} + +resource "aws_ecs_task_definition" "test" { + family = %[1]q + + container_definitions = < Date: Mon, 18 Mar 2024 10:25:32 -0400 Subject: [PATCH 4/6] Tweak CHANGELOG entry. --- .changelog/33713.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/33713.txt b/.changelog/33713.txt index 13c32256890..8146822e7ea 100644 --- a/.changelog/33713.txt +++ b/.changelog/33713.txt @@ -1,3 +1,3 @@ ```release-note:bug -resource/aws_appautoscaling_scheduled_action: Avoid missing `StartTime` and `EndTime` when update scheduled action +resource/aws_appautoscaling_scheduled_action: Always send `start_time` and `end_time` values on update when configured ``` \ No newline at end of file From 7fdb2e788eea7a471eebf2d78d27e2dd4c0352f4 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 18 Mar 2024 11:40:44 -0400 Subject: [PATCH 5/6] Fix semgrep 'ci.semgrep.migrate.error-check-service-id'. --- internal/service/appautoscaling/scheduled_action_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/appautoscaling/scheduled_action_test.go b/internal/service/appautoscaling/scheduled_action_test.go index 16f231963bc..bc2eb9afb1c 100644 --- a/internal/service/appautoscaling/scheduled_action_test.go +++ b/internal/service/appautoscaling/scheduled_action_test.go @@ -152,7 +152,7 @@ func TestAccAppAutoScalingScheduledAction_ecsUpdateScheduleRetainStartAndEndTime resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, applicationautoscaling.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.AppAutoScalingServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckScheduledActionDestroy(ctx), Steps: []resource.TestStep{ @@ -209,7 +209,7 @@ func TestAccAppAutoScalingScheduledAction_ecsUpdateStartAndEndTime(t *testing.T) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, applicationautoscaling.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.AppAutoScalingServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckScheduledActionDestroy(ctx), Steps: []resource.TestStep{ @@ -266,7 +266,7 @@ func TestAccAppAutoScalingScheduledAction_ecsAddStartTimeAndEndTimeAfterResource resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, applicationautoscaling.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.AppAutoScalingServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckScheduledActionDestroy(ctx), Steps: []resource.TestStep{ From b6cea8ff12f2f6b72834bddb08907d1e67295242 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 18 Mar 2024 11:42:02 -0400 Subject: [PATCH 6/6] Fix terrafmt errors. --- internal/service/appautoscaling/scheduled_action_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/service/appautoscaling/scheduled_action_test.go b/internal/service/appautoscaling/scheduled_action_test.go index bc2eb9afb1c..039596c2e56 100644 --- a/internal/service/appautoscaling/scheduled_action_test.go +++ b/internal/service/appautoscaling/scheduled_action_test.go @@ -963,7 +963,7 @@ resource "aws_appautoscaling_scheduled_action" "test" { resource_id = aws_appautoscaling_target.test.resource_id scalable_dimension = aws_appautoscaling_target.test.scalable_dimension schedule = "at(%[2]s)" - + start_time = %[3]q end_time = %[4]q @@ -1006,6 +1006,7 @@ resource "aws_ecs_service" "test" { cluster = aws_ecs_cluster.test.id task_definition = aws_ecs_task_definition.test.arn desired_count = 1 + deployment_maximum_percent = 200 deployment_minimum_healthy_percent = 50 }