-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
main.tf
204 lines (164 loc) · 4.5 KB
/
main.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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
provider "aws" {
region = "eu-west-1"
}
###############################
# IAM assumable role for admin
###############################
module "iam_assumable_role_admin" {
source = "../../modules/iam-assumable-role"
# https://aws.amazon.com/blogs/security/announcing-an-update-to-iam-role-trust-policy-behavior/
allow_self_assume_role = true
trusted_role_arns = [
"arn:aws:iam::307990089504:root",
"arn:aws:iam::835367859851:user/anton",
]
trusted_role_services = [
"codedeploy.amazonaws.com"
]
create_role = true
create_instance_profile = true
role_name = "admin"
role_requires_mfa = true
attach_admin_policy = true
tags = {
Role = "Admin"
}
}
##########################################
# IAM assumable role with custom policies
##########################################
module "iam_assumable_role_custom" {
source = "../../modules/iam-assumable-role"
trusted_role_arns = [
"arn:aws:iam::307990089504:root",
]
trusted_role_services = [
"codedeploy.amazonaws.com"
]
create_role = true
role_name_prefix = "custom-"
role_requires_mfa = false
role_sts_externalid = "some-id-goes-here"
custom_role_policy_arns = [
"arn:aws:iam::aws:policy/AmazonCognitoReadOnly",
"arn:aws:iam::aws:policy/AlexaForBusinessFullAccess",
module.iam_policy.arn
]
# number_of_custom_role_policy_arns = 3
}
##########################################
# IAM assumable role with inline policy
##########################################
module "iam_assumable_role_inline_policy" {
source = "../../modules/iam-assumable-role"
trusted_role_arns = [
"arn:aws:iam::307990089504:root",
]
trusted_role_services = [
"codedeploy.amazonaws.com"
]
create_role = true
role_name_prefix = "custom-"
role_requires_mfa = false
role_sts_externalid = "some-id-goes-here"
inline_policy_statements = [
{
sid = "AllowECRPushPull"
actions = [
"ecr:GetAuthorizationToken",
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchCheckLayerAvailability",
"ecr:DescribeImages",
"ecr:DescribeRepositories",
"ecr:GetDownloadUrlForLayer",
"ecr:ListImages",
"ecr:PutImage",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload"
]
effect = "Allow"
resources = ["*"]
}
]
}
####################################################
# IAM assumable role with multiple sts external ids
####################################################
module "iam_assumable_role_sts" {
source = "../../modules/iam-assumable-role"
trusted_role_arns = [
"arn:aws:iam::307990089504:root",
]
trusted_role_services = [
"codedeploy.amazonaws.com"
]
create_role = true
role_name = "custom_sts"
role_requires_mfa = true
role_sts_externalid = [
"some-id-goes-here",
"another-id-goes-here",
]
custom_role_policy_arns = [
"arn:aws:iam::aws:policy/AmazonCognitoReadOnly",
"arn:aws:iam::aws:policy/AlexaForBusinessFullAccess",
module.iam_policy.arn
]
# number_of_custom_role_policy_arns = 3
}
#########################################
# IAM assumable role with custom trust policy
#########################################
module "iam_assumable_role_custom_trust_policy" {
source = "../../modules/iam-assumable-role"
create_role = true
role_name = "iam_assumable_role_custom_trust_policy"
create_custom_role_trust_policy = true
custom_role_trust_policy = data.aws_iam_policy_document.custom_trust_policy.json
custom_role_policy_arns = ["arn:aws:iam::aws:policy/AmazonCognitoReadOnly"]
}
data "aws_iam_policy_document" "custom_trust_policy" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
condition {
test = "StringEquals"
variable = "sts:ExternalId"
values = ["some-ext-id"]
}
condition {
test = "StringEquals"
variable = "aws:PrincipalOrgID"
values = ["o-someorgid"]
}
principals {
type = "AWS"
identifiers = ["*"]
}
}
}
#########################################
# IAM policy
#########################################
module "iam_policy" {
source = "../../modules/iam-policy"
name = "example"
path = "/"
description = "My example policy"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
}