Skip to content

Commit

Permalink
resource/aws_ssm_maintenance_window: Add schedule_offset argument (#1…
Browse files Browse the repository at this point in the history
…6569)

* add schedule_offset parameter to aws_ssm_maintenance_window

* add aws_ssm_maintenance_window schedule_offset to docs

* change schedule_offset to integer in test

Co-authored-by: Brian Flad <[email protected]>

Co-authored-by: Matt Newcombe <[email protected]>
Co-authored-by: Brian Flad <[email protected]>
  • Loading branch information
3 people authored Dec 7, 2020
1 parent d4b5c28 commit e11a809
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
16 changes: 16 additions & 0 deletions aws/resource_aws_ssm_maintenance_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

Expand Down Expand Up @@ -63,6 +64,12 @@ func resourceAwsSsmMaintenanceWindow() *schema.Resource {
Optional: true,
},

"schedule_offset": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(1, 6),
},

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

if v, ok := d.GetOk("schedule_offset"); ok {
params.ScheduleOffset = aws.Int64(int64(v.(int)))
}

if v, ok := d.GetOk("start_date"); ok {
params.StartDate = aws.String(v.(string))
}
Expand Down Expand Up @@ -154,6 +165,10 @@ func resourceAwsSsmMaintenanceWindowUpdate(d *schema.ResourceData, meta interfac
params.ScheduleTimezone = aws.String(v.(string))
}

if v, ok := d.GetOk("schedule_offset"); ok {
params.ScheduleOffset = aws.Int64(int64(v.(int)))
}

if v, ok := d.GetOk("start_date"); ok {
params.StartDate = aws.String(v.(string))
}
Expand Down Expand Up @@ -208,6 +223,7 @@ func resourceAwsSsmMaintenanceWindowRead(d *schema.ResourceData, meta interface{
d.Set("end_date", resp.EndDate)
d.Set("name", resp.Name)
d.Set("schedule_timezone", resp.ScheduleTimezone)
d.Set("schedule_offset", resp.ScheduleOffset)
d.Set("schedule", resp.Schedule)
d.Set("start_date", resp.StartDate)
d.Set("description", resp.Description)
Expand Down
46 changes: 46 additions & 0 deletions aws/resource_aws_ssm_maintenance_window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func TestAccAWSSSMMaintenanceWindow_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "end_date", ""),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "schedule_timezone", ""),
resource.TestCheckResourceAttr(resourceName, "schedule_offset", "0"),
resource.TestCheckResourceAttr(resourceName, "schedule", "cron(0 16 ? * TUE *)"),
resource.TestCheckResourceAttr(resourceName, "start_date", ""),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
Expand Down Expand Up @@ -462,6 +463,39 @@ func TestAccAWSSSMMaintenanceWindow_ScheduleTimezone(t *testing.T) {
})
}

func TestAccAWSSSMMaintenanceWindow_ScheduleOffset(t *testing.T) {
var maintenanceWindow1, maintenanceWindow2 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: testAccAWSSSMMaintenanceWindowConfigScheduleOffset(rName, 2),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMMaintenanceWindowExists(resourceName, &maintenanceWindow1),
resource.TestCheckResourceAttr(resourceName, "schedule_offset", "2"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAWSSSMMaintenanceWindowConfigScheduleOffset(rName, 5),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMMaintenanceWindowExists(resourceName, &maintenanceWindow2),
resource.TestCheckResourceAttr(resourceName, "schedule_offset", "5"),
),
},
},
})
}

func TestAccAWSSSMMaintenanceWindow_StartDate(t *testing.T) {
var maintenanceWindow1, maintenanceWindow2, maintenanceWindow3 ssm.MaintenanceWindowIdentity
startDate1 := time.Now().UTC().Add(1 * time.Hour).Format(time.RFC3339)
Expand Down Expand Up @@ -719,6 +753,18 @@ resource "aws_ssm_maintenance_window" "test" {
`, rName, scheduleTimezone)
}

func testAccAWSSSMMaintenanceWindowConfigScheduleOffset(rName string, scheduleOffset int) string {
return fmt.Sprintf(`
resource "aws_ssm_maintenance_window" "test" {
cutoff = 1
duration = 3
name = %q
schedule = "cron(0 16 ? * TUE *)"
schedule_offset = %d
}
`, rName, scheduleOffset)
}

func testAccAWSSSMMaintenanceWindowConfigStartDate(rName, startDate 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 @@ -34,6 +34,7 @@ The following arguments are supported:
* `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.
* `schedule_timezone` - (Optional) Timezone for schedule in [Internet Assigned Numbers Authority (IANA) Time Zone Database format](https://www.iana.org/time-zones). For example: `America/Los_Angeles`, `etc/UTC`, or `Asia/Seoul`.
* `schedule_offset` - (Optional) The number of days to wait after the date and time specified by a CRON expression before running the maintenance window.
* `start_date` - (Optional) Timestamp in [ISO-8601 extended format](https://www.iso.org/iso-8601-date-and-time-format.html) when to begin the maintenance window.
* `tags` - (Optional) A map of tags to assign to the resource.

Expand Down

0 comments on commit e11a809

Please sign in to comment.