Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_ssm_maintenance_window_task: Prevent ValidationException error on update when priority is not set or 0 #17885

Merged
merged 3 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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