Created
August 2, 2017 00:30
-
-
Save tom-butler/819f33fa39b914b6c462cab9e5e17322 to your computer and use it in GitHub Desktop.
ASG Time Delay
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
# 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}" | |
} | |
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
# 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}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
requires jq to be installed on the server running terraform.