-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiam.tf
58 lines (49 loc) · 1.54 KB
/
iam.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
data "aws_iam_policy_document" "ecs_assume_role" {
statement {
actions = ["sts:AssumeRole"]
effect = "Allow"
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
}
}
resource "aws_iam_role" "exec_role" {
name = "ecs-task-execution-${var.name}"
assume_role_policy = data.aws_iam_policy_document.ecs_assume_role.json
}
resource "aws_iam_role_policy_attachment" "exec_policy" {
role = aws_iam_role.exec_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
}
resource "aws_iam_role" "ecs_task_tailscale" {
name = "ecs-task-${var.name}"
assume_role_policy = data.aws_iam_policy_document.ecs_assume_role.json
}
data "aws_iam_policy_document" "ecs_task_logs_tailscale" {
statement {
effect = "Allow"
actions = ["logs:DescribeLogGroups"]
resources = ["*"]
}
statement {
effect = "Allow"
actions = [
"logs:CreateLogStream",
"logs:DescribeLogStreams",
"logs:PutLogEvents",
]
resources = [
aws_cloudwatch_log_group.tailscale.arn,
]
}
}
resource "aws_iam_policy" "ecs_task_logs_tailscale" {
name = "ecs-task-logs-${var.name}"
description = "Permissions for ECS task to write logs for Tailscale"
policy = data.aws_iam_policy_document.ecs_task_logs_tailscale.json
}
resource "aws_iam_role_policy_attachment" "ecs_task_logs_tailscale" {
role = aws_iam_role.ecs_task_tailscale.name
policy_arn = aws_iam_policy.ecs_task_logs_tailscale.arn
}