Skip to content

Commit 8ae9bdc

Browse files
committed
adding example terraform config for aws iam resources
1 parent a093b0f commit 8ae9bdc

20 files changed

Lines changed: 428 additions & 0 deletions

terraform/aws-custom-policies.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module "aws_iam_policies" {
2+
source = "./modules/policies"
3+
policies = {
4+
"ManageAccessKeys" = {
5+
description = "Policy for creating, listing, and updating Access Keys"
6+
filename = "manage-access-keys-policy.json"
7+
},
8+
"FullAccessPolicy" = {
9+
description = "Full access to specific resources"
10+
filename = "full-access-policy.json"
11+
}
12+
}
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Sid": "ListUsersForConsole",
6+
"Effect": "Allow",
7+
"Action": "iam:ListUsers",
8+
"Resource": "arn:aws:iam::*:*"
9+
},
10+
{
11+
"Sid": "ViewAndUpdateAccessKeys",
12+
"Effect": "Allow",
13+
"Action": [
14+
"iam:UpdateAccessKey",
15+
"iam:CreateAccessKey",
16+
"iam:ListAccessKeys"
17+
],
18+
"Resource": "arn:aws:iam::*:user/*"
19+
}
20+
]
21+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Sid": "AllowViewAccountInfo",
6+
"Effect": "Allow",
7+
"Action": [
8+
"iam:GetAccountPasswordPolicy",
9+
"iam:GetAccountSummary"
10+
],
11+
"Resource": "*"
12+
},
13+
{
14+
"Sid": "AllowManageOwnPasswords",
15+
"Effect": "Allow",
16+
"Action": [
17+
"iam:ChangePassword",
18+
"iam:GetUser"
19+
],
20+
"Resource": "arn:aws:iam::*:user/${aws:username}"
21+
},
22+
{
23+
"Sid": "AllowManageOwnAccessKeys",
24+
"Effect": "Allow",
25+
"Action": [
26+
"iam:CreateAccessKey",
27+
"iam:DeleteAccessKey",
28+
"iam:ListAccessKeys",
29+
"iam:UpdateAccessKey"
30+
],
31+
"Resource": "arn:aws:iam::*:user/${aws:username}"
32+
},
33+
{
34+
"Sid": "AllowManageOwnSSHPublicKeys",
35+
"Effect": "Allow",
36+
"Action": [
37+
"iam:DeleteSSHPublicKey",
38+
"iam:GetSSHPublicKey",
39+
"iam:ListSSHPublicKeys",
40+
"iam:UpdateSSHPublicKey",
41+
"iam:UploadSSHPublicKey"
42+
],
43+
"Resource": "arn:aws:iam::*:user/${aws:username}"
44+
}
45+
]
46+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Sid": "VisualEditor0",
6+
"Effect": "Allow",
7+
"Action": [
8+
"elasticloadbalancing:DescribeTargetGroupAttributes",
9+
"elasticloadbalancing:DescribeTags",
10+
"s3:ListAllMyBuckets",
11+
"ecr:GetRegistryScanningConfiguration"
12+
],
13+
"Resource": "*"
14+
},
15+
{
16+
"Sid": "RDS",
17+
"Effect": "Allow",
18+
"Action": [
19+
"rds:DescribeDBInstances",
20+
"rds:DescribeDBClusters",
21+
"rds:DescribeGlobalClusters",
22+
"rds:DescribeDBInstances"
23+
],
24+
"Resource": "*"
25+
}
26+
]
27+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Sid": "AllowViewAccountInfo",
6+
"Effect": "Allow",
7+
"Action": [
8+
"iam:GetAccountPasswordPolicy",
9+
"iam:GetAccountSummary"
10+
],
11+
"Resource": "*"
12+
},
13+
{
14+
"Sid": "AllowManageOwnPasswords",
15+
"Effect": "Allow",
16+
"Action": [
17+
"iam:ChangePassword",
18+
"iam:GetUser"
19+
],
20+
"Resource": "arn:aws:iam::*:user/${aws:username}"
21+
},
22+
{
23+
"Sid": "AllowManageOwnAccessKeys",
24+
"Effect": "Allow",
25+
"Action": [
26+
"iam:CreateAccessKey",
27+
"iam:DeleteAccessKey",
28+
"iam:ListAccessKeys",
29+
"iam:UpdateAccessKey"
30+
],
31+
"Resource": "arn:aws:iam::*:user/${aws:username}"
32+
},
33+
{
34+
"Sid": "AllowManageOwnSSHPublicKeys",
35+
"Effect": "Allow",
36+
"Action": [
37+
"iam:DeleteSSHPublicKey",
38+
"iam:GetSSHPublicKey",
39+
"iam:ListSSHPublicKeys",
40+
"iam:UpdateSSHPublicKey",
41+
"iam:UploadSSHPublicKey"
42+
],
43+
"Resource": "arn:aws:iam::*:user/${aws:username}"
44+
}
45+
]
46+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Sid": "",
6+
"Effect": "",
7+
"Action": [
8+
"",
9+
"",
10+
"",
11+
""
12+
],
13+
"Resource": ""
14+
},
15+
{
16+
"Sid": "",
17+
"Effect": "",
18+
"Action": [
19+
"",
20+
"",
21+
"",
22+
""
23+
],
24+
"Resource": ""
25+
}
26+
]
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Sid": "",
6+
"Effect": "",
7+
"Action": [
8+
"",
9+
"",
10+
"",
11+
""
12+
],
13+
"Resource": ""
14+
},
15+
{
16+
"Sid": "",
17+
"Effect": "",
18+
"Action": [
19+
"",
20+
"",
21+
"",
22+
""
23+
],
24+
"Resource": ""
25+
}
26+
]
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Sid": "",
6+
"Effect": "",
7+
"Action": [
8+
"",
9+
"",
10+
"",
11+
""
12+
],
13+
"Resource": ""
14+
},
15+
{
16+
"Sid": "",
17+
"Effect": "",
18+
"Action": [
19+
"",
20+
"",
21+
"",
22+
""
23+
],
24+
"Resource": ""
25+
}
26+
]
27+
}

