Skip to content

Commit 2e9cacc

Browse files
authored
feat: Add support for cross account access in iam-assumable-role-with-oidc (#158)
1 parent af08c47 commit 2e9cacc

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

modules/iam-assumable-role-with-oidc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ No modules.
4343
| <a name="input_force_detach_policies"></a> [force\_detach\_policies](#input\_force\_detach\_policies) | Whether policies should be detached from this role when destroying | `bool` | `false` | no |
4444
| <a name="input_max_session_duration"></a> [max\_session\_duration](#input\_max\_session\_duration) | Maximum CLI/API session duration in seconds between 3600 and 43200 | `number` | `3600` | no |
4545
| <a name="input_number_of_role_policy_arns"></a> [number\_of\_role\_policy\_arns](#input\_number\_of\_role\_policy\_arns) | Number of IAM policies to attach to IAM role | `number` | `null` | no |
46+
| <a name="input_oidc_fully_qualified_audiences"></a> [oidc\_fully\_qualified\_audiences](#input\_oidc\_fully\_qualified\_audiences) | The audience to be added to the role policy. Set to sts.amazonaws.com for cross-account assumable role. Leave empty otherwise. | `set(string)` | `[]` | no |
4647
| <a name="input_oidc_fully_qualified_subjects"></a> [oidc\_fully\_qualified\_subjects](#input\_oidc\_fully\_qualified\_subjects) | The fully qualified OIDC subjects to be added to the role policy | `set(string)` | `[]` | no |
4748
| <a name="input_oidc_subjects_with_wildcards"></a> [oidc\_subjects\_with\_wildcards](#input\_oidc\_subjects\_with\_wildcards) | The OIDC subject using wildcards to be added to the role policy | `set(string)` | `[]` | no |
4849
| <a name="input_provider_url"></a> [provider\_url](#input\_provider\_url) | URL of the OIDC Provider. Use provider\_urls to specify several URLs. | `string` | `""` | no |

modules/iam-assumable-role-with-oidc/main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ data "aws_iam_policy_document" "assume_role_with_oidc" {
4848
values = var.oidc_subjects_with_wildcards
4949
}
5050
}
51+
52+
dynamic "condition" {
53+
for_each = length(var.oidc_fully_qualified_audiences) > 0 ? local.urls : []
54+
55+
content {
56+
test = "StringLike"
57+
variable = "${statement.value}:aud"
58+
values = var.oidc_fully_qualified_audiences
59+
}
60+
}
5161
}
5262
}
5363
}

modules/iam-assumable-role-with-oidc/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ variable "oidc_subjects_with_wildcards" {
8989
default = []
9090
}
9191

92+
variable "oidc_fully_qualified_audiences" {
93+
description = "The audience to be added to the role policy. Set to sts.amazonaws.com for cross-account assumable role. Leave empty otherwise."
94+
type = set(string)
95+
default = []
96+
}
97+
9298
variable "force_detach_policies" {
9399
description = "Whether policies should be detached from this role when destroying"
94100
type = bool

0 commit comments

Comments
 (0)