-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaws_ecs_iam.tf
More file actions
59 lines (49 loc) · 1.84 KB
/
aws_ecs_iam.tf
File metadata and controls
59 lines (49 loc) · 1.84 KB
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
# ------------------------------------------------------------------------------
# IAM Role
# ------------------------------------------------------------------------------
# https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_execution_IAM_role.html
resource "aws_iam_role" "ecsTaskExecutionRole" {
name = "${local.cluster_name}-ecsTaskExecutionRole"
assume_role_policy = data.aws_iam_policy_document.assume_role_policy.json
}
data "aws_iam_policy_document" "assume_role_policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
}
}
resource "aws_iam_role_policy_attachment" "ecsTaskExecutionRole_policy" {
role = aws_iam_role.ecsTaskExecutionRole.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
}
# ------------------------------------------------------------------------------
# Cloudwatch logging
# ------------------------------------------------------------------------------
resource "aws_cloudwatch_log_group" "logs" {
name = "/ecs/${local.cluster_name}"
retention_in_days = 3
tags = local.tags
}
data "aws_iam_policy_document" "log_publishing" {
statement {
actions = [
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:PutLogEventsBatch",
]
resources = ["arn:aws:logs:${var.aws_region}:*:log-group:/ecs/${local.cluster_name}:*"]
}
}
resource "aws_iam_policy" "log_publishing" {
name = "${local.cluster_name}-log"
path = "/"
description = "Allow ${local.cluster_name} to log to cloudwach"
policy = data.aws_iam_policy_document.log_publishing.json
}
resource "aws_iam_role_policy_attachment" "log_publishing" {
role = aws_iam_role.ecsTaskExecutionRole.name
policy_arn = aws_iam_policy.log_publishing.arn
}