-
Notifications
You must be signed in to change notification settings - Fork 0
/
fargate-iam.tf
125 lines (105 loc) · 3.02 KB
/
fargate-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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
resource "aws_iam_role" "containerised" {
name = "${var.SERVICE}-${var.BUILD_STAGE}-containerised"
assume_role_policy = data.aws_iam_policy_document.containerised_policy.json
tags = local.common_tags
}
data "aws_iam_policy_document" "containerised_policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ecs.amazonaws.com", "ecs-tasks.amazonaws.com"]
}
}
}
resource "aws_iam_policy" "containerised_policy" {
name = "${var.SERVICE}-${var.BUILD_STAGE}-containerised"
description = "${var.SERVICE}-${var.BUILD_STAGE}-containerised"
path = "/"
policy = data.aws_iam_policy_document.containerised.json
}
resource "aws_iam_policy_attachment" "containerised" {
name = "${var.SERVICE}-${var.BUILD_STAGE}-containerised"
roles = [aws_iam_role.containerised.name]
policy_arn = aws_iam_policy.containerised_policy.arn
}
resource "aws_secretsmanager_secret" "api_token" {
name = "${var.SERVICE}-num-${var.BUILD_STAGE}-api-token"
tags = local.common_tags
}
data "aws_iam_policy_document" "containerised" {
statement {
sid = "Secrets"
actions = [
"secretsmanager:GetResourcePolicy",
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret",
"secretsmanager:ListSecretVersionIds"
]
resources = [aws_secretsmanager_secret.api_token.arn]
}
statement {
sid = "AllowECR"
actions = [
"ecr:UntagResource",
"ecr:TagResource",
"ecr:StartImageScan",
"ecr:ListTagsForResource",
"ecr:ListImages",
"ecr:InitiateLayerUpload",
"ecr:GetRepositoryPolicy",
"ecr:GetLifecyclePolicy",
"ecr:GetAuthorizationToken",
"ecr:GetDownloadUrlForLayer",
"ecr:DescribeRepositories",
"ecr:DescribeImages",
"ecr:CompleteLayerUpload",
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
resources = ["*"]
}
statement {
sid = "AllowECS"
actions = [
"ecs:CreateCluster",
"ecs:DescribeClusters",
"ecs:DescribeServices",
"ecs:DescribeTasks",
"ecs:DescribeContainerInstances",
"ecs:ListServices",
"ecs:ListContainerInstances",
"ecs:ListClusters",
"ecs:ListTaskDefinitions"
]
resources = [
aws_ecs_cluster.main.arn
]
}
statement {
sid = "AllowKms"
actions = [
"kms:Decrypt",
"kms:Describe*",
"kms:Encrypt",
"kms:GenerateDataKey"
]
resources = [
aws_kms_key.aurora.arn,
aws_kms_key.logging.arn
]
}
statement {
sid = "AllowSsm"
actions = [
"ssm:Get*",
"ssm:Describe*"
]
resources = [
"arn:aws:logs:${var.AWS_REGION}:${data.aws_caller_identity.current.account_id}:log-group:/aws/lambda/${var.SERVICE}-${var.BUILD_STAGE}*:*",
"arn:aws:ssm:${var.AWS_REGION}:${data.aws_caller_identity.current.account_id}:parameter/${var.SERVICE}/${var.BUILD_STAGE}/*"
]
}
}