-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
115 lines (102 loc) · 2.38 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
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
#----------------------------------------------------------
# Redshift
#----------------------------------------------------------
data "aws_iam_policy_document" "assume_role_policy_for_redshift" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["redshift.amazonaws.com"]
}
condition {
test = "StringEquals"
variable = "sts:ExternalId"
values = [
"arn:aws:redshift:ap-northeast-1:${data.aws_caller_identity.current.account_id}:dbuser:${var.redshift_cluster_identifier}/${var.redshift_master_username}"
]
}
}
}
data "aws_iam_policy_document" "redshift_role_policy" {
statement {
effect = "Allow"
actions = [
"glue:GetTable"
]
resources = [
"*"
]
}
statement {
effect = "Allow"
actions = [
"s3:Get*",
"s3:List*"
]
resources = [
"*"
]
}
}
resource "aws_iam_role" "redshift" {
name = "redshift-role"
assume_role_policy = data.aws_iam_policy_document.assume_role_policy_for_redshift.json
}
resource "aws_iam_role_policy" "redshift_role_policy" {
name = "redshift-role-policy"
role = aws_iam_role.redshift.id
policy = data.aws_iam_policy_document.redshift_role_policy.json
}
#----------------------------------------------------------
# Glue
#----------------------------------------------------------
data "aws_iam_policy_document" "assume_role_policy_for_glue" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["glue.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "glue_role_policy" {
statement {
effect = "Allow"
actions = [
"s3:Get*",
"s3:List*"
]
resources = [
"*"
]
}
statement {
effect = "Allow"
actions = [
"glue:*"
]
resources = [
"*"
]
}
statement {
effect = "Allow"
actions = [
"cloudwatch:PutLogEvents"
]
resources = [
"*"
]
}
}
resource "aws_iam_role" "glue" {
name = "glue-role"
assume_role_policy = data.aws_iam_policy_document.assume_role_policy_for_glue.json
}
resource "aws_iam_role_policy" "glue_role_policy" {
name = "glue-role-policy"
role = aws_iam_role.glue.id
policy = data.aws_iam_policy_document.glue_role_policy.json
}