Skip to content

Instantly share code, notes, and snippets.

@tom-butler
Created August 2, 2017 00:30
Show Gist options
  • Save tom-butler/819f33fa39b914b6c462cab9e5e17322 to your computer and use it in GitHub Desktop.
Save tom-butler/819f33fa39b914b6c462cab9e5e17322 to your computer and use it in GitHub Desktop.
ASG Time Delay
# Get the time in UTC 15 minutes from now
data "external" "date" {
# use date to get the time 15 mins from now
program = ["bash", "${path.module}/date.sh"]
}
# Wait 15 minutes before scaling instances.
resource "aws_autoscaling_schedule" "delaystart" {
scheduled_action_name = "delaystart"
min_size = 2
max_size = 2
desired_capacity = 2
start_time = "${lookup(data.external.date.result,"future")}"
autoscaling_group_name = "${aws_autoscaling_group.asg.name}"
}
# Put this in a seperate file called date.sh
# Quit if anything fails
set -e
# Get the UTC Time in 15 minutes
FUTURE=`date -u -v +15M +"%Y-%m-%dT%H:%M:%SZ"`
# Parse it to JSON
jq -n --arg future "$FUTURE" '{"future":$future}'
@tom-butler
Copy link
Author

requires jq to be installed on the server running terraform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment