-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
113 lines (96 loc) · 2.39 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
provider "aws" {
region = "${var.aws_region}"
}
module "network" {
source = "./modules/network"
tags = {
Name = "demo-default"
}
}
module "ecs" {
source = "./modules/ecs"
vpc_id = "${module.network.vpc_id}"
cluster_name = "ecsdemo"
tags = {
Name = "demo-default"
}
}
module "ecs_spot" {
source = "./modules/ecs-spot"
subnets = "${module.network.subnets}"
security_groups = ["${module.ecs.security_group}"]
instance_profile = "${module.ecs.ecs_role}"
cluster_name = "ecsdemo"
instance_size = "m5.large"
asg_desired = "2"
tags = [{
key = "Name"
value = "demo-default"
propagate_at_launch = true
}]
}
module "lambda-permissions" {
source = "./modules/lambda-permissions"
}
module "lambda-ecs" {
source = "./modules/lambda"
source_file_path = "./lambda-handler/bin/ecs-linux"
output_path = "./ecs.zip"
description = "ECS state function"
function_name = "ecs"
lambda_handler = "ecs-linux"
role_arn = "${module.lambda-permissions.role_arn}"
environment_variables = {
"ASG_SPOT" = "${module.ecs_spot.asg_spot_name}"
"ASG_ONDEMAND" = "${module.ecs_spot.asg_name}"
}
tags = {
"key" = "val"
}
event_description = "Cloudwatch event for ECS cluster instance change"
event_pattern = <<PATTERN
{
"detail-type": [
"ECS Container Instance State Change"
],
"detail": {
"status": ["DRAINING"],
"clusterArn": [
"${module.ecs.ecs_cluster_arn}"
]
}
}
PATTERN
}
module "lambda-scale" {
source = "./modules/lambda"
source_file_path = "./lambda-handler/bin/scale-linux"
output_path = "./scale.zip"
description = ""
function_name = "scale"
lambda_handler = "scale-linux"
description = "scale function"
role_arn = "${module.lambda-permissions.role_arn}"
environment_variables = {
"ASG_SPOT" = "${module.ecs_spot.asg_spot_name}"
"ASG_ONDEMAND" = "${module.ecs_spot.asg_name}"
}
tags = {
"key" = "val"
}
event_description = "Cloudwatch event for on demand ASG"
event_pattern = <<PATTERN
{
"detail-type": [
"EC2 Instance Launch Successful",
"EC2 Instance Launch Unsuccessful",
"EC2 Instance Terminate Successful"
],
"detail": {
"AutoScalingGroupName": [
"${module.ecs_spot.asg_spot_name}"
]
}
}
PATTERN
}