Skip to content

Commit

Permalink
Merge pull request #24 from mineiros-io/mariux/fix-computed-policy-arns
Browse files Browse the repository at this point in the history
fix: Add support for using computed values in policy_arns
  • Loading branch information
mariux authored Aug 26, 2021
2 parents de30667 + ad96df5 commit bece2bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.5.1]

### Fixed

- Add support for using computed values in `policy_arns` argument.

## [0.5.0]

### Added
Expand Down Expand Up @@ -83,11 +89,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- markdown-link-check-disable -->

[unreleased]: https://github.com/mineiros-io/terraform-aws-iam-user/compare/v0.5.0...HEAD
[0.5.0]: https://github.com/mineiros-io/terraform-aws-iam-user/compare/v0.4.0...v0.5.0
[unreleased]: https://github.com/mineiros-io/terraform-aws-iam-user/compare/v0.5.1...HEAD
[0.5.1]: https://github.com/mineiros-io/terraform-aws-iam-user/compare/v0.5.0...v0.5.1

<!-- markdown-link-check-disabled -->

[0.5.0]: https://github.com/mineiros-io/terraform-aws-iam-user/compare/v0.4.0...v0.5.0
[0.4.0]: https://github.com/mineiros-io/terraform-aws-iam-user/compare/v0.3.0...v0.4.0
[0.3.0]: https://github.com/mineiros-io/terraform-aws-iam-user/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/mineiros-io/terraform-aws-iam-user/compare/v0.1.0...v0.2.0
Expand Down
15 changes: 11 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,22 @@ resource "aws_iam_user_policy" "policy" {
}

locals {
policy_arns = tolist(setproduct(var.names, var.policy_arns))
policy_attachments = flatten([
for user in var.names : [
for policy in var.policy_arns : {
user = user
policy_arn = policy
}
]
])
}

# Attach custom or managed policies
resource "aws_iam_user_policy_attachment" "policy" {
count = var.module_enabled ? length(local.policy_arns) : 0
count = var.module_enabled ? length(local.policy_attachments) : 0

user = local.policy_arns[count.index][0]
policy_arn = local.policy_arns[count.index][1]
user = local.policy_attachments[count.index].user
policy_arn = local.policy_attachments[count.index].policy_arn

depends_on = [
var.module_depends_on,
Expand Down

0 comments on commit bece2bf

Please sign in to comment.