Skip to content

Commit 92dbb09

Browse files
authored
feat: iam-assumable-roles-with-saml - Allow for multiple provider ids (#110)
1 parent 09e0a48 commit 92dbb09

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

examples/iam-assumable-roles-with-saml/main.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ resource "aws_iam_saml_provider" "idp_saml" {
77
saml_metadata_document = file("saml-metadata.xml")
88
}
99

10+
resource "aws_iam_saml_provider" "second_idp_saml" {
11+
name = "second_idp_saml"
12+
saml_metadata_document = file("saml-metadata.xml")
13+
}
14+
1015
###############################
1116
# IAM assumable roles with SAML
1217
###############################
@@ -24,6 +29,23 @@ module "iam_assumable_roles_with_saml" {
2429
provider_id = aws_iam_saml_provider.idp_saml.id
2530
}
2631

32+
###############################
33+
# IAM assumable roles with SAML
34+
###############################
35+
36+
module "iam_assumable_roles_with_saml_second_provider" {
37+
source = "../../modules/iam-assumable-roles-with-saml"
38+
39+
create_admin_role = true
40+
41+
create_poweruser_role = true
42+
poweruser_role_name = "developer"
43+
44+
create_readonly_role = true
45+
46+
provider_ids = [aws_iam_saml_provider.idp_saml.id, aws_iam_saml_provider.second_idp_saml.id]
47+
}
48+
2749
#################################################################
2850
# Create custom role with SAML idp trust and additional policies
2951
#################################################################

modules/iam-assumable-roles-with-saml/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ Creates predefined IAM roles (admin, poweruser and readonly) which can be assume
4040
| poweruser\_role\_permissions\_boundary\_arn | Permissions boundary ARN to use for poweruser role | `string` | `""` | no |
4141
| poweruser\_role\_policy\_arns | List of policy ARNs to use for poweruser role | `list(string)` | <pre>[<br> "arn:aws:iam::aws:policy/PowerUserAccess"<br>]</pre> | no |
4242
| poweruser\_role\_tags | A map of tags to add to poweruser role resource. | `map(string)` | `{}` | no |
43-
| provider\_id | ID of the SAML Provider | `string` | n/a | yes |
43+
| provider\_id | ID of the SAML Provider. Use provider\_ids to specify several IDs. | `string` | `""` | no |
44+
| provider\_ids | List of SAML Provider IDs | `list(string)` | `[]` | no |
4445
| readonly\_role\_name | IAM role with readonly access | `string` | `"readonly"` | no |
4546
| readonly\_role\_path | Path of readonly IAM role | `string` | `"/"` | no |
4647
| readonly\_role\_permissions\_boundary\_arn | Permissions boundary ARN to use for readonly role | `string` | `""` | no |

modules/iam-assumable-roles-with-saml/main.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
locals {
2+
identifiers = compact(distinct(concat(var.provider_ids, [var.provider_id])))
3+
}
4+
15
data "aws_iam_policy_document" "assume_role_with_saml" {
26
statement {
37
effect = "Allow"
48

59
actions = ["sts:AssumeRoleWithSAML"]
610

711
principals {
8-
type = "Federated"
9-
identifiers = [var.provider_id]
12+
type = "Federated"
13+
14+
identifiers = local.identifiers
1015
}
1116

1217
condition {

modules/iam-assumable-roles-with-saml/variables.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
variable "provider_id" {
2-
description = "ID of the SAML Provider"
2+
description = "ID of the SAML Provider. Use provider_ids to specify several IDs."
33
type = string
4+
default = ""
5+
}
6+
7+
variable "provider_ids" {
8+
description = "List of SAML Provider IDs"
9+
type = list(string)
10+
default = []
411
}
512

613
variable "aws_saml_endpoint" {

0 commit comments

Comments
 (0)