-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
85 lines (72 loc) · 2.53 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
resource "aws_iam_policy" "execution" {
name = "${local.prefix}-execution"
description = "${var.service} task execution policy for ${var.project} ${var.environment}."
policy = jsonencode(yamldecode(templatefile("${path.module}/templates/execution-policy.yaml.tftpl", {
project = var.project
environment = var.environment
ecr_arn = local.repository_arn
})))
tags = var.tags
}
resource "aws_iam_policy" "secrets" {
name_prefix = "${local.prefix}-secrets-access-"
description = "Allow acceess to ${var.service} secrets for ${var.project} ${var.environment}."
policy = jsonencode(yamldecode(templatefile("${path.module}/templates/secrets-access-policy.yaml.tftpl", {
secrets = toset(local.authorized_secrets)
otel_ssm_arn = module.otel_config.ssm_parameter_arn
kms_arn = aws_kms_key.fargate.arn
})))
tags = var.tags
}
resource "aws_iam_role" "execution" {
name = "${local.prefix}-execution"
description = "${var.service} task execution role for ${var.project} ${var.environment}."
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = "sts:AssumeRole"
Principal = {
Service = "ecs-tasks.amazonaws.com"
}
}
]
})
tags = var.tags
}
resource "aws_iam_role_policy_attachments_exclusive" "execution" {
role_name = aws_iam_role.execution.name
policy_arns = [
# aws_iam_policy.execution.arn
aws_iam_policy.secrets.arn,
"arn:${data.aws_partition.current.partition}:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy",
"arn:${data.aws_partition.current.partition}:iam::aws:policy/CloudWatchAgentServerPolicy"
]
}
resource "aws_iam_role" "task" {
name = "${local.prefix}-task"
description = "${var.service} task role for ${var.project} ${var.environment}."
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = "sts:AssumeRole"
Principal = {
Service = "ecs-tasks.amazonaws.com"
}
}
]
})
tags = var.tags
}
resource "aws_iam_role_policy_attachments_exclusive" "task" {
role_name = aws_iam_role.task.name
policy_arns = [
aws_iam_policy.secrets.arn,
"arn:${data.aws_partition.current.partition}:iam::aws:policy/CloudWatchFullAccess",
"arn:${data.aws_partition.current.partition}:iam::aws:policy/AmazonSSMFullAccess",
"arn:${data.aws_partition.current.partition}:iam::aws:policy/CloudWatchAgentServerPolicy",
]
}