From 2728e9d7828fd75ff07a1d539f8295f7c3fdcf58 Mon Sep 17 00:00:00 2001 From: Guimove Date: Tue, 4 Sep 2018 12:40:55 +0200 Subject: [PATCH 1/6] add name and description to SSM Maintenance Window Tasks --- ...esource_aws_ssm_maintenance_window_task.go | 22 +++++++++++++++++++ ...ce_aws_ssm_maintenance_window_task_test.go | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/aws/resource_aws_ssm_maintenance_window_task.go b/aws/resource_aws_ssm_maintenance_window_task.go index 072b5877c80..dc35ea853b9 100644 --- a/aws/resource_aws_ssm_maintenance_window_task.go +++ b/aws/resource_aws_ssm_maintenance_window_task.go @@ -73,6 +73,18 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { }, }, + "name": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + + "description": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "priority": { Type: schema.TypeInt, Optional: true, @@ -191,6 +203,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{})), } @@ -241,6 +255,14 @@ func resourceAwsSsmMaintenanceWindowTaskRead(d *schema.ResourceData, meta interf d.Set("task_arn", t.TaskArn) d.Set("priority", t.Priority) + if t.Name != nil { + d.Set("name", t.Name) + } + + if t.Description != nil { + d.Set("description", t.Description) + } + if t.LoggingInfo != nil { if err := d.Set("logging_info", flattenAwsSsmMaintenanceWindowLoggingInfo(t.LoggingInfo)); err != nil { return fmt.Errorf("[DEBUG] Error setting logging_info error: %#v", err) diff --git a/aws/resource_aws_ssm_maintenance_window_task_test.go b/aws/resource_aws_ssm_maintenance_window_task_test.go index ecb466953eb..815a1afd320 100644 --- a/aws/resource_aws_ssm_maintenance_window_task_test.go +++ b/aws/resource_aws_ssm_maintenance_window_task_test.go @@ -141,6 +141,8 @@ resource "aws_ssm_maintenance_window_task" "target" { task_type = "RUN_COMMAND" task_arn = "AWS-RunShellScript" priority = 1 + name = "TestMaintenanceWindowTask" + description = "This ressource is for test purpose only" service_role_arn = "${aws_iam_role.ssm_role.arn}" max_concurrency = "2" max_errors = "1" @@ -213,6 +215,8 @@ resource "aws_ssm_maintenance_window_task" "target" { task_type = "RUN_COMMAND" task_arn = "AWS-RunShellScript" priority = 1 + name = "TestMaintenanceWindowTask" + description = "This ressource is for test purpose only" service_role_arn = "${aws_iam_role.ssm_role.arn}" max_concurrency = "2" max_errors = "1" From 4004ffb54ebc23f69a71e16bd953c97f1127715e Mon Sep 17 00:00:00 2001 From: Guimove Date: Fri, 7 Sep 2018 18:03:24 +0200 Subject: [PATCH 2/6] add SSM Window Task validator for name and desc --- ...esource_aws_ssm_maintenance_window_task.go | 2 ++ aws/validators.go | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/aws/resource_aws_ssm_maintenance_window_task.go b/aws/resource_aws_ssm_maintenance_window_task.go index dc35ea853b9..3ead7f0066b 100644 --- a/aws/resource_aws_ssm_maintenance_window_task.go +++ b/aws/resource_aws_ssm_maintenance_window_task.go @@ -77,12 +77,14 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, + ValidateFunc: validateAwsSSMMaintenanceWindowTaskName, }, "description": { Type: schema.TypeString, Optional: true, ForceNew: true, + ValidateFunc: validateAwsSSMMaintenanceWindowTaskDescription, }, "priority": { diff --git a/aws/validators.go b/aws/validators.go index 51a8d434a87..0c41eb21165 100644 --- a/aws/validators.go +++ b/aws/validators.go @@ -1568,6 +1568,29 @@ 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 validateAwsSSMMaintenanceWindowTaskDescription(v interface{}, k string) (ws []string, errors []error) { + // https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_RegisterTaskWithMaintenanceWindow.html#systemsmanager-RegisterTaskWithMaintenanceWindow-request-Description + value := v.(string) + if len(value) > 128 { + errors = append(errors, fmt.Errorf( + "%q cannot be longer than 128 characters: %q", 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) { From 465112b834d96b8afa17e1fdb4849af3fb537f12 Mon Sep 17 00:00:00 2001 From: Guimove Date: Fri, 7 Sep 2018 18:12:19 +0200 Subject: [PATCH 3/6] fmt checked passed --- aws/resource_aws_ssm_maintenance_window_task.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aws/resource_aws_ssm_maintenance_window_task.go b/aws/resource_aws_ssm_maintenance_window_task.go index 3ead7f0066b..8512346a379 100644 --- a/aws/resource_aws_ssm_maintenance_window_task.go +++ b/aws/resource_aws_ssm_maintenance_window_task.go @@ -74,16 +74,16 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { }, "name": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, ValidateFunc: validateAwsSSMMaintenanceWindowTaskName, }, "description": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, ValidateFunc: validateAwsSSMMaintenanceWindowTaskDescription, }, From d63ff82e549775e752c675e6dd0a2456ea982348 Mon Sep 17 00:00:00 2001 From: Guimove Date: Fri, 7 Sep 2018 18:12:58 +0200 Subject: [PATCH 4/6] update acctests to check name and desc exist --- aws/resource_aws_ssm_maintenance_window_task_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aws/resource_aws_ssm_maintenance_window_task_test.go b/aws/resource_aws_ssm_maintenance_window_task_test.go index 815a1afd320..9ad2436c4cf 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"), ), }, }, From f418a43dd069af7e5eb93c99389f60e9fa28be4d Mon Sep 17 00:00:00 2001 From: Guimove Date: Fri, 14 Sep 2018 11:06:50 +0200 Subject: [PATCH 5/6] use upstream validation and typo correction --- aws/resource_aws_ssm_maintenance_window_task.go | 13 ++++--------- ...resource_aws_ssm_maintenance_window_task_test.go | 4 ++-- aws/validators.go | 10 ---------- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/aws/resource_aws_ssm_maintenance_window_task.go b/aws/resource_aws_ssm_maintenance_window_task.go index 8512346a379..2b7f03b94db 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" @@ -84,7 +85,7 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, - ValidateFunc: validateAwsSSMMaintenanceWindowTaskDescription, + ValidateFunc: validation.StringLenBetween(3, 128), }, "priority": { @@ -256,14 +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) - - if t.Name != nil { - d.Set("name", t.Name) - } - - if t.Description != nil { - d.Set("description", t.Description) - } + 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 9ad2436c4cf..0f039801629 100644 --- a/aws/resource_aws_ssm_maintenance_window_task_test.go +++ b/aws/resource_aws_ssm_maintenance_window_task_test.go @@ -144,7 +144,7 @@ resource "aws_ssm_maintenance_window_task" "target" { task_arn = "AWS-RunShellScript" priority = 1 name = "TestMaintenanceWindowTask" - description = "This ressource is for test purpose only" + description = "This resource is for test purpose only" service_role_arn = "${aws_iam_role.ssm_role.arn}" max_concurrency = "2" max_errors = "1" @@ -218,7 +218,7 @@ resource "aws_ssm_maintenance_window_task" "target" { task_arn = "AWS-RunShellScript" priority = 1 name = "TestMaintenanceWindowTask" - description = "This ressource is for test purpose only" + 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 0c41eb21165..c5658cb4128 100644 --- a/aws/validators.go +++ b/aws/validators.go @@ -1581,16 +1581,6 @@ func validateAwsSSMMaintenanceWindowTaskName(v interface{}, k string) (ws []stri return } -func validateAwsSSMMaintenanceWindowTaskDescription(v interface{}, k string) (ws []string, errors []error) { - // https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_RegisterTaskWithMaintenanceWindow.html#systemsmanager-RegisterTaskWithMaintenanceWindow-request-Description - value := v.(string) - if len(value) > 128 { - errors = append(errors, fmt.Errorf( - "%q cannot be longer than 128 characters: %q", 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) { From 2d41b1a7247f3bfab6188bb2dfb617067ee37e23 Mon Sep 17 00:00:00 2001 From: Guimove Date: Fri, 14 Sep 2018 11:16:31 +0200 Subject: [PATCH 6/6] update doc with name and description for maintenance window task --- website/docs/r/ssm_maintenance_window_task.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) 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.