-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiam.tf
59 lines (52 loc) · 1.42 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
resource "aws_iam_user" "calvin-devops" {
name = "calvin"
path = "/"
}
resource "aws_iam_user" "hobbes-devops" {
name = "hobbes"
path = "/"
}
resource "aws_iam_group" "devops-users" {
name = "devops"
path = "/"
}
# https://github.com/nccgroup/AWS-recipes/blob/master/IAM-Policies/EnforceMFA-8HourSession-AllowEnableMFAChangePassword.json
resource "aws_iam_group_policy" "require-mfa" {
name = "require-mfa"
group = "${aws_iam_group.devops-users.id}"
policy = "${file("policy-require-mfa.json")}"
}
resource "aws_iam_policy" "all-access" {
name = "all-access-policy"
description = "Generic All"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "*",
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
}
# Managed Policy
resource "aws_iam_user_policy_attachment" "attach-hobbes-readonly" {
user = "${aws_iam_user.hobbes-devops.name}"
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess"
}
# Inline Policy
resource "aws_iam_user_policy_attachment" "attach-calvin-all" {
user = "${aws_iam_user.calvin-devops.name}"
policy_arn = "${aws_iam_policy.all-access.arn}"
}
resource "aws_iam_group_membership" "devops-users-mapping" {
name = "devops-users-mapping"
users = [
"${aws_iam_user.calvin-devops.name}",
"${aws_iam_user.hobbes-devops.name}",
]
group = "${aws_iam_group.devops-users.name}"
}