diff --git a/aws/resource_aws_ssm_maintenance_window_task.go b/aws/resource_aws_ssm_maintenance_window_task.go index 088a8ab3512..f9da3fd9eeb 100644 --- a/aws/resource_aws_ssm_maintenance_window_task.go +++ b/aws/resource_aws_ssm_maintenance_window_task.go @@ -2,6 +2,7 @@ package aws import ( "fmt" + "github.com/hashicorp/terraform/helper/validation" "log" "github.com/aws/aws-sdk-go/aws" @@ -73,6 +74,20 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { }, }, + "name": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validateAwsSSMMaintenanceWindowTaskName, + }, + + "description": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringLenBetween(3, 128), + }, + "priority": { Type: schema.TypeInt, Optional: true, @@ -191,6 +206,8 @@ func resourceAwsSsmMaintenanceWindowTaskCreate(d *schema.ResourceData, meta inte TaskType: aws.String(d.Get("task_type").(string)), ServiceRoleArn: aws.String(d.Get("service_role_arn").(string)), TaskArn: aws.String(d.Get("task_arn").(string)), + Name: aws.String(d.Get("name").(string)), + Description: aws.String(d.Get("description").(string)), Targets: expandAwsSsmTargets(d.Get("targets").([]interface{})), } @@ -240,6 +257,8 @@ func resourceAwsSsmMaintenanceWindowTaskRead(d *schema.ResourceData, meta interf d.Set("service_role_arn", t.ServiceRoleArn) d.Set("task_arn", t.TaskArn) d.Set("priority", t.Priority) + d.Set("name", t.Name) + d.Set("description", t.Description) if t.LoggingInfo != nil { if err := d.Set("logging_info", flattenAwsSsmMaintenanceWindowLoggingInfo(t.LoggingInfo)); err != nil { diff --git a/aws/resource_aws_ssm_maintenance_window_task_test.go b/aws/resource_aws_ssm_maintenance_window_task_test.go index ecb466953eb..0f039801629 100644 --- a/aws/resource_aws_ssm_maintenance_window_task_test.go +++ b/aws/resource_aws_ssm_maintenance_window_task_test.go @@ -25,6 +25,8 @@ func TestAccAWSSSMMaintenanceWindowTask_basic(t *testing.T) { Config: testAccAWSSSMMaintenanceWindowTaskBasicConfig(name), Check: resource.ComposeTestCheckFunc( testAccCheckAWSSSMMaintenanceWindowTaskExists("aws_ssm_maintenance_window_task.target", &task), + resource.TestCheckResourceAttr("aws_ssm_maintenance_window_task.target", "name", "TestMaintenanceWindowTask"), + resource.TestCheckResourceAttr("aws_ssm_maintenance_window_task.target", "description", "This ressource is for test purpose only"), ), }, }, @@ -141,6 +143,8 @@ resource "aws_ssm_maintenance_window_task" "target" { task_type = "RUN_COMMAND" task_arn = "AWS-RunShellScript" priority = 1 + name = "TestMaintenanceWindowTask" + description = "This resource is for test purpose only" service_role_arn = "${aws_iam_role.ssm_role.arn}" max_concurrency = "2" max_errors = "1" @@ -213,6 +217,8 @@ resource "aws_ssm_maintenance_window_task" "target" { task_type = "RUN_COMMAND" task_arn = "AWS-RunShellScript" priority = 1 + name = "TestMaintenanceWindowTask" + description = "This resource is for test purpose only" service_role_arn = "${aws_iam_role.ssm_role.arn}" max_concurrency = "2" max_errors = "1" diff --git a/aws/validators.go b/aws/validators.go index e18e230de68..9a501d33e70 100644 --- a/aws/validators.go +++ b/aws/validators.go @@ -1564,6 +1564,19 @@ func validateAwsSSMName(v interface{}, k string) (ws []string, errors []error) { return } +func validateAwsSSMMaintenanceWindowTaskName(v interface{}, k string) (ws []string, errors []error) { + // https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_RegisterTaskWithMaintenanceWindow.html#systemsmanager-RegisterTaskWithMaintenanceWindow-request-Name + value := v.(string) + + if !regexp.MustCompile(`^[a-zA-Z0-9_\-.]{3,128}$`).MatchString(value) { + errors = append(errors, fmt.Errorf( + "Only alphanumeric characters, hyphens, dots & underscores allowed in %q: %q (Must satisfy regular expression pattern: ^[a-zA-Z0-9_\\-.]{3,128}$)", + k, value)) + } + + return +} + func validateBatchName(v interface{}, k string) (ws []string, errors []error) { value := v.(string) if !regexp.MustCompile(`^[0-9a-zA-Z]{1}[0-9a-zA-Z_\-]{0,127}$`).MatchString(value) { diff --git a/website/docs/r/ssm_maintenance_window_task.html.markdown b/website/docs/r/ssm_maintenance_window_task.html.markdown index d58a5a6cfc5..ea5186f4d33 100644 --- a/website/docs/r/ssm_maintenance_window_task.html.markdown +++ b/website/docs/r/ssm_maintenance_window_task.html.markdown @@ -22,6 +22,8 @@ resource "aws_ssm_maintenance_window" "window" { resource "aws_ssm_maintenance_window_task" "task" { window_id = "${aws_ssm_maintenance_window.window.id}" + name = "maintenance-window-task" + description = "This is a maintenance window task" task_type = "RUN_COMMAND" task_arn = "AWS-RunShellScript" priority = 1 @@ -55,6 +57,8 @@ The following arguments are supported: * `task_type` - (Required) The type of task being registered. The only allowed value is `RUN_COMMAND`. * `task_arn` - (Required) The ARN of the task to execute. * `service_role_arn` - (Required) The role that should be assumed when executing the task. +* `name` - (Optional) The name of the maintenance window task. +* `description` - (Optional) The description of the maintenance window task. * `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.