forked from wardviaene/terraform-course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
myapp.tf
66 lines (55 loc) · 1.68 KB
/
myapp.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
# app
data "template_file" "myapp-task-definition-template" {
template = file("templates/app.json.tpl")
vars = {
REPOSITORY_URL = replace(aws_ecr_repository.myapp.repository_url, "https://", "")
APP_VERSION = var.MYAPP_VERSION
}
}
resource "aws_ecs_task_definition" "myapp-task-definition" {
family = "myapp"
container_definitions = data.template_file.myapp-task-definition-template.rendered
}
resource "aws_ecs_service" "myapp-service" {
count = var.MYAPP_SERVICE_ENABLE
name = "myapp"
cluster = aws_ecs_cluster.example-cluster.id
task_definition = aws_ecs_task_definition.myapp-task-definition.arn
desired_count = 1
iam_role = aws_iam_role.ecs-service-role.arn
depends_on = [aws_iam_policy_attachment.ecs-service-attach1]
load_balancer {
elb_name = aws_elb.myapp-elb.name
container_name = "myapp"
container_port = 3000
}
lifecycle {
ignore_changes = [task_definition]
}
}
# load balancer
resource "aws_elb" "myapp-elb" {
name = "myapp-elb"
listener {
instance_port = 3000
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
health_check {
healthy_threshold = 3
unhealthy_threshold = 3
timeout = 30
target = "HTTP:3000/"
interval = 60
}
cross_zone_load_balancing = true
idle_timeout = 400
connection_draining = true
connection_draining_timeout = 400
subnets = [aws_subnet.main-public-1.id, aws_subnet.main-public-2.id]
security_groups = [aws_security_group.myapp-elb-securitygroup.id]
tags = {
Name = "myapp-elb"
}
}