From f791abdee5f3ff2b0bf0682a372a023e12507f69 Mon Sep 17 00:00:00 2001 From: Kristian Drucker Date: Wed, 10 Jul 2019 17:44:05 +0100 Subject: [PATCH 1/3] Add support for timeout_seconds in SSM --- ...esource_aws_ssm_maintenance_window_task.go | 39 +++++++++++++++++++ .../ssm_maintenance_window_task.html.markdown | 5 +++ 2 files changed, 44 insertions(+) diff --git a/aws/resource_aws_ssm_maintenance_window_task.go b/aws/resource_aws_ssm_maintenance_window_task.go index 39aad047b7a..b6d57b9e430 100644 --- a/aws/resource_aws_ssm_maintenance_window_task.go +++ b/aws/resource_aws_ssm_maintenance_window_task.go @@ -1,6 +1,7 @@ package aws import ( + "errors" "fmt" "log" @@ -95,6 +96,12 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { ForceNew: true, }, + "timeout_seconds": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + "logging_info": { Type: schema.TypeList, MaxItems: 1, @@ -182,6 +189,15 @@ func expandAwsSsmTaskParameters(config []interface{}) map[string]*ssm.Maintenanc return params } +func expandAwsSsmTaskInvocationParameters(config []interface{}) map[string][]*string { + params := make(map[string][]*string) + for _, v := range config { + paramConfig := v.(map[string]interface{}) + params[paramConfig["name"].(string)] = expandStringList(paramConfig["values"].([]interface{})) + } + return params +} + func flattenAwsSsmTaskParameters(taskParameters map[string]*ssm.MaintenanceWindowTaskParameterValueExpression) []interface{} { result := make([]interface{}, 0, len(taskParameters)) for k, v := range taskParameters { @@ -210,6 +226,9 @@ func resourceAwsSsmMaintenanceWindowTaskCreate(d *schema.ResourceData, meta inte Targets: expandAwsSsmTargets(d.Get("targets").([]interface{})), } + params.TaskInvocationParameters = &ssm.MaintenanceWindowTaskInvocationParameters{} + params.TaskInvocationParameters.RunCommand = &ssm.MaintenanceWindowRunCommandParameters{} + if v, ok := d.GetOk("name"); ok { params.Name = aws.String(v.(string)) } @@ -223,18 +242,38 @@ func resourceAwsSsmMaintenanceWindowTaskCreate(d *schema.ResourceData, meta inte } if v, ok := d.GetOk("logging_info"); ok { + if *params.TaskType == *aws.String("RUN_COMMAND") { + loggingConfig := v.([]interface{})[0].(map[string]interface{}) + params.TaskInvocationParameters.RunCommand.OutputS3BucketName = aws.String(loggingConfig["s3_bucket_name"].(string)) + params.TaskInvocationParameters.RunCommand.OutputS3KeyPrefix = aws.String(loggingConfig["s3_bucket_prefix"].(string)) + } params.LoggingInfo = expandAwsSsmMaintenanceWindowLoggingInfo(v.([]interface{})) } if v, ok := d.GetOk("task_parameters"); ok { + if *params.TaskType == *aws.String("RUN_COMMAND") { + params.TaskInvocationParameters.RunCommand.Parameters = expandAwsSsmTaskInvocationParameters(v.([]interface{})) + } params.TaskParameters = expandAwsSsmTaskParameters(v.([]interface{})) } + if v, ok := d.GetOk("timeout_seconds"); ok { + if *params.TaskType == *aws.String("RUN_COMMAND") { + params.TaskInvocationParameters.RunCommand.TimeoutSeconds = aws.Int64(int64(v.(int))) + } else { + return errors.New("use of \"timeout_seconds\" with anything other than \"RUN_COMMAND\" is not allowed") + } + } + + log.Println("PARAMS", params) + resp, err := ssmconn.RegisterTaskWithMaintenanceWindow(params) if err != nil { return err } + log.Println("RESP", resp) + d.SetId(*resp.WindowTaskId) return resourceAwsSsmMaintenanceWindowTaskRead(d, meta) diff --git a/website/docs/r/ssm_maintenance_window_task.html.markdown b/website/docs/r/ssm_maintenance_window_task.html.markdown index 2774d9f3e1d..72b3ea598a9 100644 --- a/website/docs/r/ssm_maintenance_window_task.html.markdown +++ b/website/docs/r/ssm_maintenance_window_task.html.markdown @@ -30,6 +30,8 @@ resource "aws_ssm_maintenance_window_task" "task" { service_role_arn = "arn:aws:iam::187416307283:role/service-role/AWS_Events_Invoke_Run_Command_112316643" max_concurrency = "2" max_errors = "1" + + timeout_seconds = 60 targets { key = "InstanceIds" @@ -66,6 +68,9 @@ The following arguments are supported: * `logging_info` - (Optional) A structure containing information about an Amazon S3 bucket to write instance-level logs to. Documented below. * `task_parameters` - (Optional) A structure containing information about parameters required by the particular `task_arn`. Documented below. +`RUN_COMMAND` task type supports the following: +* `timeout_seconds` - (Optional) Specify timeout on the task + `logging_info` supports the following: * `s3_bucket_name` - (Required) From ddff2ac9bae3d479b6f5a6f2577e6696d5b55b26 Mon Sep 17 00:00:00 2001 From: Kristian Drucker Date: Thu, 11 Jul 2019 09:12:05 +0100 Subject: [PATCH 2/3] Fix docs for SSM MW Task --- website/docs/r/ssm_maintenance_window_task.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/ssm_maintenance_window_task.html.markdown b/website/docs/r/ssm_maintenance_window_task.html.markdown index 72b3ea598a9..1db9135514d 100644 --- a/website/docs/r/ssm_maintenance_window_task.html.markdown +++ b/website/docs/r/ssm_maintenance_window_task.html.markdown @@ -69,6 +69,7 @@ The following arguments are supported: * `task_parameters` - (Optional) A structure containing information about parameters required by the particular `task_arn`. Documented below. `RUN_COMMAND` task type supports the following: + * `timeout_seconds` - (Optional) Specify timeout on the task `logging_info` supports the following: From 1051c6a35bd83215b6a3bdb759ecebf722c90e18 Mon Sep 17 00:00:00 2001 From: Kristian Drucker Date: Thu, 11 Jul 2019 09:22:29 +0100 Subject: [PATCH 3/3] Remove debug logging in SSM MW Task --- aws/resource_aws_ssm_maintenance_window_task.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/aws/resource_aws_ssm_maintenance_window_task.go b/aws/resource_aws_ssm_maintenance_window_task.go index b6d57b9e430..297759f4966 100644 --- a/aws/resource_aws_ssm_maintenance_window_task.go +++ b/aws/resource_aws_ssm_maintenance_window_task.go @@ -265,15 +265,11 @@ func resourceAwsSsmMaintenanceWindowTaskCreate(d *schema.ResourceData, meta inte } } - log.Println("PARAMS", params) - resp, err := ssmconn.RegisterTaskWithMaintenanceWindow(params) if err != nil { return err } - log.Println("RESP", resp) - d.SetId(*resp.WindowTaskId) return resourceAwsSsmMaintenanceWindowTaskRead(d, meta)