Add task_parameters parameter to aws_ssm_maintenance_window_task resource (#15104)

* Add task_parameters support to aws_ssm_maintenance_window_task

task_parameters weren't supported yet. This adds support for them. It
also corrects a documentation typo in the maintenance_window resource.

* Respond to internal feedback
This commit is contained in:
Joel Thompson 2017-06-06 07:11:05 -04:00 committed by Paul Stack
parent d06a4f05d4
commit 1812ce2ff3
4 changed files with 69 additions and 2 deletions

View File

@ -99,6 +99,25 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource {
},
},
},
"task_parameters": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"values": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
},
}
}
@ -132,6 +151,30 @@ func flattenAwsSsmMaintenanceWindowLoggingInfo(loggingInfo *ssm.LoggingInfo) []i
return []interface{}{result}
}
func expandAwsSsmTaskParameters(config []interface{}) map[string]*ssm.MaintenanceWindowTaskParameterValueExpression {
params := make(map[string]*ssm.MaintenanceWindowTaskParameterValueExpression)
for _, v := range config {
paramConfig := v.(map[string]interface{})
params[paramConfig["name"].(string)] = &ssm.MaintenanceWindowTaskParameterValueExpression{
Values: 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 {
taskParam := map[string]interface{}{
"name": k,
"values": flattenStringList(v.Values),
}
result = append(result, taskParam)
}
return result
}
func resourceAwsSsmMaintenanceWindowTaskCreate(d *schema.ResourceData, meta interface{}) error {
ssmconn := meta.(*AWSClient).ssmconn
@ -155,6 +198,10 @@ func resourceAwsSsmMaintenanceWindowTaskCreate(d *schema.ResourceData, meta inte
params.LoggingInfo = expandAwsSsmMaintenanceWindowLoggingInfo(v.([]interface{}))
}
if v, ok := d.GetOk("task_parameters"); ok {
params.TaskParameters = expandAwsSsmTaskParameters(v.([]interface{}))
}
resp, err := ssmconn.RegisterTaskWithMaintenanceWindow(params)
if err != nil {
return err
@ -196,6 +243,12 @@ func resourceAwsSsmMaintenanceWindowTaskRead(d *schema.ResourceData, meta interf
}
}
if t.TaskParameters != nil {
if err := d.Set("task_parameters", flattenAwsSsmTaskParameters(t.TaskParameters)); err != nil {
return fmt.Errorf("[DEBUG] Error setting task_parameters error: %#v", err)
}
}
if err := d.Set("targets", flattenAwsSsmTargets(t.Targets)); err != nil {
return fmt.Errorf("[DEBUG] Error setting targets error: %#v", err)
}

View File

@ -110,6 +110,10 @@ resource "aws_ssm_maintenance_window_task" "target" {
key = "InstanceIds"
values = ["${aws_instance.foo.id}"]
}
task_parameters {
name = "commands"
values = ["pwd"]
}
}
resource "aws_instance" "foo" {

View File

@ -29,10 +29,10 @@ The following arguments are supported:
* `schedule` - (Required) The schedule of the Maintenance Window in the form of a [cron](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-maintenance-cron.html) or rate expression.
* `cutoff` - (Required) The number of hours before the end of the Maintenance Window that Systems Manager stops scheduling new tasks for execution.
* `duration` - (Required) The duration of the Maintenance Window in hours.
* `allow_unregistered_targets` - (Optional) Whether targets must be registered with the Maintenance Window before tasks can be defined for those targets.
* `allow_unassociated_targets` - (Optional) Whether targets must be registered with the Maintenance Window before tasks can be defined for those targets.
## Attributes Reference
The following attributes are exported:
* `id` - The ID of the maintenance window.
* `id` - The ID of the maintenance window.

View File

@ -32,6 +32,10 @@ resource "aws_ssm_maintenance_window_task" "task" {
key = "InstanceIds"
values = ["${aws_instance.instance.id}"]
}
task_parameters {
name = "commands"
values = ["pwd"]
}
}
resource "aws_instance" "instance" {
@ -54,6 +58,7 @@ The following arguments are supported:
* `targets` - (Required) The targets (either instances or window target ids). Instances are specified using Key=InstanceIds,Values=instanceid1,instanceid2. Window target ids are specified using Key=WindowTargetIds,Values=window target id1, window target id2.
* `priority` - (Optional) The priority of the task in the Maintenance Window, the lower the number the higher the priority. Tasks in a Maintenance Window are scheduled in priority order with tasks that have the same priority scheduled in parallel.
* `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.
`logging_info` supports the following:
@ -61,6 +66,11 @@ The following arguments are supported:
* `s3_region` - (Required)
* `s3_bucket_prefix` - (Optional)
`task_parameters` supports the following:
* `name` - (Required)
* `values` - (Required)
## Attributes Reference
The following attributes are exported: