Skip to content

Commit 98fb546

Browse files
committed
feat(examples): add timezone scheduler example with Lambda functions
Introduced a new example for scheduling AWS Lambda functions to stop and start resources based on specified timezones.
1 parent 8eb3ff2 commit 98fb546

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

examples/timezone-scheduler/main.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Deploy two lambda for testing with awspec
2+
resource "random_pet" "suffix" {}
3+
4+
module "aws-stop-friday" {
5+
source = "../.."
6+
name = "stop-aws-${random_pet.suffix.id}"
7+
schedule_expression = "cron(0 23 ? * FRI *)"
8+
schedule_expression_timezone = "Europe/Paris"
9+
schedule_action = "stop"
10+
autoscaling_schedule = "true"
11+
ec2_schedule = "true"
12+
rds_schedule = "true"
13+
14+
scheduler_tag = {
15+
key = "tostop"
16+
value = "true-${random_pet.suffix.id}"
17+
}
18+
}
19+
20+
module "aws-start-monday" {
21+
source = "../.."
22+
name = "start-aws-${random_pet.suffix.id}"
23+
schedule_expression = "cron(0 07 ? * MON *)"
24+
schedule_expression_timezone = "Europe/Berlin"
25+
schedule_action = "start"
26+
autoscaling_schedule = "true"
27+
ec2_schedule = "true"
28+
rds_schedule = "true"
29+
30+
scheduler_tag = {
31+
key = "tostop"
32+
value = "true-${random_pet.suffix.id}"
33+
}
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
run "create_test_infrastructure" {
2+
command = apply
3+
4+
assert {
5+
condition = module.aws-stop-friday.scheduler_lambda_name == "stop-aws-${random_pet.suffix.id}"
6+
error_message = "Invalid Stop lambda name"
7+
}
8+
9+
assert {
10+
condition = module.aws-start-monday.scheduler_lambda_name == "start-aws-${random_pet.suffix.id}"
11+
error_message = "Invalid Start lambda name"
12+
}
13+
14+
assert {
15+
condition = module.aws-stop-friday.scheduler_expression == "cron(0 23 ? * FRI *)"
16+
error_message = "Invalid scheduler expression"
17+
}
18+
19+
assert {
20+
condition = module.aws-start-monday.scheduler_expression == "cron(0 07 ? * MON *)"
21+
error_message = "Invalid scheduler expression"
22+
}
23+
24+
assert {
25+
condition = module.aws-stop-friday.scheduler_timezone == "Europe/Paris"
26+
error_message = "Invalid scheduler timezone"
27+
}
28+
29+
assert {
30+
condition = module.aws-start-monday.scheduler_timezone == "Europe/Berlin"
31+
error_message = "Invalid scheduler timezone"
32+
}
33+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.94.1"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)