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 task_parameters ordering differences #9364

Merged
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
6 changes: 3 additions & 3 deletions aws/resource_aws_ssm_maintenance_window_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource {
},

"task_parameters": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
ConflictsWith: []string{"task_invocation_parameters"},
Deprecated: "use 'task_invocation_parameters' argument instead",
Expand Down Expand Up @@ -671,7 +671,7 @@ func resourceAwsSsmMaintenanceWindowTaskCreate(d *schema.ResourceData, meta inte
}

if v, ok := d.GetOk("task_parameters"); ok {
params.TaskParameters = expandAwsSsmTaskParameters(v.([]interface{}))
params.TaskParameters = expandAwsSsmTaskParameters(v.(*schema.Set).List())
}

if v, ok := d.GetOk("task_invocation_parameters"); ok {
Expand Down Expand Up @@ -773,7 +773,7 @@ func resourceAwsSsmMaintenanceWindowTaskUpdate(d *schema.ResourceData, meta inte
}

if v, ok := d.GetOk("task_parameters"); ok {
params.TaskParameters = expandAwsSsmTaskParameters(v.([]interface{}))
params.TaskParameters = expandAwsSsmTaskParameters(v.(*schema.Set).List())
}

if v, ok := d.GetOk("task_invocation_parameters"); ok {
Expand Down
112 changes: 112 additions & 0 deletions aws/resource_aws_ssm_maintenance_window_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,32 @@ func TestAccAWSSSMMaintenanceWindowTask_TaskInvocationStepFunctionParameters(t *
})
}

func TestAccAWSSSMMaintenanceWindowTask_TaskParameters(t *testing.T) {
var task 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: testAccAWSSSMMaintenanceWindowTaskConfigTaskParametersMultiple(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &task),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccAWSSSMMaintenanceWindowTaskImportStateIdFunc(resourceName),
ImportStateVerify: true,
},
},
})
}

func testAccCheckAwsSsmWindowsTaskNotRecreated(t *testing.T,
before, after *ssm.MaintenanceWindowTask) resource.TestCheckFunc {
return func(s *terraform.State) error {
Expand Down Expand Up @@ -705,3 +731,89 @@ EOF

`, rName)
}

func testAccAWSSSMMaintenanceWindowTaskConfigTaskParametersMultiple(rName string) string {
return fmt.Sprintf(`
resource "aws_ssm_maintenance_window" "test" {
cutoff = 1
duration = 3
name = %[1]q
schedule = "cron(0 16 ? * TUE *)"
}

resource "aws_ssm_maintenance_window_target" "test" {
name = %[1]q
resource_type = "INSTANCE"
window_id = "${aws_ssm_maintenance_window.test.id}"

targets {
key = "tag:Name"
values = ["tf-acc-test"]
}
}

resource "aws_iam_role" "test" {
name = %[1]q
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "events.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
POLICY
}

resource "aws_iam_role_policy" "test" {
name = %[1]q
role = "${aws_iam_role.test.name}"
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Action": "ssm:*",
"Resource": "*"
}
}
POLICY
}

resource "aws_ssm_maintenance_window_task" "test" {
max_concurrency = 1
max_errors = 1
priority = 1
service_role_arn = "${aws_iam_role.test.arn}"
task_arn = "AWS-RunRemoteScript"
task_type = "RUN_COMMAND"
window_id = "${aws_ssm_maintenance_window.test.id}"

targets {
key = "WindowTargetIds"
values = ["${aws_ssm_maintenance_window_target.test.id}"]
}

task_parameters {
name = "sourceType"
values = ["s3"]
}

task_parameters {
name = "sourceInfo"
values = ["https://s3.amazonaws.com/bucket"]
}

task_parameters {
name = "commandLine"
values = ["date"]
}
}
`, rName)
}