Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.
Open
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
24 changes: 24 additions & 0 deletions nodegroup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ Type: `bool`

Default: `true`

### create\_schedule

Description: Schedule shutdown and startup of ASG instances

Type: `bool`

Default: `false`

### detailed\_monitoring

Description: Enable EC2 detailed monitoring
Expand Down Expand Up @@ -211,6 +219,22 @@ Type: `number`

Default: `100`

### scheduled\_shutdown

Description: Scheduled shutdown of ASG instances in UTC

Type: `string`

Default: `"00 09 * * MON-FRI"`

### scheduled\_startup

Description: Scheduled startup of ASG instances in UTC

Type: `string`

Default: `"00 21 * * SUN-THU"`

### spot\_allocation\_strategy

Description: How to allocate capacity across the Spot pools
Expand Down
21 changes: 21 additions & 0 deletions nodegroup/asg-schedule.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Stop all instances each weekday at 6pm
resource "aws_autoscaling_schedule" "node_shutdown" {
count = var.create_schedule ? length(var.vpc_subnets) : 0
scheduled_action_name = "eks-${var.cluster_name}-nodes-shutdown-${var.nodegroup_name}-${count.index}"
min_size = 0
max_size = 0
desired_capacity = 0
recurrence = var.scheduled_shutdown
autoscaling_group_name = aws_autoscaling_group.node[count.index].name
}

# Startup 1 instance each weekday at 9am
resource "aws_autoscaling_schedule" "node_startup" {
count = var.create_schedule ? length(var.vpc_subnets) : 0
scheduled_action_name = "eks-${var.cluster_name}-nodes-startup-${var.nodegroup_name}-${count.index}"
min_size = var.asg_min_size
max_size = var.asg_max_size
desired_capacity = var.asg_desired_capacity
recurrence = var.scheduled_startup
autoscaling_group_name = aws_autoscaling_group.node[count.index].name
}
18 changes: 18 additions & 0 deletions nodegroup/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,24 @@ variable "proxy_bypass" {
default = "169.254.169.254,.eks.amazonaws.com"
}

variable "create_schedule" {
type = bool
description = "Schedule shutdown and startup of ASG instances"
default = false
}

variable "scheduled_shutdown" {
description = "Scheduled shutdown of ASG instances in UTC"
type = string
default = "00 09 * * MON-FRI" # 7pm Mon-Fri AEST
}

variable "scheduled_startup" {
description = "Scheduled startup of ASG instances in UTC"
type = string
default = "00 21 * * SUN-THU" # 7am Mon-Fri AEST
}

variable "tags" {
description = "Tags to apply to created resources"
type = map(string)
Expand Down