-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathiam.tf
More file actions
155 lines (138 loc) · 3.92 KB
/
Copy pathiam.tf
File metadata and controls
155 lines (138 loc) · 3.92 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
data "aws_iam_policy_document" "foundry_server_assume_role" {
statement {
sid = "ECSTaskAccess"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "foundry_server" {
statement {
sid = "CloudwatchLogAccess"
actions = [
"logs:CreateLog*",
"logs:DescribeLogStreams",
"logs:PutLogEvents",
]
resources = [
"arn:aws:logs:*:*:*"
]
}
statement {
sid = "AllowFoundryCredentialsKMSAccess"
actions = [
"kms:Decrypt",
"kms:Encrypt",
"kms:ReEncrypt"
]
resources = [aws_kms_key.foundry_server_credentials.arn]
}
statement {
sid = "AllowFoundryCredentialsAccess"
actions = [
"ssm:GetParameter*",
]
resources = compact([
aws_ssm_parameter.foundry_username.arn,
aws_ssm_parameter.foundry_password.arn,
length(aws_ssm_parameter.foundry_admin_key) > 0 ? element(aws_ssm_parameter.foundry_admin_key.*.arn, 0) : ""
])
}
statement {
sid = "S3ListAllBucketsAccess"
actions = [
"s3:ListAllMyBuckets",
# "ecr:GetAuthorizationToken",
# "ecr:BatchCheckLayerAvailability",
# "ecr:GetDownloadUrlForLayer",
# "ecr:BatchGetImage",
]
resources = [
"*"
]
}
statement {
sid = "S3BucketAccess"
actions = [
"s3:GetBucket*",
"s3:List*",
]
resources = [
aws_s3_bucket.foundry_artifacts.arn,
]
}
statement {
sid = "S3BucketObjectGetAccess"
actions = [
"s3:GetObject*"
]
resources = [
"${aws_s3_bucket.foundry_artifacts.arn}/*"
]
}
statement {
sid = "S3BucketObjectPutAccess"
actions = [
"s3:PutObject*"
]
resources = [
"${aws_s3_bucket.foundry_artifacts.arn}/data/${terraform.workspace}/*"
]
}
statement {
sid = "EFSFoundryDataWriteAccess"
actions = [
"elasticfilesystem:ClientMount",
"elasticfilesystem:ClientWrite"
]
condition {
test = "Bool"
variable = "aws:SecureTransport"
values = ["true"]
}
condition {
test = "StringEquals"
variable = "elasticfilesystem:AccessPointArn"
values = [aws_efs_access_point.foundry_server_data.arn]
}
resources = [aws_efs_file_system.foundry_server_data.arn]
}
}
resource "aws_iam_policy" "foundry_server" {
description = "The core policy allowing basic access for a functioning foundry server."
name_prefix = "foundry-server-${terraform.workspace}"
policy = data.aws_iam_policy_document.foundry_server.json
}
resource "aws_iam_role" "foundry_server" {
assume_role_policy = data.aws_iam_policy_document.foundry_server_assume_role.json
description = "Starts with the requirements for the foundry server to function."
force_detach_policies = true
name_prefix = "foundry-server-${terraform.workspace}"
tags = local.tags_rendered
}
resource "aws_iam_role_policy_attachment" "foundry_server" {
role = aws_iam_role.foundry_server.name
policy_arn = aws_iam_policy.foundry_server.arn
}
output "role_arn" {
description = "The ARN of the role the Foundry server uses to access credentials and the artifacts bucket."
value = aws_iam_role.foundry_server.arn
}
output "role_name" {
description = "The name of the role the Foundry server uses to access credentials and the artifacts bucket."
value = aws_iam_role.foundry_server.name
}
output "policy_arn" {
description = "The ARN of the policy attached to the Foundry server role."
value = aws_iam_policy.foundry_server.arn
}
output "policy_id" {
description = "The ID of the policy attached to the Foundry server role."
value = aws_iam_policy.foundry_server.arn
}
output "policy_name" {
description = "The name of the policy attached to the Foundry server role."
value = aws_iam_policy.foundry_server.name
}