-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
43 lines (32 loc) · 873 Bytes
/
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
resource "aws_iam_user" "IAM_Users" {
for_each = toset(var.username)
name = each.key
}
output "user_details" {
value = {
for username, user in aws_iam_user.IAM_Users :
username => user.name
}
}
resource "aws_iam_policy" "ec2_policy" {
name = "ec2_policy"
description = "Allows describing EC2 instances"
policy = jsonencode({
Version = "2012-10-17",
Statement = [{
Effect = "Allow",
Action = "ec2:Describe*",
Resource = "*",
}],
})
}
resource "aws_iam_policy_attachment" "ec2_policy_attachment" {
for_each = aws_iam_user.IAM_Users
name = "Policy_attachment_${each.key}"
policy_arn = aws_iam_policy.ec2_policy.arn
users = [each.value.name]
lifecycle {
create_before_destroy = true
}
depends_on = [aws_iam_user.IAM_Users]
}