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

Feature Request - Add support for AUTOMATION in aws_ssm_maintenance_window_task resource #4408

Closed
philmadden83 opened this issue May 1, 2018 · 5 comments
Labels
documentation Introduces or discusses updates to documentation. good first issue Call to action for new contributors looking for a place to start. Smaller or straightforward issues. service/ssm Issues and PRs that pertain to the ssm service.
Milestone

Comments

@philmadden83
Copy link

philmadden83 commented May 1, 2018

Add support for automation task types in the aws_ssm_maintenance_window_task resource.

From the current terraform docks

task_type - (Required) The type of task being registered. The only allowed value is RUN_COMMAND.

Docs

AWS SSM Doc

Terraform Version

Terraform v0.11.7

Affected Resource(s)

aws_ssm_maintenance_window_task

@bflad
Copy link
Contributor

bflad commented May 1, 2018

@philmadden83 looks like the resource does not currently perform plan-time validation of the task_type argument under the hood so it should just work out of the box currently. Is there something else required for this support?

We can of course update the documentation to support this new value or point to the relevant AWS documentation for the acceptable values.

@bflad bflad added documentation Introduces or discusses updates to documentation. service/ssm Issues and PRs that pertain to the ssm service. good first issue Call to action for new contributors looking for a place to start. Smaller or straightforward issues. labels May 1, 2018
@philmadden83
Copy link
Author

philmadden83 commented May 3, 2018

@bflad I can confirm that specifying the task typeAUTOMATION does indeed associate an automation document successfully however, after some false starts I belive there is still an issue that needs addressing.

The task_parameters arguments are not being populated into the maintenance windows task.

for example:

If I create the below widnow task referencing my automation document arn and specify the parameters to use..

resource "aws_ssm_maintenance_window_task" "patch-task" {
  window_id = "${ aws_ssm_maintenance_window.automation-window.id }"
  task_type = "AUTOMATION"
  priority  = 1

  service_role_arn = "arn:aws:iam::xxxxxx:role/SSMMaintenanceWindow"
  max_concurrency  = "1"
  max_errors       = "1"

  task_parameters {
    name   = "InstanceId"
    values = ["i-abcd1234"]
  }

  task_parameters {
    name   = "PreRunTask"
    values = ["a-script"]
  }

  task_parameters {
    name   = "PostRunTask"
    values = ["another-script"]
  }

  targets {
    key = "WindowTargetIds"

    values = [
      "${ aws_ssm_maintenance_window_target.targets.id }",
    ]
  }

  task_arn = "${var.task_arn}"
}

Everything is created as expected however, when I inspect the above window task and look at the input parameters I get the below.

screen shot 2018-05-03 at 10 23 12 am

The task paramter values defined in the .tf file have not been set.

If I manually enter the values and save it (as per the below image) and run a plan, Terraform wants to remove the input parameter values I maunally entered (naturally).

screen shot 2018-05-03 at 10 07 26 am

-/+ module.run-patch-baseline-jenkins-slaves.aws_ssm_maintenance_window_task.patch-task (new resource required)
      id:                         "xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx" => <computed> (forces new resource)
      max_concurrency:            "1" => "1"
      max_errors:                 "1" => "1"
      priority:                   "1" => "1"
      service_role_arn:           "arn:aws:iam::xxxxxx:role/SSMMaintenanceWindow" => "arn:aws:iam::xxxxxx:role/SSMMaintenanceWindow"
      targets.#:                  "1" => "1"
      targets.0.key:              "WindowTargetIds" => "WindowTargetIds"
      targets.0.values.#:         "1" => "1"
      targets.0.values.0:         "xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx" => "xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx"
      task_arn:                   "Vivid-PatchInstance" => "Vivid-PatchInstance"
      task_parameters.#:          "0" => "3" (forces new resource)
      task_parameters.0.name:     "" => "InstanceId" (forces new resource)
      task_parameters.0.values.#: "" => "1" (forces new resource)
      task_parameters.0.values.0: "" => "i-abcd1234" (forces new resource)
      task_parameters.1.name:     "" => "PreRunTask" (forces new resource)
      task_parameters.1.values.#: "" => "1" (forces new resource)
      task_parameters.1.values.0: "" => "a-script" (forces new resource)
      task_parameters.2.name:     "" => "PostRunTask" (forces new resource)
      task_parameters.2.values.#: "" => "1" (forces new resource)
      task_parameters.2.values.0: "" => "another-script" (forces new resource)
      task_type:                  "AUTOMATION" => "AUTOMATION"
      window_id:                  "mw-abcd1234" => "mw-abcd1234"


Plan: 1 to add, 3 to change, 1 to destroy.

As a result, any execution of the maintence window fails with the cause "The supplied parameters for invoking the specified Automation document are incorrect.".

@AndrewCi
Copy link

Can confirm this is still an issue for automation task parameter values.

@bflad
Copy link
Contributor

bflad commented Jul 16, 2019

Hi folks 👋 Releasing in version 2.20.0 of the Terraform AWS Provider later this, the aws_ssm_maintenance_window_task will have support for the newer API method of defining AUTOMATION tasks with the new task_invocation_parameters configuration block (which deprecates task_parameters to match the API), e.g.

resource "aws_ssm_maintenance_window_task" "example" {
  max_concurrency  = 2
  max_errors       = 1
  priority         = 1
  service_role_arn = "${aws_iam_role.example.arn}"
  task_arn         = "AWS-RestartEC2Instance"
  task_type        = "AUTOMATION"
  window_id        = "${aws_ssm_maintenance_window.example.id}"

  targets {
    key    = "InstanceIds"
    values = ["${aws_instance.example.id}"]
  }

  task_invocation_parameters {
    automation_parameters {
      document_version = "$LATEST"

      parameter {
        name   = "InstanceId"
        values = ["${aws_instance.example.id}"]
      }
    }
  }
}

The resource documentation will be updated to include that example via #9362 and the parameter configuration blocks are setup to not be ordered like task_parameters currently are. For further tracking of the task_parameters ordering issue, you can follow #3218, otherwise for further feature requests, documentation updates, or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@bflad bflad closed this as completed Jul 16, 2019
@ghost
Copy link

ghost commented Nov 2, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Nov 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. good first issue Call to action for new contributors looking for a place to start. Smaller or straightforward issues. service/ssm Issues and PRs that pertain to the ssm service.
Projects
None yet
Development

No branches or pull requests

3 participants