-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathecs.tf
84 lines (69 loc) · 1.93 KB
/
ecs.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
data "aws_iam_policy_document" "assume_by_ecs" {
statement {
sid = "AllowAssumeByEcsTasks"
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "execution_role" {
statement {
sid = "AllowECRLogging"
effect = "Allow"
actions = [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
resources = ["*"]
}
}
data "aws_iam_policy_document" "task_role" {
statement {
sid = "AllowDescribeCluster"
effect = "Allow"
actions = ["ecs:DescribeClusters"]
resources = ["${aws_ecs_cluster.this.arn}"]
}
}
resource "aws_iam_role" "execution_role" {
name = "${var.service_name}_ecsTaskExecutionRole"
assume_role_policy = "${data.aws_iam_policy_document.assume_by_ecs.json}"
}
resource "aws_iam_role_policy" "execution_role" {
role = "${aws_iam_role.execution_role.name}"
policy = "${data.aws_iam_policy_document.execution_role.json}"
}
resource "aws_iam_role" "task_role" {
name = "${var.service_name}_ecsTaskRole"
assume_role_policy = "${data.aws_iam_policy_document.assume_by_ecs.json}"
}
resource "aws_iam_role_policy" "task_role" {
role = "${aws_iam_role.task_role.name}"
policy = "${data.aws_iam_policy_document.task_role.json}"
}
resource "aws_ecs_cluster" "this" {
name = "${var.service_name}_cluster"
}
resource "aws_security_group" "ecs" {
name = "${var.service_name}-allow-ecs"
vpc_id = "${aws_vpc.this.id}"
ingress {
from_port = 0
protocol = "-1"
to_port = 0
security_groups = ["${aws_security_group.alb.id}"]
}
egress {
from_port = 0
protocol = "-1"
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
}