-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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/aws_ssm_maintenance_window: Add end_date, schedule_timezone, and start_date attributes #7040
Merged
Merged
resource/aws_ssm_maintenance_window: Add end_date, schedule_timezone, and start_date attributes #7040
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,21 @@ func resourceAwsSsmMaintenanceWindow() *schema.Resource { | |
Optional: true, | ||
Default: true, | ||
}, | ||
|
||
"end_date": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"schedule_timezone": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"start_date": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you want some validation on these checking the date format? |
||
}, | ||
}, | ||
} | ||
} | ||
|
@@ -59,59 +74,83 @@ func resourceAwsSsmMaintenanceWindowCreate(d *schema.ResourceData, meta interfac | |
ssmconn := meta.(*AWSClient).ssmconn | ||
|
||
params := &ssm.CreateMaintenanceWindowInput{ | ||
AllowUnassociatedTargets: aws.Bool(d.Get("allow_unassociated_targets").(bool)), | ||
Cutoff: aws.Int64(int64(d.Get("cutoff").(int))), | ||
Duration: aws.Int64(int64(d.Get("duration").(int))), | ||
Name: aws.String(d.Get("name").(string)), | ||
Schedule: aws.String(d.Get("schedule").(string)), | ||
Duration: aws.Int64(int64(d.Get("duration").(int))), | ||
Cutoff: aws.Int64(int64(d.Get("cutoff").(int))), | ||
AllowUnassociatedTargets: aws.Bool(d.Get("allow_unassociated_targets").(bool)), | ||
} | ||
|
||
if v, ok := d.GetOk("end_date"); ok { | ||
params.EndDate = aws.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("schedule_timezone"); ok { | ||
params.ScheduleTimezone = aws.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("start_date"); ok { | ||
params.StartDate = aws.String(v.(string)) | ||
} | ||
|
||
resp, err := ssmconn.CreateMaintenanceWindow(params) | ||
if err != nil { | ||
return err | ||
return fmt.Errorf("error creating SSM Maintenance Window: %s", err) | ||
} | ||
|
||
d.SetId(*resp.WindowId) | ||
return resourceAwsSsmMaintenanceWindowUpdate(d, meta) | ||
|
||
if !d.Get("enabled").(bool) { | ||
input := &ssm.UpdateMaintenanceWindowInput{ | ||
Enabled: aws.Bool(false), | ||
WindowId: aws.String(d.Id()), | ||
} | ||
|
||
_, err := ssmconn.UpdateMaintenanceWindow(input) | ||
if err != nil { | ||
return fmt.Errorf("error disabling SSM Maintenance Window (%s): %s", d.Id(), err) | ||
} | ||
} | ||
|
||
return resourceAwsSsmMaintenanceWindowRead(d, meta) | ||
} | ||
|
||
func resourceAwsSsmMaintenanceWindowUpdate(d *schema.ResourceData, meta interface{}) error { | ||
ssmconn := meta.(*AWSClient).ssmconn | ||
|
||
// Replace must be set otherwise its not possible to remove optional attributes, e.g. | ||
// ValidationException: 1 validation error detected: Value '' at 'startDate' failed to satisfy constraint: Member must have length greater than or equal to 1 | ||
params := &ssm.UpdateMaintenanceWindowInput{ | ||
WindowId: aws.String(d.Id()), | ||
} | ||
|
||
if d.HasChange("name") { | ||
params.Name = aws.String(d.Get("name").(string)) | ||
} | ||
|
||
if d.HasChange("schedule") { | ||
params.Schedule = aws.String(d.Get("schedule").(string)) | ||
AllowUnassociatedTargets: aws.Bool(d.Get("allow_unassociated_targets").(bool)), | ||
Cutoff: aws.Int64(int64(d.Get("cutoff").(int))), | ||
Duration: aws.Int64(int64(d.Get("duration").(int))), | ||
Enabled: aws.Bool(d.Get("enabled").(bool)), | ||
Name: aws.String(d.Get("name").(string)), | ||
Replace: aws.Bool(true), | ||
Schedule: aws.String(d.Get("schedule").(string)), | ||
WindowId: aws.String(d.Id()), | ||
} | ||
|
||
if d.HasChange("duration") { | ||
params.Duration = aws.Int64(int64(d.Get("duration").(int))) | ||
if v, ok := d.GetOk("end_date"); ok { | ||
params.EndDate = aws.String(v.(string)) | ||
} | ||
|
||
if d.HasChange("cutoff") { | ||
params.Cutoff = aws.Int64(int64(d.Get("cutoff").(int))) | ||
if v, ok := d.GetOk("schedule_timezone"); ok { | ||
params.ScheduleTimezone = aws.String(v.(string)) | ||
} | ||
|
||
if d.HasChange("allow_unassociated_targets") { | ||
params.AllowUnassociatedTargets = aws.Bool(d.Get("allow_unassociated_targets").(bool)) | ||
if v, ok := d.GetOk("start_date"); ok { | ||
params.StartDate = aws.String(v.(string)) | ||
} | ||
|
||
params.Enabled = aws.Bool(d.Get("enabled").(bool)) | ||
|
||
_, err := ssmconn.UpdateMaintenanceWindow(params) | ||
if err != nil { | ||
if isAWSErr(err, ssm.ErrCodeDoesNotExistException, "") { | ||
log.Printf("[WARN] Maintenance Window %s not found, removing from state", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
return err | ||
return fmt.Errorf("error updating SSM Maintenance Window (%s): %s", d.Id(), err) | ||
} | ||
|
||
return resourceAwsSsmMaintenanceWindowRead(d, meta) | ||
|
@@ -131,15 +170,18 @@ func resourceAwsSsmMaintenanceWindowRead(d *schema.ResourceData, meta interface{ | |
d.SetId("") | ||
return nil | ||
} | ||
return err | ||
return fmt.Errorf("error reading SSM Maintenance Window (%s): %s", d.Id(), err) | ||
} | ||
|
||
d.Set("name", resp.Name) | ||
d.Set("allow_unassociated_targets", resp.AllowUnassociatedTargets) | ||
d.Set("cutoff", resp.Cutoff) | ||
d.Set("duration", resp.Duration) | ||
d.Set("enabled", resp.Enabled) | ||
d.Set("allow_unassociated_targets", resp.AllowUnassociatedTargets) | ||
d.Set("end_date", resp.EndDate) | ||
d.Set("name", resp.Name) | ||
d.Set("schedule_timezone", resp.ScheduleTimezone) | ||
d.Set("schedule", resp.Schedule) | ||
d.Set("start_date", resp.StartDate) | ||
|
||
return nil | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you want some validation on these checking the date format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API parameter says it accepts ISO-8601 extended format, which has some slight differences with RFC3339, that would match our normal date validators. The
time.RFC3339
format built into Go's standard library doesn't work with all ISO-8601 formats unfortunately.It looks like we have ISO-8601 needs in other places where it is inconsistently handled, so I have created a technical debt issue to address all these at once (I would think preferably upstream in the provider SDK), but even a common solution in the provider itself is a good start: #7045