Skip to content

Commit

Permalink
resource/aws_ssm_maintenance_window_task: Prevent ValidationException…
Browse files Browse the repository at this point in the history
… error on update when priority is not set or 0 (#17885)

Reference: #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)
```
  • Loading branch information
bflad authored Mar 4, 2021
1 parent beaa075 commit 9458ef9
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/17885.txt
Original file line number Diff line number Diff line change
@@ -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
```
5 changes: 1 addition & 4 deletions aws/resource_aws_ssm_maintenance_window_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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{}))
}
Expand Down
64 changes: 64 additions & 0 deletions aws/resource_aws_ssm_maintenance_window_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) + `
Expand Down

0 comments on commit 9458ef9

Please sign in to comment.