Skip to content

Commit f34e103

Browse files
authored
feat: Added number_of_ variables for iam-assumable-role submodules (#96)
1 parent cf8f3cc commit f34e103

File tree

8 files changed

+19
-2
lines changed

8 files changed

+19
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module "iam_assumable_role_admin" {
2222
role_policy_arns = [
2323
"arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy",
2424
]
25+
number_of_role_policy_arns = 1
2526

2627
oidc_fully_qualified_subjects = ["system:serviceaccount:default:sa1", "system:serviceaccount:default:sa2"]
2728
}

examples/iam-assumable-role/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ module "iam_assumable_role_custom" {
5454
"arn:aws:iam::aws:policy/AmazonCognitoReadOnly",
5555
"arn:aws:iam::aws:policy/AlexaForBusinessFullAccess",
5656
]
57+
number_of_custom_role_policy_arns = 2
5758
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ This module supports IAM Roles for kubernetes service accounts as described in t
2828
| create\_role | Whether to create a role | `bool` | `false` | no |
2929
| force\_detach\_policies | Whether policies should be detached from this role when destroying | `bool` | `false` | no |
3030
| max\_session\_duration | Maximum CLI/API session duration in seconds between 3600 and 43200 | `number` | `3600` | no |
31+
| number\_of\_role\_policy\_arns | Number of custom policies passed to variable role\_policy\_arns | `number` | `0` | no |
3132
| oidc\_fully\_qualified\_subjects | The fully qualified OIDC subjects to be added to the role policy | `set(string)` | `[]` | no |
3233
| oidc\_subjects\_with\_wildcards | The OIDC subject using wildcards to be added to the role policy | `set(string)` | `[]` | no |
3334
| 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ resource "aws_iam_role" "this" {
6868
}
6969

7070
resource "aws_iam_role_policy_attachment" "custom" {
71-
count = var.create_role ? length(var.role_policy_arns) : 0
71+
count = var.create_role ? var.number_of_role_policy_arns : 0
7272

7373
role = join("", aws_iam_role.this.*.name)
7474
policy_arn = var.role_policy_arns[count.index]

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ variable "role_policy_arns" {
7070
default = []
7171
}
7272

73+
variable "number_of_role_policy_arns" {
74+
description = "Number of IAM policies to attach to IAM role"
75+
type = number
76+
default = 0
77+
}
78+
79+
7380
variable "oidc_fully_qualified_subjects" {
7481
description = "The fully qualified OIDC subjects to be added to the role policy"
7582
type = set(string)

modules/iam-assumable-role/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Trusted resources can be any [IAM ARNs](https://docs.aws.amazon.com/IAM/latest/U
3232
| force\_detach\_policies | Whether policies should be detached from this role when destroying | `bool` | `false` | no |
3333
| max\_session\_duration | Maximum CLI/API session duration in seconds between 3600 and 43200 | `number` | `3600` | no |
3434
| mfa\_age | Max age of valid MFA (in seconds) for roles which require MFA | `number` | `86400` | no |
35+
| number\_of\_custom\_role\_policy\_arns | Number of custom policies passed to variable custom\_role\_policy\_arns | `number` | `0` | no |
3536
| poweruser\_role\_policy\_arn | Policy ARN to use for poweruser role | `string` | `"arn:aws:iam::aws:policy/PowerUserAccess"` | no |
3637
| readonly\_role\_policy\_arn | Policy ARN to use for readonly role | `string` | `"arn:aws:iam::aws:policy/ReadOnlyAccess"` | no |
3738
| role\_description | IAM Role description | `string` | `""` | no |

modules/iam-assumable-role/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ resource "aws_iam_role" "this" {
7272
}
7373

7474
resource "aws_iam_role_policy_attachment" "custom" {
75-
count = var.create_role ? length(var.custom_role_policy_arns) : 0
75+
count = var.create_role ? var.number_of_custom_role_policy_arns : 0
7676

7777
role = aws_iam_role.this[0].name
7878
policy_arn = element(var.custom_role_policy_arns, count.index)

modules/iam-assumable-role/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ variable "custom_role_policy_arns" {
7676
default = []
7777
}
7878

79+
variable "number_of_custom_role_policy_arns" {
80+
description = "Number of IAM policies to attach to IAM role"
81+
type = number
82+
default = 0
83+
}
84+
7985
# Pre-defined policies
8086
variable "admin_role_policy_arn" {
8187
description = "Policy ARN to use for admin role"

0 commit comments

Comments
 (0)