-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiam_athena_readonly_user.tf
115 lines (104 loc) · 3.09 KB
/
iam_athena_readonly_user.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
resource "aws_iam_policy" "athena_readonly_user" {
name = "athena_readonly_user_policy"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"athena:StartQueryExecution",
"athena:GetQueryExecution",
"athena:GetQueryResults",
"athena:GetQueryResultsStream"
],
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket",
"s3:ListAllMyBuckets",
"s3:ListBucketMultipartUploads",
"s3:ListMultipartUploadParts",
"s3:AbortMultipartUpload"
],
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"s3:PutObject",
"s3:PutBucketPublicAccessBlock"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::s3-dq-athena-log-${var.namespace}",
"arn:aws:s3:::s3-dq-athena-log-${var.namespace}/*"
]
},
{
"Action": [
"glue:GetDatabase",
"glue:GetDatabases",
"glue:GetTable",
"glue:GetTables",
"glue:GetPartition",
"glue:GetPartitions"
],
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:GenerateDataKey",
"kms:DescribeKey"
],
"Effect": "Allow",
"Resource": "${var.kms_key_s3[var.namespace]}"
},
{
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:GenerateDataKey",
"kms:DescribeKey"
],
"Effect": "Allow",
"Resource": "${data.aws_kms_key.glue.arn}"
}
]
}
EOF
}
resource "aws_iam_group_policy_attachment" "athena_readonly_user" {
group = aws_iam_group.athena_readonly_user.name
policy_arn = aws_iam_policy.athena_readonly_user.arn
}
resource "aws_iam_user" "athena_readonly_user" {
name = "athena_readonly_user"
}
resource "aws_iam_access_key" "athena_readonly_user" {
user = aws_iam_user.athena_readonly_user.name
}
resource "aws_iam_group" "athena_readonly_user" {
name = "athena_readonly_user"
}
resource "aws_iam_group_membership" "athena_readonly_user" {
name = "athena_readonly_user"
users = [aws_iam_user.athena_readonly_user.name]
group = aws_iam_group.athena_readonly_user.name
}
resource "aws_ssm_parameter" "athena_readonly_user_id" {
name = "athena-readonly-user-id-${local.naming_suffix}"
type = "SecureString"
value = aws_iam_access_key.athena_readonly_user.id
}
resource "aws_ssm_parameter" "athena_readonly_user_key" {
name = "athena-readonly-user-key-${local.naming_suffix}"
type = "SecureString"
value = aws_iam_access_key.athena_readonly_user.secret
}