@@ -13,50 +13,12 @@ data "aws_ami" "ubuntu" {
13
13
owners = [" 099720109477" ] # Canonical
14
14
}
15
15
16
- resource "aws_vpc" "test" {
17
- cidr_block = " 10.0.0.0/16"
18
- enable_dns_hostnames = true
19
- enable_dns_support = true
20
- }
21
-
22
- resource "aws_internet_gateway" "test" {
23
- vpc_id = aws_vpc. test . id
24
-
25
- tags = {
26
- Name = " scheduler-exclusion-igw-${ random_pet . suffix . id } "
27
- }
28
- }
29
-
30
- resource "aws_subnet" "public" {
31
- vpc_id = aws_vpc. test . id
32
- cidr_block = " 10.0.1.0/24"
33
- availability_zone = data. aws_availability_zones . available . names [0 ]
34
- map_public_ip_on_launch = true
35
- }
36
-
37
- resource "aws_route_table" "public" {
38
- vpc_id = aws_vpc. test . id
39
-
40
- route {
41
- cidr_block = " 0.0.0.0/0"
42
- gateway_id = aws_internet_gateway. test . id
43
- }
44
- }
45
-
46
- resource "aws_route_table_association" "public" {
47
- subnet_id = aws_subnet. public . id
48
- route_table_id = aws_route_table. public . id
49
- }
50
-
51
- data "aws_availability_zones" "available" {
52
- state = " available"
53
- }
54
16
55
17
resource "aws_instance" "scheduled" {
56
18
count = 2
57
19
ami = data. aws_ami . ubuntu . id
58
20
instance_type = " t2.micro"
59
- subnet_id = aws_subnet. public . id
21
+ subnet_id = aws_subnet. test . id
60
22
61
23
tags = {
62
24
tostop = " true-${ random_pet . suffix . id } "
@@ -67,7 +29,7 @@ resource "aws_instance" "scheduled" {
67
29
resource "aws_instance" "not_scheduled" {
68
30
ami = data. aws_ami . ubuntu . id
69
31
instance_type = " t2.micro"
70
- subnet_id = aws_subnet. public . id
32
+ subnet_id = aws_subnet. test . id
71
33
72
34
tags = {
73
35
tostop = " false"
@@ -85,6 +47,16 @@ module "ec2_stop_with_exclusions" {
85
47
rds_schedule = false
86
48
autoscaling_schedule = false
87
49
cloudwatch_alarm_schedule = false
50
+ scheduler_excluded_dates = [
51
+ " 01-01" , # New Year's Day
52
+ " 12-25" , # Christmas Day
53
+ " 12-24" , # Christmas Eve
54
+ " 07-04" , # Independence Day (US)
55
+ " 11-24" , # Thanksgiving (example date)
56
+ " 05-01" , # Labor Day
57
+ " 12-31" , # New Year's Eve
58
+ formatdate (" MM-DD" , timestamp ()) # Current date (for tests purposes)
59
+ ]
88
60
89
61
scheduler_tag = {
90
62
key = " tostop"
@@ -103,19 +75,18 @@ module "ec2_start_with_exclusions" {
103
75
autoscaling_schedule = false
104
76
cloudwatch_alarm_schedule = false
105
77
106
- scheduler_excluded_dates = [
107
- " 01-01" , # New Year's Day
108
- " 12-25" , # Christmas Day
109
- " 12-24" , # Christmas Eve
110
- " 07-04" , # Independence Day (US)
111
- " 11-24" , # Thanksgiving (example date)
112
- " 05-01" , # Labor Day
113
- " 12-31" , # New Year's Eve
114
- formatdate (" MM-DD" , timestamp ()) # Current date (for tests purposes)
115
- ]
116
-
117
78
scheduler_tag = {
118
79
key = " tostop"
119
80
value = " true-${ random_pet . suffix . id } "
120
81
}
121
82
}
83
+
84
+ module "test_execution" {
85
+ count = var. test_mode ? 1 : 0
86
+ source = " ./test-execution"
87
+
88
+ lambda_stop_name = module. ec2_stop_with_exclusions . scheduler_lambda_name
89
+ instance_1_to_scheduled_id = aws_instance. scheduled [0 ]. id
90
+ instance_2_to_scheduled_id = aws_instance. scheduled [1 ]. id
91
+ instance_not_to_scheduled_id = aws_instance. not_scheduled . id
92
+ }
0 commit comments