-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
61 lines (49 loc) · 1.46 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
57
58
59
60
61
data "aws_iam_policy_document" "ecs-assume-role" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
}
}
resource "aws_iam_role" "ecs-agent" {
description = "ECS Task Execution Role used by ECS Agent"
assume_role_policy = data.aws_iam_policy_document.ecs-assume-role.json
force_detach_policies = true
name_prefix = "ecs-task-execution-agent-role-"
}
data "aws_kms_alias" "secretsmanager" {
name = "alias/aws/secretsmanager"
}
data "aws_iam_policy_document" "secrets-manager" {
statement {
sid = "1"
actions = [
"secretsmanager:GetSecretValue"
]
resources = values(var.container_secrets)
}
statement {
sid = "2"
actions = [
"kms:Decrypt"
]
resources = [
data.aws_kms_alias.secretsmanager.arn
]
}
}
resource "aws_iam_policy" "secrets-manager" {
name_prefix = "secrets-manager"
description = "IAM Policy that allows access to Secrets Manager entries"
policy = data.aws_iam_policy_document.secrets-manager.json
}
resource "aws_iam_role_policy_attachment" "secrets-manager" {
role = aws_iam_role.ecs-agent.name
policy_arn = aws_iam_policy.secrets-manager.arn
}
resource "aws_iam_role_policy_attachment" "task-exec-role-policy-default" {
role = aws_iam_role.ecs-agent.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
}