Skip to content

For each fun #9

Open
wants to merge 2 commits into
base: tf-upgrade
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
# rev: v1.31.0
rev: v1.47.0
rev: v1.96.2
hooks:
# - id: terraform_validate
- id: terraform_validate
- id: terraform_fmt
- id: terraform_docs_replace
args: ['table']
# exclude: common/*.tf
# exclude: version.tf

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
rev: v5.0.0
hooks:
- id: check-symlinks
- id: detect-aws-credentials
# - id: detect-aws-credentials
- id: detect-private-key
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ module "myrole3" {

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.66.0 |
| <a name="provider_external"></a> [external](#provider\_external) | >= 2.2.0 |
| <a name="provider_ldap"></a> [ldap](#provider\_ldap) | >= 0.5.4 |
| <a name="provider_null"></a> [null](#provider\_null) | n/a |
| <a name="provider_template"></a> [template](#provider\_template) | n/a |
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.74.0 |
| <a name="provider_external"></a> [external](#provider\_external) | 2.3.4 |
| <a name="provider_ldap"></a> [ldap](#provider\_ldap) | 0.5.4 |
| <a name="provider_null"></a> [null](#provider\_null) | 3.2.3 |
| <a name="provider_template"></a> [template](#provider\_template) | 2.2.0 |

## Modules

Expand Down
11 changes: 6 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@
#* ec2_attached_policies = []

locals {
account_id = var.account_id != "" ? var.account_id : data.aws_caller_identity.current.account_id
region = data.aws_region.current.name
account_environment = data.aws_arn.current.partition == "aws-us-gov" ? "gov" : "ew"
account_alias = var.account_alias != "" && var.account_alias != null ? var.account_alias : "none"
account_id = var.account_id != "" ? var.account_id : data.aws_caller_identity.current.account_id
region = data.aws_region.current.name
account_environment = data.aws_arn.current.partition == "aws-us-gov" ? "gov" : "ew"
account_alias = var.account_alias != "" && var.account_alias != null ? var.account_alias : "none"
attached_policies_map = { for idx, policy in var.attached_policies : idx => policy }
Copy link
Contributor

Choose a reason for hiding this comment

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

This statement will create in essence a count problem with sorting. Use it this way please:

attached_policies_map = { for p in var.attached_policies : p => p }

This is also the prior behavior. Otherwise, you'll end up with a lot of resources being deleted and recreated because you're changing the key.


# _ec2_role_name = var.ec2_role_name != "" ? var.ec2_role_name : var.role_name
role_name = format("%v%v", lookup(local._prefixes, "role", ""), var.role_name)
Expand Down Expand Up @@ -183,7 +184,7 @@ resource "aws_iam_role" "role" {
}

resource "aws_iam_role_policy_attachment" "role" {
for_each = var.create ? toset(var.attached_policies) : toset([])
for_each = var.create ? local.attached_policies_map : toset([])
Copy link
Contributor

Choose a reason for hiding this comment

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

The false type of this has to match the true type. Change

: toset([])
: {}

role = var.create ? aws_iam_role.role[0].name : ""
policy_arn = each.value
}
Expand Down