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

Not able to tag autoscaling group created by EKS Managed Node Group #2128

Closed
sparsh-anurag opened this issue Jun 29, 2022 · 3 comments
Closed

Comments

@sparsh-anurag
Copy link

sparsh-anurag commented Jun 29, 2022

HI, I am trying to use this code in order to tag asg group, it is working when all the resources are already created. but when I am trying to run it from scratch I am getting this error

│ Error: Invalid for_each argument

│ on modules/eks/main.tf line 144, in resource "aws_autoscaling_group_tag" "example":
│ 144: for_each = toset(
│ 145: [for asg in flatten(
│ 146: [for resources in aws_eks_node_group.worker-nodes.resources : resources.autoscaling_groups]
│ 147: ) : asg.name]
│ 148: )
│ ├────────────────
│ │ aws_eks_node_group.worker-nodes.resources is a list of object, known only after apply

│ 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 only the resources that the for_each depends on.

The code block which I am using

resource "aws_autoscaling_group_tag" "example" {
for_each = toset(
[for asg in flatten(
[for resources in aws_eks_node_group.worker-nodes.resources : resources.autoscaling_groups]
) : asg.name]
)

autoscaling_group_name = each.value

tag {
key = "Name"
value = "Worker"
propagate_at_launch = true
}
depends_on = [
aws_eks_node_group.worker-nodes,
aws_eks_cluster.eks,

]
}

@prateekn
Copy link

You can try the method mentioned in the example section ! !

@bryantbiggs
Copy link
Member

Thank you for linking @prateekn - @sparsh-anurag please see the link provided for how to achieve this

@github-actions
Copy link

I'm going to lock this issue 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 similar to this, 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 Nov 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants