diff --git a/aws/resource_aws_ssm_maintenance_window_target.go b/aws/resource_aws_ssm_maintenance_window_target.go index dfced2ee2c8..9a8b65e79e1 100644 --- a/aws/resource_aws_ssm_maintenance_window_target.go +++ b/aws/resource_aws_ssm_maintenance_window_target.go @@ -81,8 +81,14 @@ func resourceAwsSsmMaintenanceWindowTargetCreate(d *schema.ResourceData, meta in WindowId: aws.String(d.Get("window_id").(string)), ResourceType: aws.String(d.Get("resource_type").(string)), Targets: expandAwsSsmTargets(d.Get("targets").([]interface{})), - Name: aws.String(d.Get("name").(string)), - Description: aws.String(d.Get("description").(string)), + } + + 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("owner_information"); ok { @@ -154,6 +160,14 @@ func resourceAwsSsmMaintenanceWindowTargetUpdate(d *schema.ResourceData, meta in WindowTargetId: aws.String(d.Id()), } + if d.HasChange("name") { + params.Name = aws.String(d.Get("name").(string)) + } + + if d.HasChange("description") { + params.Description = aws.String(d.Get("description").(string)) + } + if d.HasChange("owner_information") { params.OwnerInformation = aws.String(d.Get("owner_information").(string)) } diff --git a/aws/resource_aws_ssm_maintenance_window_target_test.go b/aws/resource_aws_ssm_maintenance_window_target_test.go index d68d95d14c4..a7c0f84832d 100644 --- a/aws/resource_aws_ssm_maintenance_window_target_test.go +++ b/aws/resource_aws_ssm_maintenance_window_target_test.go @@ -44,6 +44,35 @@ func TestAccAWSSSMMaintenanceWindowTarget_basic(t *testing.T) { }) } +func TestAccAWSSSMMaintenanceWindowTarget_noNameOrDescription(t *testing.T) { + name := acctest.RandString(10) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSSSMMaintenanceWindowTargetDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSSSMMaintenanceWindowTargetNoNameOrDescriptionConfig(name), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSSMMaintenanceWindowTargetExists("aws_ssm_maintenance_window_target.target"), + resource.TestCheckResourceAttr("aws_ssm_maintenance_window_target.target", "targets.0.key", "tag:Name"), + resource.TestCheckResourceAttr("aws_ssm_maintenance_window_target.target", "targets.0.values.#", "1"), + resource.TestCheckResourceAttr("aws_ssm_maintenance_window_target.target", "targets.0.values.0", "acceptance_test"), + resource.TestCheckResourceAttr("aws_ssm_maintenance_window_target.target", "targets.1.key", "tag:Name2"), + resource.TestCheckResourceAttr("aws_ssm_maintenance_window_target.target", "targets.1.values.#", "2"), + resource.TestCheckResourceAttr("aws_ssm_maintenance_window_target.target", "targets.1.values.0", "acceptance_test"), + resource.TestCheckResourceAttr("aws_ssm_maintenance_window_target.target", "targets.1.values.1", "acceptance_test2"), + ), + }, + { + ResourceName: "aws_ssm_maintenance_window.foo", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAWSSSMMaintenanceWindowTarget_validation(t *testing.T) { name := acctest.RandString(10) resource.ParallelTest(t, resource.TestCase{ @@ -208,6 +237,32 @@ resource "aws_ssm_maintenance_window_target" "target" { `, rName) } +func testAccAWSSSMMaintenanceWindowTargetNoNameOrDescriptionConfig(rName string) string { + return fmt.Sprintf(` +resource "aws_ssm_maintenance_window" "foo" { + name = "maintenance-window-%s" + schedule = "cron(0 16 ? * TUE *)" + duration = 3 + cutoff = 1 +} + +resource "aws_ssm_maintenance_window_target" "target" { + window_id = "${aws_ssm_maintenance_window.foo.id}" + resource_type = "INSTANCE" + + targets { + key = "tag:Name" + values = ["acceptance_test"] + } + + targets { + key = "tag:Name2" + values = ["acceptance_test", "acceptance_test2"] + } +} +`, rName) +} + func testAccAWSSSMMaintenanceWindowTargetBasicConfigUpdated(rName string) string { return fmt.Sprintf(` resource "aws_ssm_maintenance_window" "foo" {