hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.8k stars 9.15k forks source link

[New Resource]: EC2 Scheduled events #27570

Open jeroen-nijssen opened 1 year ago

jeroen-nijssen commented 1 year ago

Description

AWS can schedule events for your instances, such as a reboot, stop/start, or retirement. These events do not occur frequently. If one of your instances will be affected by a scheduled event, AWS sends an email to the email address that's associated with your AWS account prior to the scheduled event. The email provides details about the event, including the start and end date. Depending on the event, you might be able to take action to control the timing of the event

Scheduled events are managed by AWS; you cannot schedule events for your instances. You can view the events scheduled by AWS, customize scheduled event notifications to include or remove tags from the email notification, and perform actions when an instance is scheduled to reboot, retire, or stop.

Requested Resource(s) and/or Data Source(s)

aws_ec2_event_window data.aws_ec2_event_window

aws_ec2_associate_event_window aws_ec2_event_notification_attributes

Potential Terraform Configuration

resource "aws_ec2_event_window" "default" {
  name = "some event"
  time-range {
    StartWeekDay = "monday"
    StartHour    = 10
    EndWeekDay   = "monday"
    EndHour      = 11

    schedule-expression = "* 0-4,20-23 * * 1,5"
  }

  tags {
    name = "some event"
  }
}

data "aws_ec2_event_window" "default" {
  name = "some event"
}

resource "aws_ec2_associate_event_window" "server1" {
  event_arn = aws_ec2_event_window.default.arn
  targets {
    key    = "tag:${var.patch_tag}"
    values = ["Linux"]
  }
}

resource "aws_ec2_event_notification_attributes" "all" {
  IncludeAllTagsOfInstance = true
  # -- OR --
  InstanceTagKeys = ["name", "owner"]
}

References

Detailed documentation from AWS: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/monitoring-instances-status-check_sched.html

CDK Documentation: https://pkg.go.dev/github.com/aws/aws-sdk-go@v1.44.127/service/ec2/ec2iface search on "EventWindow"

Would you like to implement a fix?

No

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

github-actions[bot] commented 27 minutes ago

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!