terraform/aws-groups.tf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Create groups and attach policies
2+
module "iam_read_only_group" {
3+
source = "./modules/groups"
4+
5+
group_name = "read-only-group"
6+
policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess"
7+
}
8+
9+
module "iam_project_admin_group" {
10+
source = "./modules/groups"
11+
12+
group_name = "project-admin-group"
13+
policy_arn = [ # here we can pass a list of policies that are aws managed or customer managed
14+
"arn:aws:iam::aws:policy/SomeAWSPolicy",
15+
module.iam_policies.policy_arns["ManageAccessKeys"]
16+
]
17+
}
18+
19+
module "iam_ops_mentor_group" {
20+
source = "./modules/groups"
21+
22+
group_name = "project-admin-group"
23+
policy_arn = [ # here we can pass a list of policies that are aws managed or customer managed
24+
"arn:aws:iam::aws:policy/SomeAWSPolicy",
25+
"arn:aws:iam::aws:policy/SomeAWSPolicy",
26+
"arn:aws:iam::aws:policy/SomeAWSPolicy",
27+
"arn:aws:iam::aws:policy/SomeAWSPolicy",
28+
]
29+
}
30+
31+
// Assign users to groups
32+
resource "aws_iam_group_membership" "project_admin_group_membership" {
33+
name = "project_admin_group_membership" # A unique name for the group membership
34+
35+
users = [
36+
module.iam_user_gwenstacy.user_name,
37+
module.iam_user_miles_morales.user_name,
38+
"chelseybeck"
39+
]
40+
41+
group = module.iam_project_admin_group.group_name
42+
}

terraform/aws-users.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module "iam_user_gwenstacy" {
2+
source = "./modules/users"
3+
4+
user_name = "gwenstacy"
5+
user_tags = {
6+
"Environment" = "Development"
7+
"Project" = "spiderverse"
8+
}
9+
pgp_key = "user_provided_public_key_here"
10+
}
11+
12+
module "iam_user_milesmorales" {
13+
source = "./modules/users"
14+
15+
user_name = "miles_morales"
16+
user_tags = {
17+
"Environment" = "Production"
18+
"Project" = "spiderverse"
19+
}
20+
pgp_key = "user_provided_public_key_here"
21+
}

0 commit comments

Comments
 (0)