Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: simplify count statements #93

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/iam-assumable-role-with-oidc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ resource "aws_iam_role" "this" {
}

resource "aws_iam_role_policy_attachment" "custom" {
count = var.create_role && length(var.role_policy_arns) > 0 ? length(var.role_policy_arns) : 0
count = var.create_role ? length(var.role_policy_arns) : 0

role = join("", aws_iam_role.this.*.name)
policy_arn = var.role_policy_arns[count.index]
Expand Down
2 changes: 1 addition & 1 deletion modules/iam-assumable-role/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ resource "aws_iam_role" "this" {
}

resource "aws_iam_role_policy_attachment" "custom" {
count = var.create_role && length(var.custom_role_policy_arns) > 0 ? length(var.custom_role_policy_arns) : 0
count = var.create_role ? length(var.custom_role_policy_arns) : 0

role = aws_iam_role.this[0].name
policy_arn = element(var.custom_role_policy_arns, count.index)
Expand Down
6 changes: 3 additions & 3 deletions modules/iam-group-with-policies/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ resource "aws_iam_group_policy_attachment" "iam_self_management" {
}

resource "aws_iam_group_policy_attachment" "custom_arns" {
count = length(var.custom_group_policy_arns) > 0 ? length(var.custom_group_policy_arns) : 0
count = length(var.custom_group_policy_arns)

group = local.group_name
policy_arn = element(var.custom_group_policy_arns, count.index)
}

resource "aws_iam_group_policy_attachment" "custom" {
count = length(var.custom_group_policies) > 0 ? length(var.custom_group_policies) : 0
count = length(var.custom_group_policies)

group = local.group_name
policy_arn = element(aws_iam_policy.custom.*.arn, count.index)
Expand All @@ -51,7 +51,7 @@ resource "aws_iam_policy" "iam_self_management" {
}

resource "aws_iam_policy" "custom" {
count = length(var.custom_group_policies) > 0 ? length(var.custom_group_policies) : 0
count = length(var.custom_group_policies)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good - might be worth considering a refactor to for_each with an array of maps. just food for thought

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ill go over he module and see where this refactor is needed. i wanted to make changes more incremental


name = var.custom_group_policies[count.index]["name"]
policy = var.custom_group_policies[count.index]["policy"]
Expand Down