Quantcast
Channel: Terraform - HashiCorp Discuss
Viewing all articles
Browse latest Browse all 11357

Attache different multiple policies to multiple users with for_each

$
0
0

@mo-saeed wrote:

Terraform Version

0.12.7

Terraform Configuration Files

resource "aws_iam_user" "test" {
  for_each = "${var.svcMap}"
  name = "${var.svcMap[each.key]}"

}

resource "aws_iam_user_policy_attachment" "test-attach" {
  for_each = "${var.svcMap}"
  user = "${var.svcMap[each.key]}"
  
  policy_arn = "??"
}

Debug Output

It’s just a question, How to

Crash Output

N/A

Expected Behavior

To be able to attach different policies to multiple users with for_each

Actual Behavior

Not possible as policy_arn accept only string not list

Steps to Reproduce

N/A

Additional Context

I need to automate creation of users using terraform, mainly i have map “svcMap” like that {user1=[policy_arn1, policy_arn2] user2=[policy_arn3, policy_arn4]}, it’s easy to create users but not easy to attach policies:

resource "aws_iam_user" "test" {
  for_each = "${var.svcMap}"
  name = "${var.svcMap[each.key]}"

}

resource "aws_iam_user_policy_attachment" "test-attach" {
  for_each = "${var.svcMap}"
  user = "${var.svcMap[each.key]}"
  
  policy_arn = "??"
}

Is there anyway to achieve that ?

Posts: 5

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 11357

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>