Skip to content

Commit afc9ffa

Browse files
authored
feat: Fixed number of policies everywhere (#121)
1 parent 70e7898 commit afc9ffa

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

examples/iam-assumable-role/main.tf

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,33 @@ module "iam_assumable_role_custom" {
5353
custom_role_policy_arns = [
5454
"arn:aws:iam::aws:policy/AmazonCognitoReadOnly",
5555
"arn:aws:iam::aws:policy/AlexaForBusinessFullAccess",
56+
module.iam_policy.arn
5657
]
57-
number_of_custom_role_policy_arns = 2
58+
# number_of_custom_role_policy_arns = 3
59+
}
60+
61+
#########################################
62+
# IAM policy
63+
#########################################
64+
module "iam_policy" {
65+
source = "../../modules/iam-policy"
66+
67+
name = "example"
68+
path = "/"
69+
description = "My example policy"
70+
71+
policy = <<EOF
72+
{
73+
"Version": "2012-10-17",
74+
"Statement": [
75+
{
76+
"Action": [
77+
"ec2:Describe*"
78+
],
79+
"Effect": "Allow",
80+
"Resource": "*"
81+
}
82+
]
83+
}
84+
EOF
5885
}

modules/iam-assumable-role/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +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 IAM policies to attach to IAM role | `number` | `0` | no |
35+
| number\_of\_custom\_role\_policy\_arns | Number of IAM policies to attach to IAM role | `number` | `null` | no |
3636
| poweruser\_role\_policy\_arn | Policy ARN to use for poweruser role | `string` | `"arn:aws:iam::aws:policy/PowerUserAccess"` | no |
3737
| readonly\_role\_policy\_arn | Policy ARN to use for readonly role | `string` | `"arn:aws:iam::aws:policy/ReadOnlyAccess"` | no |
3838
| 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 ? var.number_of_custom_role_policy_arns : 0
75+
count = var.create_role ? coalesce(var.number_of_custom_role_policy_arns, length(var.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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ variable "custom_role_policy_arns" {
7979
variable "number_of_custom_role_policy_arns" {
8080
description = "Number of IAM policies to attach to IAM role"
8181
type = number
82-
default = 0
82+
default = null
8383
}
8484

8585
# Pre-defined policies

0 commit comments

Comments
 (0)