Skip to content

Commit 60e5d33

Browse files
committed
chore: update from testing and validation, add note on main README
1 parent e6545ab commit 60e5d33

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

README.md

+33
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,39 @@ Terraform module which creates AWS EKS (Kubernetes) resources
1818
- Support for providing maps of node groups/Fargate profiles to the cluster module definition or use separate node group/Fargate profile sub-modules
1919
- Provisions to provide node group/Fargate profile "default" settings - useful for when creating multiple node groups/Fargate profiles where you want to set a common set of configurations once, and then individual control only select features
2020

21+
### ℹ️ `Error: Invalid for_each argument ...`
22+
23+
Users may encounter an error such as `Error: Invalid for_each argument - The "for_each" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around this, use the -target argument to first apply ...`
24+
25+
This error is due to an upstream issue with [Terraform core](https://github.com/hashicorp/terraform/issues/4149). There are two potential options you can take to help mitigate this issue:
26+
27+
1. Create the dependent resources before the cluster => `terraform apply --target <your policy or your security group>` and then `terraform apply` for the cluster (or other similar means to just ensure the referenced resources exist before creating the cluster)
28+
- Note: this is the route users will have to take for adding additonal security groups to nodes since there isn't a separate "security group attachment" resource
29+
2. For addtional IAM policies, users can attach the policies outside of the cluster definition as demonstrated below
30+
31+
```hcl
32+
resource "aws_iam_role_policy_attachment" "additional" {
33+
for_each = module.eks.eks_managed_node_groups
34+
# you could also do the following or any comibination:
35+
# for_each = merge(
36+
# module.eks.eks_managed_node_groups,
37+
# module.eks.self_managed_node_group,
38+
# module.eks.fargate_profile,
39+
# )
40+
41+
# This policy does not have to exist at the time of cluster creation. Terraform can deduce
42+
# the proper order of its creation to avoid errors during creation
43+
policy_arn = aws_iam_policy.node_additional.arn
44+
role = each.value.iam_role_name
45+
}
46+
```
47+
48+
The tl;dr for this issue is that the Terraform resource passed into the modules map definition *must* be known before you can apply the EKS module. The variables this potentially affects are:
49+
50+
- `cluster_security_group_additional_rules` (i.e. - referencing an external security group resource in a rule)
51+
- `node_security_group_additional_rules` (i.e. - referencing an external security group resource in a rule)
52+
- `iam_role_additional_policies` (i.e. - referencing an external policy resource)
53+
2154
## Usage
2255

2356
```hcl

examples/eks_managed_node_group/main.tf

+1-2
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ module "eks" {
270270
tags = local.tags
271271
}
272272

273-
274273
# References to resources that do not exist yet when creating a cluster will cause a plan failure due to https://github.com/hashicorp/terraform/issues/4149
275274
# There are two options users can take
276275
# 1. Create the dependent resources before the cluster => `terraform apply --target <your policy or your security group> and then `terraform apply`
@@ -280,7 +279,7 @@ resource "aws_iam_role_policy_attachment" "additional" {
280279
for_each = module.eks.eks_managed_node_groups
281280

282281
policy_arn = aws_iam_policy.node_additional.arn
283-
role = each.value.iam_role_arn
282+
role = each.value.iam_role_name
284283
}
285284

286285
################################################################################

modules/eks-managed-node-group/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ module "eks_managed_node_group" {
139139
| <a name="input_post_bootstrap_user_data"></a> [post\_bootstrap\_user\_data](#input\_post\_bootstrap\_user\_data) | User data that is appended to the user data script after of the EKS bootstrap script. Not used when `platform` = `bottlerocket` | `string` | `""` | no |
140140
| <a name="input_pre_bootstrap_user_data"></a> [pre\_bootstrap\_user\_data](#input\_pre\_bootstrap\_user\_data) | User data that is injected into the user data script ahead of the EKS bootstrap script. Not used when `platform` = `bottlerocket` | `string` | `""` | no |
141141
| <a name="input_ram_disk_id"></a> [ram\_disk\_id](#input\_ram\_disk\_id) | The ID of the ram disk | `string` | `null` | no |
142-
| <a name="input_remote_access"></a> [remote\_access](#input\_remote\_access) | Configuration block with remote access settings | `map(string)` | `{}` | no |
142+
| <a name="input_remote_access"></a> [remote\_access](#input\_remote\_access) | Configuration block with remote access settings | `any` | `{}` | no |
143143
| <a name="input_security_group_description"></a> [security\_group\_description](#input\_security\_group\_description) | Description for the security group created | `string` | `"EKS managed node group security group"` | no |
144144
| <a name="input_security_group_name"></a> [security\_group\_name](#input\_security\_group\_name) | Name to use on security group created | `string` | `null` | no |
145145
| <a name="input_security_group_rules"></a> [security\_group\_rules](#input\_security\_group\_rules) | List of security group rules to add to the security group created | `any` | `{}` | no |

modules/eks-managed-node-group/variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ variable "launch_template_version" {
334334

335335
variable "remote_access" {
336336
description = "Configuration block with remote access settings"
337-
type = map(string)
337+
type = any
338338
default = {}
339339
}
340340

0 commit comments

Comments
 (0)