-
Notifications
You must be signed in to change notification settings - Fork 4
/
ecs_fargate.tf
67 lines (59 loc) · 2.87 KB
/
ecs_fargate.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
resource "aws_ecr_repository" "fargete_nginx" {
name = "${var.env}-${var.project_name}-fargate-repo-nginx"
}
#########################################
# cloudwatch logs group
#########################################
resource "aws_cloudwatch_log_group" "fargete_nginx_log" {
name = "${var.env}-${var.project_name}-fargate-nginx-log"
}
########################################
# ECS Cluster
#########################################
resource "aws_ecs_cluster" "fargete_cluster" {
name = "${var.env}-${var.project_name}-fargate-cluster"
}
#########################################
# Task Definition
#########################################
data "template_file" "task_definition_fargete_nginx" {
template = "${file("${path.module}/ecs_tasks/task-definition-fargete-nginx.json.tpl")}"
vars {
name = "${lookup(var.container-nginx, "name")}"
image = "${aws_ecr_repository.fargete_nginx.repository_url}"
version = "${lookup(var.container-nginx, "version")}"
memory = "${lookup(var.container-nginx, "memory")}"
cpu = "${lookup(var.container-nginx, "cpu")}"
docker_port = "${lookup(var.container-nginx, "docker_port")}"
awslogs-group = "${var.env}-${var.project_name}-fargete-nginx-log"
awslogs-region = "${var.region}"
}
}
resource "aws_ecs_task_definition" "ecs_task_fargete_nginx" {
depends_on = ["data.template_file.task_definition_fargete_nginx"]
family = "${var.env}-${var.project_name}-ecs-task-fargete-nginx"
container_definitions = "${data.template_file.task_definition_fargete_nginx.rendered}"
task_role_arn = "${aws_iam_role.ecs_task_role.arn}"
}
#########################################
# ECS Service
#########################################
resource "aws_ecs_service" "service-fargete-nginx" {
depends_on = ["aws_ecs_task_definition.ecs_task_fargete_nginx"]
name = "${var.env}-${var.project_name}-service-fargete-nginx"
cluster = "${aws_ecs_cluster.fargete_cluster.id}"
task_definition = "${aws_ecs_task_definition.ecs_task_fargete_nginx.arn}"
desired_count = "${lookup(var.container-nginx, "desired_count")}"
deployment_maximum_percent = "${lookup(var.container-nginx, "deployment_maximum_percent")}"
deployment_minimum_healthy_percent = "${lookup(var.container-nginx, "deployment_minimum_healthy_percent")}"
launch_type = "FARGATE"
load_balancer {
target_group_arn = "${aws_alb_target_group.nginx.arn}"
container_name = "${lookup(var.container-nginx, "name")}"
container_port = "${lookup(var.container-nginx, "docker_port")}"
}
network_configuration {
security_groups = ["${aws_security_group.app-sg.id}"]
subnets = ["${lookup(var.vpc, "app-a")}", "${lookup(var.vpc, "app-c")}"]
}
}