Skip to content

Commit fd70c07

Browse files
authored
feat: Allows multiple STS External IDs to be provided to an assumable role (#138)
1 parent 564ea41 commit fd70c07

File tree

6 files changed

+43
-8
lines changed

6 files changed

+43
-8
lines changed

examples/iam-assumable-role/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ No provider.
3434
|------|--------|---------|
3535
| iam_assumable_role_admin | ../../modules/iam-assumable-role | |
3636
| iam_assumable_role_custom | ../../modules/iam-assumable-role | |
37+
| iam_assumable_role_sts | ../../modules/iam-assumable-role | |
3738
| iam_policy | ../../modules/iam-policy | |
3839

3940
## Resources

examples/iam-assumable-role/main.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,38 @@ module "iam_assumable_role_custom" {
5858
# number_of_custom_role_policy_arns = 3
5959
}
6060

61+
####################################################
62+
# IAM assumable role with multiple sts external ids
63+
####################################################
64+
module "iam_assumable_role_sts" {
65+
source = "../../modules/iam-assumable-role"
66+
67+
trusted_role_arns = [
68+
"arn:aws:iam::307990089504:root",
69+
]
70+
71+
trusted_role_services = [
72+
"codedeploy.amazonaws.com"
73+
]
74+
75+
create_role = true
76+
77+
role_name = "custom_sts"
78+
role_requires_mfa = false
79+
80+
role_sts_externalid = [
81+
"some-id-goes-here",
82+
"another-id-goes-here",
83+
]
84+
85+
custom_role_policy_arns = [
86+
"arn:aws:iam::aws:policy/AmazonCognitoReadOnly",
87+
"arn:aws:iam::aws:policy/AlexaForBusinessFullAccess",
88+
module.iam_policy.arn
89+
]
90+
# number_of_custom_role_policy_arns = 3
91+
}
92+
6193
#########################################
6294
# IAM policy
6395
#########################################

modules/iam-assumable-role/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ No Modules.
5353
| role\_path | Path of IAM role | `string` | `"/"` | no |
5454
| role\_permissions\_boundary\_arn | Permissions boundary ARN to use for IAM role | `string` | `""` | no |
5555
| role\_requires\_mfa | Whether role requires MFA | `bool` | `true` | no |
56-
| role\_sts\_externalid | STS ExternalId condition value to use with a role (when MFA is not required) | `string` | `null` | no |
56+
| role\_sts\_externalid | STS ExternalId condition values to use with a role (when MFA is not required) | `any` | `[]` | no |
5757
| tags | A map of tags to add to IAM role resources | `map(string)` | `{}` | no |
5858
| trusted\_role\_actions | Actions of STS | `list(string)` | <pre>[<br> "sts:AssumeRole"<br>]</pre> | no |
5959
| trusted\_role\_arns | ARNs of AWS entities who can assume these roles | `list(string)` | `[]` | no |

modules/iam-assumable-role/main.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
locals {
2+
role_sts_externalid = flatten(list(var.role_sts_externalid))
3+
}
4+
15
data "aws_iam_policy_document" "assume_role" {
26
statement {
37
effect = "Allow"
@@ -15,11 +19,11 @@ data "aws_iam_policy_document" "assume_role" {
1519
}
1620

1721
dynamic "condition" {
18-
for_each = var.role_sts_externalid != null ? [true] : []
22+
for_each = length(local.role_sts_externalid) != 0 ? [true] : []
1923
content {
2024
test = "StringEquals"
2125
variable = "sts:ExternalId"
22-
values = [var.role_sts_externalid]
26+
values = local.role_sts_externalid
2327
}
2428
}
2529
}

modules/iam-assumable-role/outputs.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@ output "role_sts_externalid" {
3737
description = "STS ExternalId condition value to use with a role"
3838
value = var.role_sts_externalid
3939
}
40-

modules/iam-assumable-role/variables.tf

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ variable "role_description" {
132132
}
133133

134134
variable "role_sts_externalid" {
135-
description = "STS ExternalId condition value to use with a role (when MFA is not required)"
136-
type = string
137-
default = null
135+
description = "STS ExternalId condition values to use with a role (when MFA is not required)"
136+
type = any
137+
default = []
138138
}
139-

0 commit comments

Comments
 (0)