Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/ssm_maintenance_window_target: name and description are optional #9165

Merged
merged 1 commit into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions aws/resource_aws_ssm_maintenance_window_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
Expand Down
55 changes: 55 additions & 0 deletions aws/resource_aws_ssm_maintenance_window_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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" {
Expand Down