I have an aws_iam_user
resource that creates users:
variable "users_list" {
default = [
"user1",
"user2",
"user3"
]
}
resource "aws_iam_user" "users" {
count = length(var.users_list)
name = "${var.platform}_${element(var.users_list, count.index)}
}
Policies
resource "aws_iam_user_policy" "db_access" {
count = length(aws_iam_user.users)
user = element(aws_iam_user.users[*].name, count.index)
name = "test1"
policy = <<EOF
...
EOF
}
resource "aws_iam_user_policy" "ec2_access" {
count = length(aws_iam_user.users)
user = element(aws_iam_user.users[*].name, count.index)
name = "test2"
policy = <<EOF
...
EOF
}
This way I can assign all these policies to all users
But for example, user1
can have db_access
and ec2_access
, but user3
could have only db_access
Is there any way to do this in terraform?