From 2cfff0542f424c08290ea2de38cdcadfe036a1d8 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Tue, 5 Mar 2019 17:06:22 +0900 Subject: [PATCH 01/13] Fix to use GetMaintenanceWindowTask --- ...esource_aws_ssm_maintenance_window_task.go | 71 +++++++++---------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/aws/resource_aws_ssm_maintenance_window_task.go b/aws/resource_aws_ssm_maintenance_window_task.go index 39aad047b7a..005ea9e5086 100644 --- a/aws/resource_aws_ssm_maintenance_window_task.go +++ b/aws/resource_aws_ssm_maintenance_window_task.go @@ -242,53 +242,46 @@ func resourceAwsSsmMaintenanceWindowTaskCreate(d *schema.ResourceData, meta inte func resourceAwsSsmMaintenanceWindowTaskRead(d *schema.ResourceData, meta interface{}) error { ssmconn := meta.(*AWSClient).ssmconn + windowID := d.Get("window_id").(string) - params := &ssm.DescribeMaintenanceWindowTasksInput{ - WindowId: aws.String(d.Get("window_id").(string)), + params := &ssm.GetMaintenanceWindowTaskInput{ + WindowId: aws.String(windowID), + WindowTaskId: aws.String(d.Id()), + } + resp, err := ssmconn.GetMaintenanceWindowTask(params) + if isAWSErr(err, ssm.ErrCodeDoesNotExistException, "") { + log.Printf("[WARN] Maintenance Window (%s) Task (%s) not found, removing from state", windowID, d.Id()) + d.SetId("") + return nil } - - resp, err := ssmconn.DescribeMaintenanceWindowTasks(params) if err != nil { - return err + return fmt.Errorf("Error getting Maintenance Window (%s) Task (%s): %s", windowID, d.Id(), err) } - found := false - for _, t := range resp.Tasks { - if *t.WindowTaskId == d.Id() { - found = true - - d.Set("window_id", t.WindowId) - d.Set("max_concurrency", t.MaxConcurrency) - d.Set("max_errors", t.MaxErrors) - d.Set("task_type", t.Type) - 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 { - return fmt.Errorf("Error setting logging_info error: %#v", err) - } - } - - if t.TaskParameters != nil { - if err := d.Set("task_parameters", flattenAwsSsmTaskParameters(t.TaskParameters)); err != nil { - return fmt.Errorf("Error setting task_parameters error: %#v", err) - } - } - - if err := d.Set("targets", flattenAwsSsmTargets(t.Targets)); err != nil { - return fmt.Errorf("Error setting targets error: %#v", err) - } + d.Set("window_id", resp.WindowId) + d.Set("max_concurrency", resp.MaxConcurrency) + d.Set("max_errors", resp.MaxErrors) + d.Set("task_type", resp.TaskType) + d.Set("service_role_arn", resp.ServiceRoleArn) + d.Set("task_arn", resp.TaskArn) + d.Set("priority", resp.Priority) + d.Set("name", resp.Name) + d.Set("description", resp.Description) + + if resp.LoggingInfo != nil { + if err := d.Set("logging_info", flattenAwsSsmMaintenanceWindowLoggingInfo(resp.LoggingInfo)); err != nil { + return fmt.Errorf("Error setting logging_info error: %#v", err) } } - if !found { - log.Printf("[INFO] Maintenance Window Target not found. Removing from state") - d.SetId("") - return nil + if resp.TaskParameters != nil { + if err := d.Set("task_parameters", flattenAwsSsmTaskParameters(resp.TaskParameters)); err != nil { + return fmt.Errorf("Error setting task_parameters error: %#v", err) + } + } + + if err := d.Set("targets", flattenAwsSsmTargets(resp.Targets)); err != nil { + return fmt.Errorf("Error setting targets error: %#v", err) } return nil From 925989f30d65478c56217824a7799a49d25732ea Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Tue, 5 Mar 2019 17:09:31 +0900 Subject: [PATCH 02/13] Add Update Step for aws_ssm_maintenance_window_task --- ...esource_aws_ssm_maintenance_window_task.go | 67 +++++++++++++++---- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/aws/resource_aws_ssm_maintenance_window_task.go b/aws/resource_aws_ssm_maintenance_window_task.go index 005ea9e5086..305579edb57 100644 --- a/aws/resource_aws_ssm_maintenance_window_task.go +++ b/aws/resource_aws_ssm_maintenance_window_task.go @@ -15,6 +15,7 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { return &schema.Resource{ Create: resourceAwsSsmMaintenanceWindowTaskCreate, Read: resourceAwsSsmMaintenanceWindowTaskRead, + Update: resourceAwsSsmMaintenanceWindowTaskUpdate, Delete: resourceAwsSsmMaintenanceWindowTaskDelete, Schema: map[string]*schema.Schema{ @@ -27,13 +28,11 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { "max_concurrency": { Type: schema.TypeString, Required: true, - ForceNew: true, }, "max_errors": { Type: schema.TypeString, Required: true, - ForceNew: true, }, "task_type": { @@ -45,30 +44,25 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { "task_arn": { Type: schema.TypeString, Required: true, - ForceNew: true, }, "service_role_arn": { Type: schema.TypeString, Required: true, - ForceNew: true, }, "targets": { Type: schema.TypeList, Required: true, - ForceNew: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "key": { Type: schema.TypeString, Required: true, - ForceNew: true, }, "values": { Type: schema.TypeList, Required: true, - ForceNew: true, Elem: &schema.Schema{Type: schema.TypeString}, }, }, @@ -78,28 +72,24 @@ 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(1, 128), }, "priority": { Type: schema.TypeInt, Optional: true, - ForceNew: true, }, "logging_info": { Type: schema.TypeList, MaxItems: 1, Optional: true, - ForceNew: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "s3_bucket_name": { @@ -121,18 +111,15 @@ 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, - ForceNew: true, }, "values": { Type: schema.TypeList, Required: true, - ForceNew: true, Elem: &schema.Schema{Type: schema.TypeString}, }, }, @@ -287,6 +274,55 @@ func resourceAwsSsmMaintenanceWindowTaskRead(d *schema.ResourceData, meta interf return nil } +func resourceAwsSsmMaintenanceWindowTaskUpdate(d *schema.ResourceData, meta interface{}) error { + ssmconn := meta.(*AWSClient).ssmconn + windowID := d.Get("window_id").(string) + + params := &ssm.UpdateMaintenanceWindowTaskInput{ + WindowId: aws.String(windowID), + WindowTaskId: aws.String(d.Id()), + MaxConcurrency: aws.String(d.Get("max_concurrency").(string)), + MaxErrors: aws.String(d.Get("max_errors").(string)), + ServiceRoleArn: aws.String(d.Get("service_role_arn").(string)), + TaskArn: aws.String(d.Get("task_arn").(string)), + Targets: expandAwsSsmTargets(d.Get("targets").([]interface{})), + Replace: aws.Bool(true), + } + + if v, ok := d.GetOk("name"); ok { + params.Name = aws.String(v.(string)) + } + + if v, ok := d.GetOk("description"); ok { + params.Description = aws.String(v.(string)) + } + + if v, ok := d.GetOk("priority"); ok { + params.Priority = aws.Int64(int64(v.(int))) + } + + if v, ok := d.GetOk("logging_info"); ok { + params.LoggingInfo = expandAwsSsmMaintenanceWindowLoggingInfo(v.([]interface{})) + } + + if v, ok := d.GetOk("task_parameters"); ok { + params.TaskParameters = expandAwsSsmTaskParameters(v.([]interface{})) + } + + _, err := ssmconn.UpdateMaintenanceWindowTask(params) + if isAWSErr(err, ssm.ErrCodeDoesNotExistException, "") { + log.Printf("[WARN] Maintenance Window (%s) Task (%s) not found, removing from state", windowID, d.Id()) + d.SetId("") + return nil + } + + if err != nil { + return fmt.Errorf("Error updating Maintenance Window (%s) Task (%s): %s", windowID, d.Id(), err) + } + + return resourceAwsSsmMaintenanceWindowTaskRead(d, meta) +} + func resourceAwsSsmMaintenanceWindowTaskDelete(d *schema.ResourceData, meta interface{}) error { ssmconn := meta.(*AWSClient).ssmconn @@ -298,6 +334,9 @@ func resourceAwsSsmMaintenanceWindowTaskDelete(d *schema.ResourceData, meta inte } _, err := ssmconn.DeregisterTaskFromMaintenanceWindow(params) + if isAWSErr(err, ssm.ErrCodeDoesNotExistException, "") { + return nil + } if err != nil { return fmt.Errorf("error deregistering SSM Maintenance Window Task (%s): %s", d.Id(), err) } From 1300ab931412635b404bacf4e6c310e84e594ce7 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Tue, 5 Mar 2019 21:54:53 +0900 Subject: [PATCH 03/13] Add support import resource --- ...esource_aws_ssm_maintenance_window_task.go | 19 ++++++++++ ...ce_aws_ssm_maintenance_window_task_test.go | 36 ++++++++++++++++--- .../ssm_maintenance_window_task.html.markdown | 8 +++++ 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/aws/resource_aws_ssm_maintenance_window_task.go b/aws/resource_aws_ssm_maintenance_window_task.go index 305579edb57..184c11cc9b0 100644 --- a/aws/resource_aws_ssm_maintenance_window_task.go +++ b/aws/resource_aws_ssm_maintenance_window_task.go @@ -3,6 +3,7 @@ package aws import ( "fmt" "log" + "strings" "github.com/hashicorp/terraform/helper/validation" @@ -17,6 +18,9 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { Read: resourceAwsSsmMaintenanceWindowTaskRead, Update: resourceAwsSsmMaintenanceWindowTaskUpdate, Delete: resourceAwsSsmMaintenanceWindowTaskDelete, + Importer: &schema.ResourceImporter{ + State: resourceAwsSsmMaintenanceWindowTaskImport, + }, Schema: map[string]*schema.Schema{ "window_id": { @@ -343,3 +347,18 @@ func resourceAwsSsmMaintenanceWindowTaskDelete(d *schema.ResourceData, meta inte return nil } + +func resourceAwsSsmMaintenanceWindowTaskImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + idParts := strings.SplitN(d.Id(), "/", 2) + if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { + return nil, fmt.Errorf("unexpected format of ID (%q), expected /", d.Id()) + } + + windowID := idParts[0] + windowTaskID := idParts[1] + + d.Set("window_id", windowID) + d.SetId(windowTaskID) + + return []*schema.ResourceData{d}, nil +} diff --git a/aws/resource_aws_ssm_maintenance_window_task_test.go b/aws/resource_aws_ssm_maintenance_window_task_test.go index 396eb00ec5b..d3925bcabd9 100644 --- a/aws/resource_aws_ssm_maintenance_window_task_test.go +++ b/aws/resource_aws_ssm_maintenance_window_task_test.go @@ -14,6 +14,7 @@ import ( func TestAccAWSSSMMaintenanceWindowTask_basic(t *testing.T) { var task ssm.MaintenanceWindowTask + resourceName := "aws_ssm_maintenance_window_task.target" name := acctest.RandString(10) resource.ParallelTest(t, resource.TestCase{ @@ -24,9 +25,15 @@ func TestAccAWSSSMMaintenanceWindowTask_basic(t *testing.T) { { Config: testAccAWSSSMMaintenanceWindowTaskBasicConfig(name), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSSSMMaintenanceWindowTaskExists("aws_ssm_maintenance_window_task.target", &task), + testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &task), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccAWSSSMMaintenanceWindowTaskImportStateIdFunc(resourceName), + ImportStateVerify: true, + }, }, }) } @@ -34,6 +41,8 @@ func TestAccAWSSSMMaintenanceWindowTask_basic(t *testing.T) { func TestAccAWSSSMMaintenanceWindowTask_updateForcesNewResource(t *testing.T) { var before, after ssm.MaintenanceWindowTask name := acctest.RandString(10) + resourceName := "aws_ssm_maintenance_window_task.target" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -42,18 +51,24 @@ func TestAccAWSSSMMaintenanceWindowTask_updateForcesNewResource(t *testing.T) { { Config: testAccAWSSSMMaintenanceWindowTaskBasicConfig(name), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSSSMMaintenanceWindowTaskExists("aws_ssm_maintenance_window_task.target", &before), + testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &before), ), }, { Config: testAccAWSSSMMaintenanceWindowTaskBasicConfigUpdated(name), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSSSMMaintenanceWindowTaskExists("aws_ssm_maintenance_window_task.target", &after), - resource.TestCheckResourceAttr("aws_ssm_maintenance_window_task.target", "name", "TestMaintenanceWindowTask"), - resource.TestCheckResourceAttr("aws_ssm_maintenance_window_task.target", "description", "This resource is for test purpose only"), + testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &after), + resource.TestCheckResourceAttr(resourceName, "name", "TestMaintenanceWindowTask"), + resource.TestCheckResourceAttr(resourceName, "description", "This resource is for test purpose only"), testAccCheckAwsSsmWindowsTaskRecreated(t, &before, &after), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccAWSSSMMaintenanceWindowTaskImportStateIdFunc(resourceName), + ImportStateVerify: true, + }, }, }) } @@ -129,6 +144,17 @@ func testAccCheckAWSSSMMaintenanceWindowTaskDestroy(s *terraform.State) error { return nil } +func testAccAWSSSMMaintenanceWindowTaskImportStateIdFunc(resourceName string) resource.ImportStateIdFunc { + return func(s *terraform.State) (string, error) { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return "", fmt.Errorf("Not found: %s", resourceName) + } + + return fmt.Sprintf("%s/%s", rs.Primary.Attributes["window_id"], rs.Primary.ID), nil + } +} + func testAccAWSSSMMaintenanceWindowTaskBasicConfig(rName string) string { return fmt.Sprintf(` resource "aws_ssm_maintenance_window" "foo" { diff --git a/website/docs/r/ssm_maintenance_window_task.html.markdown b/website/docs/r/ssm_maintenance_window_task.html.markdown index 2774d9f3e1d..0d9c4784497 100644 --- a/website/docs/r/ssm_maintenance_window_task.html.markdown +++ b/website/docs/r/ssm_maintenance_window_task.html.markdown @@ -82,3 +82,11 @@ The following arguments are supported: In addition to all arguments above, the following attributes are exported: * `id` - The ID of the maintenance window task. + +## Import + +AWS Maintenance Window Task can be imported using the `window_id` and `window_task_id` separated by `/`. + +```sh +$ terraform import aws_ssm_maintenance_window_task.task / +``` From 6b183428af63cd8c6253ded2a022015778f6823b Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Wed, 6 Mar 2019 15:36:04 +0900 Subject: [PATCH 04/13] Add support for task_invocation_parameters deprecated logging_info & task_parameters --- ...esource_aws_ssm_maintenance_window_task.go | 469 ++++++++++++- ...ce_aws_ssm_maintenance_window_task_test.go | 647 ++++++++++++++++++ .../ssm_maintenance_window_task.html.markdown | 53 +- 3 files changed, 1162 insertions(+), 7 deletions(-) diff --git a/aws/resource_aws_ssm_maintenance_window_task.go b/aws/resource_aws_ssm_maintenance_window_task.go index 184c11cc9b0..fa359f5ae30 100644 --- a/aws/resource_aws_ssm_maintenance_window_task.go +++ b/aws/resource_aws_ssm_maintenance_window_task.go @@ -3,6 +3,8 @@ package aws import ( "fmt" "log" + "regexp" + "sort" "strings" "github.com/hashicorp/terraform/helper/validation" @@ -91,9 +93,10 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { }, "logging_info": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Deprecated: "use 'task_invocation_parameters' argument instead", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "s3_bucket_name": { @@ -113,8 +116,9 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { }, "task_parameters": { - Type: schema.TypeList, - Optional: true, + Type: schema.TypeList, + Optional: true, + Deprecated: "use 'task_invocation_parameters' argument instead", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "name": { @@ -129,6 +133,189 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { }, }, }, + + "task_invocation_parameters": { + Type: schema.TypeList, + Optional: true, + ConflictsWith: []string{"task_parameters", "logging_info"}, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "automation_parameters": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "document_version": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringMatch(regexp.MustCompile("([$]LATEST|[$]DEFAULT|^[1-9][0-9]*$)"), "see https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_MaintenanceWindowAutomationParameters.html"), + }, + "parameters": { + Type: schema.TypeList, + Optional: 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}, + }, + }, + }, + }, + }, + }, + }, + + "lambda_parameters": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "client_context": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringLenBetween(1, 8000), + }, + + "payload": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + ValidateFunc: validation.StringLenBetween(0, 4096), + }, + + "qualifier": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringLenBetween(1, 128), + }, + }, + }, + }, + + "run_command_parameters": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "comment": { + Type: schema.TypeString, + Optional: true, + }, + + "document_hash": { + Type: schema.TypeString, + Optional: true, + }, + + "document_hash_type": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + ssm.DocumentHashTypeSha256, + ssm.DocumentHashTypeSha1, + }, false), + }, + + "notification_config": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "notification_arn": { + Type: schema.TypeString, + Optional: true, + }, + + "notification_events": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + + "notification_type": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + ssm.NotificationTypeCommand, + ssm.NotificationTypeInvocation, + }, false), + }, + }, + }, + }, + + "output_s3_bucket": { + Type: schema.TypeString, + Optional: true, + }, + + "output_s3_key_prefix": { + Type: schema.TypeString, + Optional: true, + }, + + "parameters": { + Type: schema.TypeList, + Optional: 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}, + }, + }, + }, + }, + + "service_role_arn": { + Type: schema.TypeString, + Optional: true, + }, + + "timeout_seconds": { + Type: schema.TypeInt, + Optional: true, + }, + }, + }, + }, + + "step_functions_parameters": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "input": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + ValidateFunc: validation.StringLenBetween(0, 4096), + }, + + "name": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringLenBetween(1, 80), + }, + }, + }, + }, + }, + }, + }, }, } } @@ -186,6 +373,264 @@ func flattenAwsSsmTaskParameters(taskParameters map[string]*ssm.MaintenanceWindo return result } +func expandAwsSsmTaskInvocationParameters(config []interface{}) *ssm.MaintenanceWindowTaskInvocationParameters { + params := &ssm.MaintenanceWindowTaskInvocationParameters{} + for _, v := range config { + paramConfig := v.(map[string]interface{}) + if attr, ok := paramConfig["automation_parameters"]; ok && len(attr.([]interface{})) > 0 { + params.Automation = expandAwsSsmTaskInvocationAutomationParameters(attr.([]interface{})) + } + if attr, ok := paramConfig["lambda_parameters"]; ok && len(attr.([]interface{})) > 0 { + params.Lambda = expandAwsSsmTaskInvocationLambdaParameters(attr.([]interface{})) + } + if attr, ok := paramConfig["run_command_parameters"]; ok && len(attr.([]interface{})) > 0 { + params.RunCommand = expandAwsSsmTaskInvocationRunCommandParameters(attr.([]interface{})) + } + if attr, ok := paramConfig["step_functions_parameters"]; ok && len(attr.([]interface{})) > 0 { + params.StepFunctions = expandAwsSsmTaskInvocationStepFunctionsParameters(attr.([]interface{})) + } + } + return params +} + +func flattenAwsSsmTaskInvocationParameters(parameters *ssm.MaintenanceWindowTaskInvocationParameters) []interface{} { + result := make(map[string]interface{}) + if parameters.Automation != nil { + result["automation_parameters"] = flattenAwsSsmTaskInvocationAutomationParameters(parameters.Automation) + } + + if parameters.Lambda != nil { + result["lambda_parameters"] = flattenAwsSsmTaskInvocationLambdaParameters(parameters.Lambda) + } + + if parameters.RunCommand != nil { + result["run_command_parameters"] = flattenAwsSsmTaskInvocationRunCommandParameters(parameters.RunCommand) + } + + if parameters.StepFunctions != nil { + result["step_functions_parameters"] = flattenAwsSsmTaskInvocationStepFunctionsParameters(parameters.StepFunctions) + } + + return []interface{}{result} +} + +func expandAwsSsmTaskInvocationAutomationParameters(config []interface{}) *ssm.MaintenanceWindowAutomationParameters { + params := &ssm.MaintenanceWindowAutomationParameters{} + configParam := config[0].(map[string]interface{}) + if attr, ok := configParam["document_version"]; ok && len(attr.(string)) != 0 { + params.DocumentVersion = aws.String(attr.(string)) + } + if attr, ok := configParam["parameters"]; ok && len(attr.([]interface{})) > 0 { + params.Parameters = expandAwsSsmTaskInvocationCommonParameters(attr.([]interface{})) + } + + return params +} + +func flattenAwsSsmTaskInvocationAutomationParameters(parameters *ssm.MaintenanceWindowAutomationParameters) []interface{} { + result := make(map[string]interface{}) + + if parameters.DocumentVersion != nil { + result["document_version"] = aws.StringValue(parameters.DocumentVersion) + } + if parameters.Parameters != nil { + result["parameters"] = flattenAwsSsmTaskInvocationCommonParameters(parameters.Parameters) + } + + return []interface{}{result} +} + +func expandAwsSsmTaskInvocationLambdaParameters(config []interface{}) *ssm.MaintenanceWindowLambdaParameters { + params := &ssm.MaintenanceWindowLambdaParameters{} + configParam := config[0].(map[string]interface{}) + if attr, ok := configParam["client_context"]; ok && len(attr.(string)) != 0 { + params.ClientContext = aws.String(attr.(string)) + } + if attr, ok := configParam["payload"]; ok && len(attr.(string)) != 0 { + params.Payload = []byte(attr.(string)) + } + if attr, ok := configParam["qualifier"]; ok && len(attr.(string)) != 0 { + params.Qualifier = aws.String(attr.(string)) + } + return params +} + +func flattenAwsSsmTaskInvocationLambdaParameters(parameters *ssm.MaintenanceWindowLambdaParameters) []interface{} { + result := make(map[string]interface{}) + + if parameters.ClientContext != nil { + result["client_context"] = aws.StringValue(parameters.ClientContext) + } + if parameters.Payload != nil { + result["payload"] = string(parameters.Payload) + } + if parameters.Qualifier != nil { + result["qualifier"] = aws.StringValue(parameters.Qualifier) + } + return []interface{}{result} +} + +func expandAwsSsmTaskInvocationRunCommandParameters(config []interface{}) *ssm.MaintenanceWindowRunCommandParameters { + params := &ssm.MaintenanceWindowRunCommandParameters{} + configParam := config[0].(map[string]interface{}) + if attr, ok := configParam["comment"]; ok && len(attr.(string)) != 0 { + params.Comment = aws.String(attr.(string)) + } + if attr, ok := configParam["document_hash"]; ok && len(attr.(string)) != 0 { + params.DocumentHash = aws.String(attr.(string)) + } + if attr, ok := configParam["document_hash_type"]; ok && len(attr.(string)) != 0 { + params.DocumentHashType = aws.String(attr.(string)) + } + if attr, ok := configParam["notification_config"]; ok && len(attr.([]interface{})) > 0 { + params.NotificationConfig = expandAwsSsmTaskInvocationRunCommandParametersNotificationConfig(attr.([]interface{})) + } + if attr, ok := configParam["output_s3_bucket"]; ok && len(attr.(string)) != 0 { + params.OutputS3BucketName = aws.String(attr.(string)) + } + if attr, ok := configParam["output_s3_key_prefix"]; ok && len(attr.(string)) != 0 { + params.OutputS3KeyPrefix = aws.String(attr.(string)) + } + if attr, ok := configParam["parameters"]; ok && len(attr.([]interface{})) > 0 { + params.Parameters = expandAwsSsmTaskInvocationCommonParameters(attr.([]interface{})) + } + if attr, ok := configParam["service_role_arn"]; ok && len(attr.(string)) != 0 { + params.ServiceRoleArn = aws.String(attr.(string)) + } + if attr, ok := configParam["timeout_seconds"]; ok && attr.(int) != 0 { + params.TimeoutSeconds = aws.Int64(int64(attr.(int))) + } + return params +} + +func flattenAwsSsmTaskInvocationRunCommandParameters(parameters *ssm.MaintenanceWindowRunCommandParameters) []interface{} { + result := make(map[string]interface{}) + + if parameters.Comment != nil { + result["comment"] = aws.StringValue(parameters.Comment) + } + if parameters.DocumentHash != nil { + result["document_hash"] = aws.StringValue(parameters.DocumentHash) + } + if parameters.DocumentHashType != nil { + result["document_hash_type"] = aws.StringValue(parameters.DocumentHashType) + } + if parameters.NotificationConfig != nil { + result["notification_config"] = flattenAwsSsmTaskInvocationRunCommandParametersNotificationConfig(parameters.NotificationConfig) + } + if parameters.OutputS3BucketName != nil { + result["output_s3_bucket"] = aws.StringValue(parameters.OutputS3BucketName) + } + if parameters.OutputS3KeyPrefix != nil { + result["output_s3_key_prefix"] = aws.StringValue(parameters.OutputS3KeyPrefix) + } + if parameters.Parameters != nil { + result["parameters"] = flattenAwsSsmTaskInvocationCommonParameters(parameters.Parameters) + } + if parameters.ServiceRoleArn != nil { + result["service_role_arn"] = aws.StringValue(parameters.ServiceRoleArn) + } + if parameters.TimeoutSeconds != nil { + result["timeout_seconds"] = aws.Int64Value(parameters.TimeoutSeconds) + } + + return []interface{}{result} +} + +func expandAwsSsmTaskInvocationStepFunctionsParameters(config []interface{}) *ssm.MaintenanceWindowStepFunctionsParameters { + params := &ssm.MaintenanceWindowStepFunctionsParameters{} + configParam := config[0].(map[string]interface{}) + + if attr, ok := configParam["input"]; ok && len(attr.(string)) != 0 { + params.Input = aws.String(attr.(string)) + } + if attr, ok := configParam["name"]; ok && len(attr.(string)) != 0 { + params.Name = aws.String(attr.(string)) + } + + return params +} + +func flattenAwsSsmTaskInvocationStepFunctionsParameters(parameters *ssm.MaintenanceWindowStepFunctionsParameters) []interface{} { + result := make(map[string]interface{}) + + if parameters.Input != nil { + result["input"] = aws.StringValue(parameters.Input) + } + if parameters.Name != nil { + result["name"] = aws.StringValue(parameters.Name) + } + return []interface{}{result} +} + +func expandAwsSsmTaskInvocationRunCommandParametersNotificationConfig(config []interface{}) *ssm.NotificationConfig { + params := &ssm.NotificationConfig{} + configParam := config[0].(map[string]interface{}) + + if attr, ok := configParam["notification_arn"]; ok && len(attr.(string)) != 0 { + params.NotificationArn = aws.String(attr.(string)) + } + if attr, ok := configParam["notification_events"]; ok && len(attr.([]interface{})) > 0 { + params.NotificationEvents = expandStringList(attr.([]interface{})) + } + if attr, ok := configParam["notification_type"]; ok && len(attr.(string)) != 0 { + params.NotificationType = aws.String(attr.(string)) + } + + return params +} + +func flattenAwsSsmTaskInvocationRunCommandParametersNotificationConfig(config *ssm.NotificationConfig) []interface{} { + result := make(map[string]interface{}) + + if config.NotificationArn != nil { + result["notification_arn"] = aws.StringValue(config.NotificationArn) + } + if config.NotificationEvents != nil { + result["notification_events"] = flattenStringList(config.NotificationEvents) + } + if config.NotificationType != nil { + result["notification_type"] = aws.StringValue(config.NotificationType) + } + + return []interface{}{result} +} + +func expandAwsSsmTaskInvocationCommonParameters(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 flattenAwsSsmTaskInvocationCommonParameters(parameters map[string][]*string) []interface{} { + result := make([]interface{}, 0, len(parameters)) + + keys := make([]string, 0, len(parameters)) + for k := range parameters { + keys = append(keys, k) + } + sort.Strings(keys) + + for _, key := range keys { + values := make([]string, 0) + for _, value := range parameters[key] { + values = append(values, aws.StringValue(value)) + } + params := map[string]interface{}{ + "name": key, + "values": values, + } + result = append(result, params) + } + + return result +} + func resourceAwsSsmMaintenanceWindowTaskCreate(d *schema.ResourceData, meta interface{}) error { ssmconn := meta.(*AWSClient).ssmconn @@ -221,6 +666,10 @@ func resourceAwsSsmMaintenanceWindowTaskCreate(d *schema.ResourceData, meta inte params.TaskParameters = expandAwsSsmTaskParameters(v.([]interface{})) } + if v, ok := d.GetOk("task_invocation_parameters"); ok { + params.TaskInvocationParameters = expandAwsSsmTaskInvocationParameters(v.([]interface{})) + } + resp, err := ssmconn.RegisterTaskWithMaintenanceWindow(params) if err != nil { return err @@ -271,6 +720,12 @@ func resourceAwsSsmMaintenanceWindowTaskRead(d *schema.ResourceData, meta interf } } + if resp.TaskInvocationParameters != nil { + if err := d.Set("task_invocation_parameters", flattenAwsSsmTaskInvocationParameters(resp.TaskInvocationParameters)); err != nil { + return fmt.Errorf("Error setting task_invocation_parameters error: %#v", err) + } + } + if err := d.Set("targets", flattenAwsSsmTargets(resp.Targets)); err != nil { return fmt.Errorf("Error setting targets error: %#v", err) } @@ -313,6 +768,10 @@ func resourceAwsSsmMaintenanceWindowTaskUpdate(d *schema.ResourceData, meta inte params.TaskParameters = expandAwsSsmTaskParameters(v.([]interface{})) } + if v, ok := d.GetOk("task_invocation_parameters"); ok { + params.TaskInvocationParameters = expandAwsSsmTaskInvocationParameters(v.([]interface{})) + } + _, err := ssmconn.UpdateMaintenanceWindowTask(params) if isAWSErr(err, ssm.ErrCodeDoesNotExistException, "") { log.Printf("[WARN] Maintenance Window (%s) Task (%s) not found, removing from state", windowID, d.Id()) diff --git a/aws/resource_aws_ssm_maintenance_window_task_test.go b/aws/resource_aws_ssm_maintenance_window_task_test.go index d3925bcabd9..a41cae22334 100644 --- a/aws/resource_aws_ssm_maintenance_window_task_test.go +++ b/aws/resource_aws_ssm_maintenance_window_task_test.go @@ -73,6 +73,139 @@ func TestAccAWSSSMMaintenanceWindowTask_updateForcesNewResource(t *testing.T) { }) } +func TestAccAWSSSMMaintenanceWindowTask_TaskInvocationAutomationParameters(t *testing.T) { + var task ssm.MaintenanceWindowTask + resourceName := "aws_ssm_maintenance_window_task.target" + + name := acctest.RandString(10) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSSSMMaintenanceWindowTaskDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSSSMMaintenanceWindowTaskAutomationConfig(name, "$DEFAULT"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &task), + resource.TestCheckResourceAttr(resourceName, "task_invocation_parameters.0.automation_parameters.0.document_version", "$DEFAULT"), + ), + }, + { + Config: testAccAWSSSMMaintenanceWindowTaskAutomationConfigUpdate(name, "$LATEST"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &task), + resource.TestCheckResourceAttr(resourceName, "task_invocation_parameters.0.automation_parameters.0.document_version", "$LATEST"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccAWSSSMMaintenanceWindowTaskImportStateIdFunc(resourceName), + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAWSSSMMaintenanceWindowTask_TaskInvocationLambdaParameters(t *testing.T) { + var task ssm.MaintenanceWindowTask + resourceName := "aws_ssm_maintenance_window_task.target" + rString := acctest.RandString(8) + rInt := acctest.RandInt() + + funcName := fmt.Sprintf("tf_acc_lambda_func_tags_%s", rString) + policyName := fmt.Sprintf("tf_acc_policy_lambda_func_tags_%s", rString) + roleName := fmt.Sprintf("tf_acc_role_lambda_func_tags_%s", rString) + sgName := fmt.Sprintf("tf_acc_sg_lambda_func_tags_%s", rString) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSSSMMaintenanceWindowTaskDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSSSMMaintenanceWindowTaskLambdaConfig(funcName, policyName, roleName, sgName, rString, rInt), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &task), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccAWSSSMMaintenanceWindowTaskImportStateIdFunc(resourceName), + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAWSSSMMaintenanceWindowTask_TaskInvocationRunCommandParameters(t *testing.T) { + var task ssm.MaintenanceWindowTask + resourceName := "aws_ssm_maintenance_window_task.target" + serviceRoleResourceName := "aws_iam_role.ssm_role" + s3BucketResourceName := "aws_s3_bucket.foo" + + name := acctest.RandString(10) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSSSMMaintenanceWindowTaskDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSSSMMaintenanceWindowTaskRunCommandConfig(name, "test comment", 30), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &task), + resource.TestCheckResourceAttrPair(resourceName, "service_role_arn", serviceRoleResourceName, "arn"), + resource.TestCheckResourceAttrPair(resourceName, "task_invocation_parameters.0.run_command_parameters.0.service_role_arn", serviceRoleResourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "task_invocation_parameters.0.run_command_parameters.0.comment", "test comment"), + resource.TestCheckResourceAttr(resourceName, "task_invocation_parameters.0.run_command_parameters.0.timeout_seconds", "30"), + ), + }, + { + Config: testAccAWSSSMMaintenanceWindowTaskRunCommandConfigUpdate(name, "test comment update", 60), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &task), + resource.TestCheckResourceAttr(resourceName, "task_invocation_parameters.0.run_command_parameters.0.comment", "test comment update"), + resource.TestCheckResourceAttr(resourceName, "task_invocation_parameters.0.run_command_parameters.0.timeout_seconds", "60"), + resource.TestCheckResourceAttrPair(resourceName, "task_invocation_parameters.0.run_command_parameters.0.output_s3_bucket", s3BucketResourceName, "id"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccAWSSSMMaintenanceWindowTaskImportStateIdFunc(resourceName), + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAWSSSMMaintenanceWindowTask_TaskInvocationStepFunctionParameters(t *testing.T) { + var task ssm.MaintenanceWindowTask + resourceName := "aws_ssm_maintenance_window_task.target" + rString := acctest.RandString(8) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSSSMMaintenanceWindowTaskDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSSSMMaintenanceWindowTaskStepFunctionConfig(rString), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &task), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccAWSSSMMaintenanceWindowTaskImportStateIdFunc(resourceName), + ImportStateVerify: true, + }, + }, + }) +} + func testAccCheckAwsSsmWindowsTaskRecreated(t *testing.T, before, after *ssm.MaintenanceWindowTask) resource.TestCheckFunc { return func(s *terraform.State) error { @@ -302,3 +435,517 @@ EOF } `, rName, rName, rName) } + +func testAccAWSSSMMaintenanceWindowTaskAutomationConfig(rName, version string) string { + return fmt.Sprintf(` +resource "aws_ssm_maintenance_window" "foo" { + name = "maintenance-window-%[1]s" + schedule = "cron(0 16 ? * TUE *)" + duration = 3 + cutoff = 1 +} + +resource "aws_ssm_maintenance_window_task" "target" { + window_id = "${aws_ssm_maintenance_window.foo.id}" + task_type = "AUTOMATION" + task_arn = "AWS-CreateImage" + priority = 1 + service_role_arn = "${aws_iam_role.ssm_role.arn}" + max_concurrency = "2" + max_errors = "1" + targets { + key = "InstanceIds" + values = ["${aws_instance.foo.id}"] + } + task_invocation_parameters { + automation_parameters { + document_version = "%[2]s" + parameters { + name = "InstanceId" + values = ["${aws_instance.foo.id}"] + } + parameters { + name = "NoReboot" + values = ["false"] + } + } + } +} + +resource "aws_instance" "foo" { + ami = "ami-4fccb37f" + + instance_type = "m1.small" +} + +resource "aws_iam_role" "ssm_role" { + name = "ssm-role-%[1]s" + + assume_role_policy = < Date: Tue, 9 Jul 2019 12:35:33 +0900 Subject: [PATCH 05/13] fix to space --- ...ce_aws_ssm_maintenance_window_task_test.go | 290 +++++++++--------- 1 file changed, 145 insertions(+), 145 deletions(-) diff --git a/aws/resource_aws_ssm_maintenance_window_task_test.go b/aws/resource_aws_ssm_maintenance_window_task_test.go index a41cae22334..eb5d3c80f7f 100644 --- a/aws/resource_aws_ssm_maintenance_window_task_test.go +++ b/aws/resource_aws_ssm_maintenance_window_task_test.go @@ -291,20 +291,20 @@ func testAccAWSSSMMaintenanceWindowTaskImportStateIdFunc(resourceName string) re func testAccAWSSSMMaintenanceWindowTaskBasicConfig(rName string) string { return fmt.Sprintf(` resource "aws_ssm_maintenance_window" "foo" { - name = "maintenance-window-%s" + name = "maintenance-window-%s" schedule = "cron(0 16 ? * TUE *)" duration = 3 cutoff = 1 } resource "aws_ssm_maintenance_window_task" "target" { - window_id = "${aws_ssm_maintenance_window.foo.id}" - task_type = "RUN_COMMAND" - task_arn = "AWS-RunShellScript" - priority = 1 + window_id = "${aws_ssm_maintenance_window.foo.id}" + task_type = "RUN_COMMAND" + task_arn = "AWS-RunShellScript" + priority = 1 service_role_arn = "${aws_iam_role.ssm_role.arn}" max_concurrency = "2" - max_errors = "1" + max_errors = "1" targets { key = "InstanceIds" @@ -330,14 +330,14 @@ resource "aws_iam_role" "ssm_role" { { "Version": "2012-10-17", "Statement": [ - { - "Action": "sts:AssumeRole", - "Principal": { - "Service": "events.amazonaws.com" - }, - "Effect": "Allow", - "Sid": "" - } + { + "Action": "sts:AssumeRole", + "Principal": { + "Service": "events.amazonaws.com" + }, + "Effect": "Allow", + "Sid": "" + } ] } POLICY @@ -364,22 +364,22 @@ EOF func testAccAWSSSMMaintenanceWindowTaskBasicConfigUpdated(rName string) string { return fmt.Sprintf(` resource "aws_ssm_maintenance_window" "foo" { - name = "maintenance-window-%s" + name = "maintenance-window-%s" schedule = "cron(0 16 ? * TUE *)" duration = 3 cutoff = 1 } resource "aws_ssm_maintenance_window_task" "target" { - window_id = "${aws_ssm_maintenance_window.foo.id}" - task_type = "RUN_COMMAND" - task_arn = "AWS-RunShellScript" - priority = 1 - name = "TestMaintenanceWindowTask" - description = "This resource is for test purpose only" + window_id = "${aws_ssm_maintenance_window.foo.id}" + 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" + max_errors = "1" targets { key = "InstanceIds" @@ -405,14 +405,14 @@ resource "aws_iam_role" "ssm_role" { { "Version": "2012-10-17", "Statement": [ - { - "Action": "sts:AssumeRole", - "Principal": { - "Service": "events.amazonaws.com" - }, - "Effect": "Allow", - "Sid": "" - } + { + "Action": "sts:AssumeRole", + "Principal": { + "Service": "events.amazonaws.com" + }, + "Effect": "Allow", + "Sid": "" + } ] } POLICY @@ -458,17 +458,17 @@ resource "aws_ssm_maintenance_window_task" "target" { values = ["${aws_instance.foo.id}"] } task_invocation_parameters { - automation_parameters { - document_version = "%[2]s" - parameters { - name = "InstanceId" - values = ["${aws_instance.foo.id}"] - } - parameters { - name = "NoReboot" - values = ["false"] - } - } + automation_parameters { + document_version = "%[2]s" + parameters { + name = "InstanceId" + values = ["${aws_instance.foo.id}"] + } + parameters { + name = "NoReboot" + values = ["false"] + } + } } } @@ -485,14 +485,14 @@ resource "aws_iam_role" "ssm_role" { { "Version": "2012-10-17", "Statement": [ - { - "Action": "sts:AssumeRole", - "Principal": { - "Service": "events.amazonaws.com" - }, - "Effect": "Allow", - "Sid": "" - } + { + "Action": "sts:AssumeRole", + "Principal": { + "Service": "events.amazonaws.com" + }, + "Effect": "Allow", + "Sid": "" + } ] } POLICY @@ -520,9 +520,9 @@ EOF func testAccAWSSSMMaintenanceWindowTaskAutomationConfigUpdate(rName, version string) string { return fmt.Sprintf(` resource "aws_s3_bucket" "foo" { - bucket = "tf-s3-%[1]s" - acl = "private" - force_destroy = true + bucket = "tf-s3-%[1]s" + acl = "private" + force_destroy = true } resource "aws_ssm_maintenance_window" "foo" { @@ -545,17 +545,17 @@ resource "aws_ssm_maintenance_window_task" "target" { values = ["${aws_instance.foo.id}"] } task_invocation_parameters { - automation_parameters { - document_version = "%[2]s" - parameters { - name = "InstanceId" - values = ["${aws_instance.foo.id}"] - } - parameters { - name = "NoReboot" - values = ["false"] - } - } + automation_parameters { + document_version = "%[2]s" + parameters { + name = "InstanceId" + values = ["${aws_instance.foo.id}"] + } + parameters { + name = "NoReboot" + values = ["false"] + } + } } } @@ -572,14 +572,14 @@ resource "aws_iam_role" "ssm_role" { { "Version": "2012-10-17", "Statement": [ - { - "Action": "sts:AssumeRole", - "Principal": { - "Service": "events.amazonaws.com" - }, - "Effect": "Allow", - "Sid": "" - } + { + "Action": "sts:AssumeRole", + "Principal": { + "Service": "events.amazonaws.com" + }, + "Effect": "Allow", + "Sid": "" + } ] } POLICY @@ -626,10 +626,10 @@ resource "aws_ssm_maintenance_window_task" "target" { values = ["${aws_instance.foo.id}"] } task_invocation_parameters { - lambda_parameters { - client_context = "${base64encode(data.template_file.client_context.rendered)}" - payload = "${data.template_file.payload.rendered}" - } + lambda_parameters { + client_context = "${base64encode(data.template_file.client_context.rendered)}" + payload = "${data.template_file.payload.rendered}" + } } } @@ -646,14 +646,14 @@ resource "aws_iam_role" "ssm_role" { { "Version": "2012-10-17", "Statement": [ - { - "Action": "sts:AssumeRole", - "Principal": { - "Service": "events.amazonaws.com" - }, - "Effect": "Allow", - "Sid": "" - } + { + "Action": "sts:AssumeRole", + "Principal": { + "Service": "events.amazonaws.com" + }, + "Effect": "Allow", + "Sid": "" + } ] } POLICY @@ -678,9 +678,9 @@ EOF data "template_file" "client_context" { template = < Date: Tue, 9 Jul 2019 12:35:59 +0900 Subject: [PATCH 06/13] fix to follow review comment --- .../docs/r/ssm_maintenance_window_task.html.markdown | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/website/docs/r/ssm_maintenance_window_task.html.markdown b/website/docs/r/ssm_maintenance_window_task.html.markdown index 88c672bf2a3..e51e9e872ee 100644 --- a/website/docs/r/ssm_maintenance_window_task.html.markdown +++ b/website/docs/r/ssm_maintenance_window_task.html.markdown @@ -63,9 +63,9 @@ The following arguments are supported: * `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,**Deprecated**) A structure containing information about an Amazon S3 bucket to write instance-level logs to. Documented below. -* `task_parameters` - (Optional,**Deprecated**) A structure containing information about parameters required by the particular `task_arn`. Documented below. -* `task_invocation_parameters` - (Optional) The parameters for task execution. +* `logging_info` - (Optional, **Deprecated**) A structure containing information about an Amazon S3 bucket to write instance-level logs to. Use `task_invocation_parameters` configuration block `run_command_parameters` configuration block `output_s3_*` arguments instead. Conflicts with `task_invocation_parameters`. Documented below. +* `task_parameters` - (Optional, **Deprecated**) A structure containing information about parameters required by the particular `task_arn`. Use `parameter` configuration blocks under the `task_invocation_parameters` configuration block instead. Conflicts with `task_invocation_parameters`. Documented below. +* `task_invocation_parameters` - (Optional) The parameters for task execution. This argument is conflict with `task_parameters` and `logging_info`. `logging_info` supports the following: @@ -80,12 +80,10 @@ The following arguments are supported: `task_invocation_parameters` supports the following: -This argument is conflict with `task_parameters` and `logging_info`. - * `automation_parameters` - (Optional) The parameters for an AUTOMATION task type. Documented below. * `lambda_parameters` - (Optional) The parameters for a LAMBDA task type. Documented below. * `run_command_parameters` - (Optional) The parameters for a RUN_COMMAND task type. Documented below. -* `step_functions_parameters` - (Optional) +* `step_functions_parameters` - (Optional) The parameters for a STEP_FUNCTIONS task type. Documented below. `automation_parameters` supports the following: From b36e54b22d302f7234d8e865f5b5a97c7791ea47 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Fri, 12 Jul 2019 18:50:06 +0900 Subject: [PATCH 07/13] Add acctest case for removed ForceNew setting attributes --- ...ce_aws_ssm_maintenance_window_task_test.go | 114 ++++++++++++++++-- 1 file changed, 104 insertions(+), 10 deletions(-) diff --git a/aws/resource_aws_ssm_maintenance_window_task_test.go b/aws/resource_aws_ssm_maintenance_window_task_test.go index eb5d3c80f7f..af6a16d2b58 100644 --- a/aws/resource_aws_ssm_maintenance_window_task_test.go +++ b/aws/resource_aws_ssm_maintenance_window_task_test.go @@ -13,7 +13,7 @@ import ( ) func TestAccAWSSSMMaintenanceWindowTask_basic(t *testing.T) { - var task ssm.MaintenanceWindowTask + var before, after ssm.MaintenanceWindowTask resourceName := "aws_ssm_maintenance_window_task.target" name := acctest.RandString(10) @@ -25,7 +25,18 @@ func TestAccAWSSSMMaintenanceWindowTask_basic(t *testing.T) { { Config: testAccAWSSSMMaintenanceWindowTaskBasicConfig(name), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &task), + testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &before), + ), + }, + { + Config: testAccAWSSSMMaintenanceWindowTaskBasicConfigUpdate(name, "RUN_COMMAND", "AWS-InstallPowerShellModule", 3, 2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &after), + resource.TestCheckResourceAttr(resourceName, "task_type", "RUN_COMMAND"), + resource.TestCheckResourceAttr(resourceName, "task_arn", "AWS-InstallPowerShellModule"), + resource.TestCheckResourceAttr(resourceName, "max_concurrency", "3"), + resource.TestCheckResourceAttr(resourceName, "max_errors", "2"), + testAccCheckAwsSsmWindowsTaskNotRecreated(t, &before, &after), ), }, { @@ -206,6 +217,16 @@ func TestAccAWSSSMMaintenanceWindowTask_TaskInvocationStepFunctionParameters(t * }) } +func testAccCheckAwsSsmWindowsTaskNotRecreated(t *testing.T, + before, after *ssm.MaintenanceWindowTask) resource.TestCheckFunc { + return func(s *terraform.State) error { + if aws.StringValue(before.WindowTaskId) != aws.StringValue(after.WindowTaskId) { + t.Fatalf("Unexpected change of Windows Task IDs, but both were %s and %s", aws.StringValue(before.WindowTaskId), aws.StringValue(after.WindowTaskId)) + } + return nil + } +} + func testAccCheckAwsSsmWindowsTaskRecreated(t *testing.T, before, after *ssm.MaintenanceWindowTask) resource.TestCheckFunc { return func(s *terraform.State) error { @@ -291,7 +312,7 @@ func testAccAWSSSMMaintenanceWindowTaskImportStateIdFunc(resourceName string) re func testAccAWSSSMMaintenanceWindowTaskBasicConfig(rName string) string { return fmt.Sprintf(` resource "aws_ssm_maintenance_window" "foo" { - name = "maintenance-window-%s" + name = "maintenance-window-%[1]s" schedule = "cron(0 16 ? * TUE *)" duration = 3 cutoff = 1 @@ -324,7 +345,7 @@ resource "aws_instance" "foo" { } resource "aws_iam_role" "ssm_role" { - name = "ssm-role-%s" + name = "ssm-role-%[1]s" assume_role_policy = < Date: Sat, 13 Jul 2019 14:40:34 +0900 Subject: [PATCH 08/13] add missing test case --- ...urce_aws_ssm_maintenance_window_task_test.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/aws/resource_aws_ssm_maintenance_window_task_test.go b/aws/resource_aws_ssm_maintenance_window_task_test.go index af6a16d2b58..0666ad621e1 100644 --- a/aws/resource_aws_ssm_maintenance_window_task_test.go +++ b/aws/resource_aws_ssm_maintenance_window_task_test.go @@ -29,11 +29,14 @@ func TestAccAWSSSMMaintenanceWindowTask_basic(t *testing.T) { ), }, { - Config: testAccAWSSSMMaintenanceWindowTaskBasicConfigUpdate(name, "RUN_COMMAND", "AWS-InstallPowerShellModule", 3, 2), + Config: testAccAWSSSMMaintenanceWindowTaskBasicConfigUpdate(name, "test description", "RUN_COMMAND", "AWS-InstallPowerShellModule", 3, 3, 2), Check: resource.ComposeTestCheckFunc( testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &after), + resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("maintenance-window-task-%s", name)), + resource.TestCheckResourceAttr(resourceName, "description", "test description"), resource.TestCheckResourceAttr(resourceName, "task_type", "RUN_COMMAND"), resource.TestCheckResourceAttr(resourceName, "task_arn", "AWS-InstallPowerShellModule"), + resource.TestCheckResourceAttr(resourceName, "priority", "3"), resource.TestCheckResourceAttr(resourceName, "max_concurrency", "3"), resource.TestCheckResourceAttr(resourceName, "max_errors", "2"), testAccCheckAwsSsmWindowsTaskNotRecreated(t, &before, &after), @@ -382,7 +385,7 @@ EOF `, rName) } -func testAccAWSSSMMaintenanceWindowTaskBasicConfigUpdate(rName, taskType, taskArn string, maxConcurrency, maxErrors int) string { +func testAccAWSSSMMaintenanceWindowTaskBasicConfigUpdate(rName, description, taskType, taskArn string, priority, maxConcurrency, maxErrors int) string { return fmt.Sprintf(` resource "aws_ssm_maintenance_window" "foo" { name = "maintenance-window-%[1]s" @@ -395,10 +398,12 @@ resource "aws_ssm_maintenance_window_task" "target" { window_id = "${aws_ssm_maintenance_window.foo.id}" task_type = "%[2]s" task_arn = "%[3]s" - priority = 1 + name = "maintenance-window-task-%[1]s" + description = "%[4]s" + priority = %[5]d service_role_arn = "${aws_iam_role.ssm_role_update.arn}" - max_concurrency = %[4]d - max_errors = %[5]d + max_concurrency = %[6]d + max_errors = %[7]d targets { key = "InstanceIds" @@ -452,7 +457,7 @@ resource "aws_iam_role_policy" "bar" { } EOF } -`, rName, taskType, taskArn, maxConcurrency, maxErrors) +`, rName, taskType, taskArn, description, priority, maxConcurrency, maxErrors) } func testAccAWSSSMMaintenanceWindowTaskBasicConfigUpdated(rName string) string { From ef4bf15ce230705b7263df7d1ac2f9cf83b5d4b4 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Sat, 13 Jul 2019 14:41:58 +0900 Subject: [PATCH 09/13] add missing ConflictsWith setting --- aws/resource_aws_ssm_maintenance_window_task.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/aws/resource_aws_ssm_maintenance_window_task.go b/aws/resource_aws_ssm_maintenance_window_task.go index fa359f5ae30..60fbf10f90a 100644 --- a/aws/resource_aws_ssm_maintenance_window_task.go +++ b/aws/resource_aws_ssm_maintenance_window_task.go @@ -93,10 +93,11 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { }, "logging_info": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Deprecated: "use 'task_invocation_parameters' argument instead", + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + ConflictsWith: []string{"task_invocation_parameters"}, + Deprecated: "use 'task_invocation_parameters' argument instead", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "s3_bucket_name": { @@ -116,9 +117,10 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { }, "task_parameters": { - Type: schema.TypeList, - Optional: true, - Deprecated: "use 'task_invocation_parameters' argument instead", + Type: schema.TypeList, + Optional: true, + ConflictsWith: []string{"task_invocation_parameters"}, + Deprecated: "use 'task_invocation_parameters' argument instead", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "name": { From fc858efc2817498476d2f13fcc1fa162e1c0ff52 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Sat, 13 Jul 2019 14:44:00 +0900 Subject: [PATCH 10/13] add missing MaxItems setting --- aws/resource_aws_ssm_maintenance_window_task.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aws/resource_aws_ssm_maintenance_window_task.go b/aws/resource_aws_ssm_maintenance_window_task.go index 60fbf10f90a..d7de3511bab 100644 --- a/aws/resource_aws_ssm_maintenance_window_task.go +++ b/aws/resource_aws_ssm_maintenance_window_task.go @@ -146,6 +146,7 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { "automation_parameters": { Type: schema.TypeList, Optional: true, + MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "document_version": { @@ -177,6 +178,7 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { "lambda_parameters": { Type: schema.TypeList, Optional: true, + MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "client_context": { @@ -204,6 +206,7 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { "run_command_parameters": { Type: schema.TypeList, Optional: true, + MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "comment": { @@ -298,6 +301,7 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { "step_functions_parameters": { Type: schema.TypeList, Optional: true, + MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "input": { From b80e4e3a4f009bb5c4257cfa3b1badd8459dc00a Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Sat, 13 Jul 2019 14:44:33 +0900 Subject: [PATCH 11/13] add cnil check to prevent potential panics --- aws/resource_aws_ssm_maintenance_window_task.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aws/resource_aws_ssm_maintenance_window_task.go b/aws/resource_aws_ssm_maintenance_window_task.go index d7de3511bab..f37450bf87d 100644 --- a/aws/resource_aws_ssm_maintenance_window_task.go +++ b/aws/resource_aws_ssm_maintenance_window_task.go @@ -383,16 +383,16 @@ func expandAwsSsmTaskInvocationParameters(config []interface{}) *ssm.Maintenance params := &ssm.MaintenanceWindowTaskInvocationParameters{} for _, v := range config { paramConfig := v.(map[string]interface{}) - if attr, ok := paramConfig["automation_parameters"]; ok && len(attr.([]interface{})) > 0 { + if attr, ok := paramConfig["automation_parameters"]; ok && len(attr.([]interface{})) > 0 && attr.([]interface{})[0] != nil { params.Automation = expandAwsSsmTaskInvocationAutomationParameters(attr.([]interface{})) } - if attr, ok := paramConfig["lambda_parameters"]; ok && len(attr.([]interface{})) > 0 { + if attr, ok := paramConfig["lambda_parameters"]; ok && len(attr.([]interface{})) > 0 && attr.([]interface{})[0] != nil { params.Lambda = expandAwsSsmTaskInvocationLambdaParameters(attr.([]interface{})) } - if attr, ok := paramConfig["run_command_parameters"]; ok && len(attr.([]interface{})) > 0 { + if attr, ok := paramConfig["run_command_parameters"]; ok && len(attr.([]interface{})) > 0 && attr.([]interface{})[0] != nil { params.RunCommand = expandAwsSsmTaskInvocationRunCommandParameters(attr.([]interface{})) } - if attr, ok := paramConfig["step_functions_parameters"]; ok && len(attr.([]interface{})) > 0 { + if attr, ok := paramConfig["step_functions_parameters"]; ok && len(attr.([]interface{})) > 0 && attr.([]interface{})[0] != nil { params.StepFunctions = expandAwsSsmTaskInvocationStepFunctionsParameters(attr.([]interface{})) } } From 458aba1ad2bdad8492052084b1009492ede1fea7 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Sun, 14 Jul 2019 16:58:57 +0900 Subject: [PATCH 12/13] fix parameter scheme type to TypeSet fix attribute name parameters -> parameter --- ...esource_aws_ssm_maintenance_window_task.go | 28 ++++++++++--------- ...ce_aws_ssm_maintenance_window_task_test.go | 12 ++++---- .../ssm_maintenance_window_task.html.markdown | 6 ++-- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/aws/resource_aws_ssm_maintenance_window_task.go b/aws/resource_aws_ssm_maintenance_window_task.go index f37450bf87d..34513f900e6 100644 --- a/aws/resource_aws_ssm_maintenance_window_task.go +++ b/aws/resource_aws_ssm_maintenance_window_task.go @@ -154,8 +154,8 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { Optional: true, ValidateFunc: validation.StringMatch(regexp.MustCompile("([$]LATEST|[$]DEFAULT|^[1-9][0-9]*$)"), "see https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_MaintenanceWindowAutomationParameters.html"), }, - "parameters": { - Type: schema.TypeList, + "parameter": { + Type: schema.TypeSet, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -163,6 +163,7 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { Type: schema.TypeString, Required: true, }, + "values": { Type: schema.TypeList, Required: true, @@ -267,8 +268,8 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { Optional: true, }, - "parameters": { - Type: schema.TypeList, + "parameter": { + Type: schema.TypeSet, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -276,6 +277,7 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource { Type: schema.TypeString, Required: true, }, + "values": { Type: schema.TypeList, Required: true, @@ -426,8 +428,8 @@ func expandAwsSsmTaskInvocationAutomationParameters(config []interface{}) *ssm.M if attr, ok := configParam["document_version"]; ok && len(attr.(string)) != 0 { params.DocumentVersion = aws.String(attr.(string)) } - if attr, ok := configParam["parameters"]; ok && len(attr.([]interface{})) > 0 { - params.Parameters = expandAwsSsmTaskInvocationCommonParameters(attr.([]interface{})) + if attr, ok := configParam["parameter"]; ok && len(attr.(*schema.Set).List()) > 0 { + params.Parameters = expandAwsSsmTaskInvocationCommonParameters(attr.(*schema.Set).List()) } return params @@ -440,7 +442,7 @@ func flattenAwsSsmTaskInvocationAutomationParameters(parameters *ssm.Maintenance result["document_version"] = aws.StringValue(parameters.DocumentVersion) } if parameters.Parameters != nil { - result["parameters"] = flattenAwsSsmTaskInvocationCommonParameters(parameters.Parameters) + result["parameter"] = flattenAwsSsmTaskInvocationCommonParameters(parameters.Parameters) } return []interface{}{result} @@ -497,8 +499,8 @@ func expandAwsSsmTaskInvocationRunCommandParameters(config []interface{}) *ssm.M if attr, ok := configParam["output_s3_key_prefix"]; ok && len(attr.(string)) != 0 { params.OutputS3KeyPrefix = aws.String(attr.(string)) } - if attr, ok := configParam["parameters"]; ok && len(attr.([]interface{})) > 0 { - params.Parameters = expandAwsSsmTaskInvocationCommonParameters(attr.([]interface{})) + if attr, ok := configParam["parameter"]; ok && len(attr.(*schema.Set).List()) > 0 { + params.Parameters = expandAwsSsmTaskInvocationCommonParameters(attr.(*schema.Set).List()) } if attr, ok := configParam["service_role_arn"]; ok && len(attr.(string)) != 0 { params.ServiceRoleArn = aws.String(attr.(string)) @@ -531,7 +533,7 @@ func flattenAwsSsmTaskInvocationRunCommandParameters(parameters *ssm.Maintenance result["output_s3_key_prefix"] = aws.StringValue(parameters.OutputS3KeyPrefix) } if parameters.Parameters != nil { - result["parameters"] = flattenAwsSsmTaskInvocationCommonParameters(parameters.Parameters) + result["parameter"] = flattenAwsSsmTaskInvocationCommonParameters(parameters.Parameters) } if parameters.ServiceRoleArn != nil { result["service_role_arn"] = aws.StringValue(parameters.ServiceRoleArn) @@ -614,7 +616,7 @@ func expandAwsSsmTaskInvocationCommonParameters(config []interface{}) map[string } func flattenAwsSsmTaskInvocationCommonParameters(parameters map[string][]*string) []interface{} { - result := make([]interface{}, 0, len(parameters)) + attributes := make([]interface{}, 0, len(parameters)) keys := make([]string, 0, len(parameters)) for k := range parameters { @@ -631,10 +633,10 @@ func flattenAwsSsmTaskInvocationCommonParameters(parameters map[string][]*string "name": key, "values": values, } - result = append(result, params) + attributes = append(attributes, params) } - return result + return attributes } func resourceAwsSsmMaintenanceWindowTaskCreate(d *schema.ResourceData, meta interface{}) error { diff --git a/aws/resource_aws_ssm_maintenance_window_task_test.go b/aws/resource_aws_ssm_maintenance_window_task_test.go index 0666ad621e1..c3532bc19f2 100644 --- a/aws/resource_aws_ssm_maintenance_window_task_test.go +++ b/aws/resource_aws_ssm_maintenance_window_task_test.go @@ -559,11 +559,11 @@ resource "aws_ssm_maintenance_window_task" "target" { task_invocation_parameters { automation_parameters { document_version = "%[2]s" - parameters { + parameter { name = "InstanceId" values = ["${aws_instance.foo.id}"] } - parameters { + parameter { name = "NoReboot" values = ["false"] } @@ -646,11 +646,11 @@ resource "aws_ssm_maintenance_window_task" "target" { task_invocation_parameters { automation_parameters { document_version = "%[2]s" - parameters { + parameter { name = "InstanceId" values = ["${aws_instance.foo.id}"] } - parameters { + parameter { name = "NoReboot" values = ["false"] } @@ -823,7 +823,7 @@ resource "aws_ssm_maintenance_window_task" "target" { document_hash_type = "Sha256" service_role_arn = "${aws_iam_role.ssm_role.arn}" timeout_seconds = %[3]d - parameters { + parameter { name = "commands" values = ["date"] } @@ -912,7 +912,7 @@ resource "aws_ssm_maintenance_window_task" "target" { timeout_seconds = %[3]d output_s3_bucket = "${aws_s3_bucket.foo.id}" output_s3_key_prefix = "foo" - parameters { + parameter { name = "commands" values = ["date"] } diff --git a/website/docs/r/ssm_maintenance_window_task.html.markdown b/website/docs/r/ssm_maintenance_window_task.html.markdown index e51e9e872ee..b5abe9e5c2d 100644 --- a/website/docs/r/ssm_maintenance_window_task.html.markdown +++ b/website/docs/r/ssm_maintenance_window_task.html.markdown @@ -88,7 +88,7 @@ The following arguments are supported: `automation_parameters` supports the following: * `document_version` - (Optional) The version of an Automation document to use during task execution. -* `parameters` - (Optional) The parameters for the RUN_COMMAND task execution. Documented below. +* `parameter` - (Optional) The parameters for the RUN_COMMAND task execution. Documented below. `lambda_parameters` supports the following: @@ -104,7 +104,7 @@ The following arguments are supported: * `notification_config` - (Optional) Configurations for sending notifications about command status changes on a per-instance basis. Documented below. * `output_s3_bucket` - (Optional) The name of the Amazon S3 bucket. * `output_s3_key_prefix` - (Optional) The Amazon S3 bucket subfolder. -* `parameters` - (Optional) The parameters for the RUN_COMMAND task execution. Documented below. +* `parameter` - (Optional) The parameters for the RUN_COMMAND task execution. Documented below. * `service_role_arn` - (Optional) The IAM service role to assume during task execution. * `timeout_seconds` - (Optional) If this time is reached and the command has not already started executing, it doesn't run. @@ -119,7 +119,7 @@ The following arguments are supported: * `notification_events` - (Optional) The different events for which you can receive notifications. * `notification_type` - (Optional) Command: Receive notification when the status of a command changes. Invocation: For commands sent to multiple instances, receive notification on a per-instance basis when the status of a command changes. -`parameters` supports the following: +`parameter` supports the following: * `name` - (Required) The parameter name. * `values` - (Required) The array of strings. From cdf96a7a42bf9585ee24377ad56f9d280f8044db Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Sun, 14 Jul 2019 18:19:21 +0900 Subject: [PATCH 13/13] split icommon settings and put in testAccAWSSSMMaintenanceWindowTaskConfigBase --- ...ce_aws_ssm_maintenance_window_task_test.go | 515 +++--------------- 1 file changed, 86 insertions(+), 429 deletions(-) diff --git a/aws/resource_aws_ssm_maintenance_window_task_test.go b/aws/resource_aws_ssm_maintenance_window_task_test.go index c3532bc19f2..1197f02a50e 100644 --- a/aws/resource_aws_ssm_maintenance_window_task_test.go +++ b/aws/resource_aws_ssm_maintenance_window_task_test.go @@ -156,7 +156,7 @@ func TestAccAWSSSMMaintenanceWindowTask_TaskInvocationLambdaParameters(t *testin func TestAccAWSSSMMaintenanceWindowTask_TaskInvocationRunCommandParameters(t *testing.T) { var task ssm.MaintenanceWindowTask resourceName := "aws_ssm_maintenance_window_task.target" - serviceRoleResourceName := "aws_iam_role.ssm_role" + serviceRoleResourceName := "aws_iam_role.test" s3BucketResourceName := "aws_s3_bucket.foo" name := acctest.RandString(10) @@ -312,66 +312,44 @@ func testAccAWSSSMMaintenanceWindowTaskImportStateIdFunc(resourceName string) re } } -func testAccAWSSSMMaintenanceWindowTaskBasicConfig(rName string) string { +func testAccAWSSSMMaintenanceWindowTaskConfigBase(rName string) string { return fmt.Sprintf(` -resource "aws_ssm_maintenance_window" "foo" { - name = "maintenance-window-%[1]s" - schedule = "cron(0 16 ? * TUE *)" - duration = 3 +resource "aws_ssm_maintenance_window" "test" { cutoff = 1 + duration = 3 + name = %[1]q + schedule = "cron(0 16 ? * TUE *)" } -resource "aws_ssm_maintenance_window_task" "target" { - window_id = "${aws_ssm_maintenance_window.foo.id}" - task_type = "RUN_COMMAND" - task_arn = "AWS-RunShellScript" - priority = 1 - service_role_arn = "${aws_iam_role.ssm_role.arn}" - max_concurrency = "2" - max_errors = "1" - - targets { - key = "InstanceIds" - values = ["${aws_instance.foo.id}"] - } - - task_parameters { - name = "commands" - values = ["pwd"] - } -} - -resource "aws_instance" "foo" { +resource "aws_instance" "test" { ami = "ami-4fccb37f" instance_type = "m1.small" } -resource "aws_iam_role" "ssm_role" { - name = "ssm-role-%[1]s" - +resource "aws_iam_role" "test" { + name = %[1]q assume_role_policy = <