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

Moving the conditional out of the for_each #2388

Closed
wants to merge 1 commit into from

Conversation

wpbeckwith
Copy link

Description

Currently by having the conditional check in the for_each terraform will fail to plan with the dreaded "Error: Invalid for_each argument" error. This happens even if you are not trying to use the module provided role. Moving the conditional check out allows terraform to plan successfully.

Motivation and Context

#2337

Breaking Changes

No

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects

I have added the following to the bottom of the examples/eks_managed_node_group/main.tf


module "foo_mng" {
  source  = "../../modules/eks-managed-node-group"

  name            = "foo"
  cluster_name    = "foo"
  cluster_version = "1.24"
  create_iam_role = false
  iam_role_arn    = "arn:aws:iam::123456789012:role/foo-eks-node-group"

 cluster_primary_security_group_id = module.eks.node_security_group_id

  subnet_ids             = module.vpc.private_subnets
  min_size               = 1
  desired_size           = 1
  max_size               = 1
  instance_types         = ["t3.large"]
}

With the above, the example continues to plan successfully. In my env, the PR change allows me to successfully plan and create a cluster while the previous code caused a for_each plan failure.

  • I have executed pre-commit run -a on my pull request

Currently by having the conditional check in the for_each terraform will fail to plan with the dreaded "Error: Invalid for_each argument" error.  This happens even if you are not trying to use the module provided role.  Moving the conditional check out allows terraform to plan successfully.
@bryantbiggs
Copy link
Member

This is not the correct way

@bryantbiggs bryantbiggs closed this Jan 8, 2023
@wpbeckwith
Copy link
Author

What is not the correct way? I forked the repo, made a change and then opened a PR to send the change back. What's incorrect?

@bryantbiggs
Copy link
Member

bryantbiggs commented Jan 8, 2023

The current implementation is the correct form. This form raises issues with inconsistent types

@wpbeckwith
Copy link
Author

Not trying to be extra dense, but I'm not following. Can you clarify a bit more what you mean by the "This form raises issues with inconsistent types"? The PR does not change any types, so that's what is confusing.

@wpbeckwith
Copy link
Author

Regardless, I see reading back on the PR while the code may be correct I have since created a better example of the issue in repo https://github.com/wpbeckwith/terraform-aws-eks-2337. So a more accurate PR should be created.

@sanarena
Copy link

This patch worked for me, I will be using this patch until official AWS module fix this issue. @bryantbiggs

@sanarena sanarena mentioned this pull request Jan 10, 2023
1 task
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants