From 1b224f560f8dcd83cec5d4193fd8b3323bfa747a Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Tue, 2 Mar 2021 12:03:24 -0500 Subject: [PATCH 1/3] resource/aws_ssm_maintenance_window_task: Prevent ValidationException error on update when priority is not set or 0 Reference: https://github.com/hashicorp/terraform-provider-aws/issues/17871 Priority is optional, but it is currently configured in every test configuration which is why this was not found before. To minimize the changes to verify this bug and timebox effort as part of triage, submitting one preferred style test that covers the behavior. Previously: ``` === CONT TestAccAWSSSMMaintenanceWindowTask_Description resource_aws_ssm_maintenance_window_task_test.go:114: Step 3/3 error: Error running apply: exit status 1 Error: Error updating Maintenance Window (mw-02f66f1bc3df08b83) Task (4c1a1e3e-c449-4e2d-882c-5f8a23a2104d): ValidationException: Value null at 'Priority' failed to satisfy constraint: Member must not be null status code: 400, request id: fc15f736-7e53-49bb-8d5d-11f35ba98a30 on terraform_plugin_test.tf line 58, in resource "aws_ssm_maintenance_window_task" "test": 58: resource "aws_ssm_maintenance_window_task" "test" { --- FAIL: TestAccAWSSSMMaintenanceWindowTask_Description (22.29s) ``` Output from acceptance testing in AWS Commercial: ``` --- PASS: TestAccAWSSSMMaintenanceWindowTask_basic (36.64s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_Description (36.65s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_disappears (20.12s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig (21.04s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_noRole (21.13s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationAutomationParameters (49.73s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationLambdaParameters (39.99s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationRunCommandParameters (50.76s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationRunCommandParametersCloudWatch (53.64s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationStepFunctionParameters (23.05s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_updateForcesNewResource (36.64s) ``` Output from acceptance testing in AWS GovCloud (US): ``` --- PASS: TestAccAWSSSMMaintenanceWindowTask_basic (48.68s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_Description (45.57s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_disappears (28.64s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig (28.72s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_noRole (28.97s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationAutomationParameters (52.58s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationLambdaParameters (49.44s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationRunCommandParameters (54.30s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationRunCommandParametersCloudWatch (60.93s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationStepFunctionParameters (31.03s) --- PASS: TestAccAWSSSMMaintenanceWindowTask_updateForcesNewResource (46.25s) ``` --- .changelog/pending.txt | 3 + ...esource_aws_ssm_maintenance_window_task.go | 5 +- ...ce_aws_ssm_maintenance_window_task_test.go | 64 +++++++++++++++++++ 3 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 .changelog/pending.txt diff --git a/.changelog/pending.txt b/.changelog/pending.txt new file mode 100644 index 00000000000..146450dc5d3 --- /dev/null +++ b/.changelog/pending.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_ssm_maintenance_window_task: Prevent `ValidationException` error on update when priority is not set or 0 +``` diff --git a/aws/resource_aws_ssm_maintenance_window_task.go b/aws/resource_aws_ssm_maintenance_window_task.go index d22dd54461c..52f1e7e847b 100644 --- a/aws/resource_aws_ssm_maintenance_window_task.go +++ b/aws/resource_aws_ssm_maintenance_window_task.go @@ -739,6 +739,7 @@ func resourceAwsSsmMaintenanceWindowTaskUpdate(d *schema.ResourceData, meta inte windowID := d.Get("window_id").(string) params := &ssm.UpdateMaintenanceWindowTaskInput{ + Priority: aws.Int64(int64(d.Get("priority").(int))), WindowId: aws.String(windowID), WindowTaskId: aws.String(d.Id()), MaxConcurrency: aws.String(d.Get("max_concurrency").(string)), @@ -760,10 +761,6 @@ func resourceAwsSsmMaintenanceWindowTaskUpdate(d *schema.ResourceData, meta inte params.Description = aws.String(v.(string)) } - if v, ok := d.GetOk("priority"); ok { - params.Priority = aws.Int64(int64(v.(int))) - } - if v, ok := d.GetOk("task_invocation_parameters"); ok { params.TaskInvocationParameters = expandAwsSsmTaskInvocationParameters(v.([]interface{})) } diff --git a/aws/resource_aws_ssm_maintenance_window_task_test.go b/aws/resource_aws_ssm_maintenance_window_task_test.go index 13548ee7011..036f753a15a 100644 --- a/aws/resource_aws_ssm_maintenance_window_task_test.go +++ b/aws/resource_aws_ssm_maintenance_window_task_test.go @@ -106,6 +106,41 @@ func TestAccAWSSSMMaintenanceWindowTask_updateForcesNewResource(t *testing.T) { }) } +func TestAccAWSSSMMaintenanceWindowTask_Description(t *testing.T) { + var task1, task2 ssm.MaintenanceWindowTask + resourceName := "aws_ssm_maintenance_window_task.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSSSMMaintenanceWindowTaskDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSSSMMaintenanceWindowTaskConfigDescription(rName, "description1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &task1), + resource.TestCheckResourceAttr(resourceName, "description", "description1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccAWSSSMMaintenanceWindowTaskImportStateIdFunc(resourceName), + ImportStateVerify: true, + }, + { + Config: testAccAWSSSMMaintenanceWindowTaskConfigDescription(rName, "description2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &task2), + resource.TestCheckResourceAttr(resourceName, "description", "description2"), + testAccCheckAwsSsmWindowsTaskNotRecreated(t, &task1, &task2), + ), + }, + }, + }) +} + func TestAccAWSSSMMaintenanceWindowTask_TaskInvocationAutomationParameters(t *testing.T) { var task ssm.MaintenanceWindowTask resourceName := "aws_ssm_maintenance_window_task.test" @@ -614,6 +649,35 @@ resource "aws_ssm_maintenance_window_task" "test" { `) } +func testAccAWSSSMMaintenanceWindowTaskConfigDescription(rName string, description string) string { + return composeConfig( + testAccAWSSSMMaintenanceWindowTaskConfigBase(rName), + fmt.Sprintf(` +resource "aws_ssm_maintenance_window_task" "test" { + description = %[1]q + max_concurrency = 2 + max_errors = 1 + task_arn = "AWS-RunShellScript" + task_type = "RUN_COMMAND" + window_id = aws_ssm_maintenance_window.test.id + + targets { + key = "WindowTargetIds" + values = [aws_ssm_maintenance_window_target.test.id] + } + + task_invocation_parameters { + run_command_parameters { + parameter { + name = "commands" + values = ["pwd"] + } + } + } +} +`, description)) +} + func testAccAWSSSMMaintenanceWindowTaskConfigEmptyNotifcationConfig(rName string) string { return fmt.Sprintf(testAccAWSSSMMaintenanceWindowTaskConfigBase(rName) + ` From f5e6c3d1ba55cbc4d7762ea88463d54ac13dffe9 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Tue, 2 Mar 2021 12:06:19 -0500 Subject: [PATCH 2/3] Update CHANGELOG for #17885 --- .changelog/{pending.txt => 17885.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{pending.txt => 17885.txt} (100%) diff --git a/.changelog/pending.txt b/.changelog/17885.txt similarity index 100% rename from .changelog/pending.txt rename to .changelog/17885.txt From 579b16b3a475e3022ab930cb9b9bf1c6ee9bcdd2 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Tue, 2 Mar 2021 17:30:00 -0500 Subject: [PATCH 3/3] tests/resource/aws_ssm_maintenance_window_task: terrafmt fix --- aws/resource_aws_ssm_maintenance_window_task_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aws/resource_aws_ssm_maintenance_window_task_test.go b/aws/resource_aws_ssm_maintenance_window_task_test.go index 036f753a15a..2ad5b7a3e1a 100644 --- a/aws/resource_aws_ssm_maintenance_window_task_test.go +++ b/aws/resource_aws_ssm_maintenance_window_task_test.go @@ -654,12 +654,12 @@ func testAccAWSSSMMaintenanceWindowTaskConfigDescription(rName string, descripti testAccAWSSSMMaintenanceWindowTaskConfigBase(rName), fmt.Sprintf(` resource "aws_ssm_maintenance_window_task" "test" { - description = %[1]q - max_concurrency = 2 - max_errors = 1 - task_arn = "AWS-RunShellScript" - task_type = "RUN_COMMAND" - window_id = aws_ssm_maintenance_window.test.id + description = %[1]q + max_concurrency = 2 + max_errors = 1 + task_arn = "AWS-RunShellScript" + task_type = "RUN_COMMAND" + window_id = aws_ssm_maintenance_window.test.id targets { key = "WindowTargetIds"