Skip to content

Commit

Permalink
resource/aws_ssm_maintenance_window: Add description argument (hash…
Browse files Browse the repository at this point in the history
…icorp#11478)

Output from acceptance testing:

```
--- PASS: TestAccAWSSSMMaintenanceWindow_disappears (12.72s)
--- PASS: TestAccAWSSSMMaintenanceWindow_basic (18.22s)
--- PASS: TestAccAWSSSMMaintenanceWindow_multipleUpdates (28.21s)
--- PASS: TestAccAWSSSMMaintenanceWindow_Schedule (29.34s)
--- PASS: TestAccAWSSSMMaintenanceWindow_description (31.62s)
--- PASS: TestAccAWSSSMMaintenanceWindow_Duration (31.81s)
--- PASS: TestAccAWSSSMMaintenanceWindow_Cutoff (34.06s)
--- PASS: TestAccAWSSSMMaintenanceWindow_Enabled (37.01s)
--- PASS: TestAccAWSSSMMaintenanceWindow_StartDate (39.18s)
--- PASS: TestAccAWSSSMMaintenanceWindow_ScheduleTimezone (39.59s)
--- PASS: TestAccAWSSSMMaintenanceWindow_EndDate (40.98s)
--- PASS: TestAccAWSSSMMaintenanceWindow_tags (43.23s)
```
  • Loading branch information
DrFaust92 authored and bflad committed Jan 24, 2020
1 parent 51b9329 commit dbd17a6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
13 changes: 13 additions & 0 deletions aws/resource_aws_ssm_maintenance_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func resourceAwsSsmMaintenanceWindow() *schema.Resource {
},

"tags": tagsSchema(),
"description": {
Type: schema.TypeString,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -100,6 +104,10 @@ func resourceAwsSsmMaintenanceWindowCreate(d *schema.ResourceData, meta interfac
params.StartDate = aws.String(v.(string))
}

if v, ok := d.GetOk("description"); ok {
params.Description = aws.String(v.(string))
}

resp, err := ssmconn.CreateMaintenanceWindow(params)
if err != nil {
return fmt.Errorf("error creating SSM Maintenance Window: %s", err)
Expand Down Expand Up @@ -150,6 +158,10 @@ func resourceAwsSsmMaintenanceWindowUpdate(d *schema.ResourceData, meta interfac
params.StartDate = aws.String(v.(string))
}

if v, ok := d.GetOk("description"); ok {
params.Description = aws.String(v.(string))
}

_, err := ssmconn.UpdateMaintenanceWindow(params)
if err != nil {
if isAWSErr(err, ssm.ErrCodeDoesNotExistException, "") {
Expand Down Expand Up @@ -197,6 +209,7 @@ func resourceAwsSsmMaintenanceWindowRead(d *schema.ResourceData, meta interface{
d.Set("schedule_timezone", resp.ScheduleTimezone)
d.Set("schedule", resp.Schedule)
d.Set("start_date", resp.StartDate)
d.Set("description", resp.Description)

tags, err := keyvaluetags.SsmListTags(ssmconn, d.Id(), ssm.ResourceTypeForTaggingMaintenanceWindow)

Expand Down
47 changes: 47 additions & 0 deletions aws/resource_aws_ssm_maintenance_window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,41 @@ func TestAccAWSSSMMaintenanceWindow_basic(t *testing.T) {
})
}

func TestAccAWSSSMMaintenanceWindow_description(t *testing.T) {
var winId ssm.MaintenanceWindowIdentity
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_ssm_maintenance_window.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSSMMaintenanceWindowDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSSMMaintenanceWindowConfigDescription(rName, "foo"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMMaintenanceWindowExists(resourceName, &winId),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "description", "foo"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAWSSSMMaintenanceWindowConfigDescription(rName, "bar"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMMaintenanceWindowExists(resourceName, &winId),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "description", "bar"),
),
},
},
})
}

func TestAccAWSSSMMaintenanceWindow_tags(t *testing.T) {
var winId ssm.MaintenanceWindowIdentity
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -496,6 +531,18 @@ resource "aws_ssm_maintenance_window" "test" {
`, rName)
}

func testAccAWSSSMMaintenanceWindowConfigDescription(rName, desc string) string {
return fmt.Sprintf(`
resource "aws_ssm_maintenance_window" "test" {
cutoff = 1
duration = 3
name = %[1]q
description = %[2]q
schedule = "cron(0 16 ? * TUE *)"
}
`, rName, desc)
}

func testAccAWSSSMMaintenanceWindowConfigTags1(rName, tagKey1, tagValue1 string) string {
return fmt.Sprintf(`
resource "aws_ssm_maintenance_window" "test" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/ssm_maintenance_window.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The following arguments are supported:
* `schedule` - (Required) The schedule of the Maintenance Window in the form of a [cron](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-maintenance-cron.html) or rate expression.
* `cutoff` - (Required) The number of hours before the end of the Maintenance Window that Systems Manager stops scheduling new tasks for execution.
* `duration` - (Required) The duration of the Maintenance Window in hours.
* `description` - (Optional) A description for the maintenance window.
* `allow_unassociated_targets` - (Optional) Whether targets must be registered with the Maintenance Window before tasks can be defined for those targets.
* `enabled` - (Optional) Whether the maintenance window is enabled. Default: `true`.
* `end_date` - (Optional) Timestamp in [ISO-8601 extended format](https://www.iso.org/iso-8601-date-and-time-format.html) when to no longer run the maintenance window.
Expand Down

0 comments on commit dbd17a6

Please sign in to comment.