-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.tf
36 lines (31 loc) · 978 Bytes
/
role.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
# IAM assume role policy document for the IAM role
data "aws_iam_policy_document" "assume_role" {
statement {
actions = [
"sts:AssumeRole",
"sts:TagSession"
]
effect = "Allow"
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
# Calculate all combinations of account_ids and iam_usernames
principals {
type = "AWS"
identifiers = [for t in setproduct(var.account_ids, local.iam_usernames) : format("arn:aws:iam::${t[0]}:${t[1]}")]
}
}
}
# The IAM role
resource "aws_iam_role" "s3_access" {
assume_role_policy = data.aws_iam_policy_document.assume_role.json
description = local.role_description
name = local.role_name
tags = var.additional_role_tags
}
# Attach the policy to the role
resource "aws_iam_role_policy_attachment" "s3_access" {
policy_arn = aws_iam_policy.s3_access.arn
role = aws_iam_role.s3_access.name
}