Skip to content

Commit

Permalink
resource/aws_ssm_maintenance_window_task: Prevent `task_paramet… (#9364)
Browse files Browse the repository at this point in the history
Reference: #3218

Previously (before code update):

```
--- FAIL: TestAccAWSSSMMaintenanceWindowTask_TaskParameters (12.95s)
    testing.go:568: Step 0 error: After applying this step, the plan was not empty:

        DIFF:

        UPDATE: aws_ssm_maintenance_window_task.test
...
          task_parameters.#:            "3" => "3"
          task_parameters.0.name:       "commandLine" => "sourceType"
          task_parameters.0.values.#:   "1" => "1"
          task_parameters.0.values.0:   "date" => "s3"
          task_parameters.1.name:       "sourceInfo" => "sourceInfo"
          task_parameters.1.values.#:   "1" => "1"
          task_parameters.1.values.0:   "https://s3.amazonaws.com/bucket" => "https://s3.amazonaws.com/bucket"
          task_parameters.2.name:       "sourceType" => "commandLine"
          task_parameters.2.values.#:   "1" => "1"
          task_parameters.2.values.0:   "s3" => "date"
```

Output from acceptance testing:

```
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskParameters (18.13s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationStepFunctionParameters (126.33s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_basic (127.14s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_updateForcesNewResource (157.65s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationRunCommandParameters (158.38s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationAutomationParameters (178.09s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationLambdaParameters (233.40s)
```
  • Loading branch information
bflad authored and nywilken committed Jul 19, 2019
1 parent 0d00f7e commit 1ae564f
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 3 deletions.
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 @@ -710,3 +736,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)
}

0 comments on commit 1ae564f

Please sign in to comment.