This repository was archived by the owner on Oct 25, 2023. It is now read-only.
generated from TechNative-B-V/terraform-aws-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrust_relationship.tf
57 lines (49 loc) · 1.48 KB
/
trust_relationship.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
data "aws_iam_policy_document" "useraccount_trust" {
for_each = var.trust_relationship
statement {
sid = each.key
actions = ["sts:AssumeRole"]
effect = "Allow"
principals {
type = each.value.identifier_type
identifiers = [each.value.identifier]
}
# https://docs.aws.amazon.com/IAM/latest/UserGuide/confused-deputy.html
# prevent at least cross account confused deputy
dynamic "condition" {
for_each = each.value.prevent_account_confuseddeputy ? [1] : []
content {
test = "StringEquals"
variable = "aws:SourceAccount"
values = [data.aws_caller_identity.current.id]
}
}
dynamic "condition" {
for_each = each.value.enforce_userprincipal ? [1] : []
content {
test = "StringEquals"
variable = "aws:PrincipalType"
values = ["User"]
}
}
dynamic "condition" {
for_each = each.value.enforce_mfa ? [1] : []
content {
test = "Bool"
variable = "aws:MultiFactorAuthPresent"
values = [true]
}
}
dynamic "condition" {
for_each = each.value.external_id != null ? [each.value.external_id] : []
content {
test = "StringEquals"
variable = "sts:ExternalId"
values = [condition.value]
}
}
}
}
data "aws_iam_policy_document" "trust_relationship" {
source_policy_documents = [for k, v in data.aws_iam_policy_document.useraccount_trust : v.json]
}