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

Tags are not propagated on nodegroup ASG #860

Closed
3 tasks
amitsehgal opened this issue May 5, 2020 · 8 comments
Closed
3 tasks

Tags are not propagated on nodegroup ASG #860

amitsehgal opened this issue May 5, 2020 · 8 comments

Comments

@amitsehgal
Copy link

amitsehgal commented May 5, 2020

I have added additional tags on node groups and they are not propagated to ASG or EC2.

I'm submitting a...

  • [ * ] bug report
  • feature request
  • support request - read the FAQ first!
  • kudos, thank you, warm fuzzy

What is the current behavior?

Tags does not propagate

If this is a bug, how to reproduce? Please include a code sample if relevant.

add tags like above
locals {
common_tags = {
bu = "bu"
envType = var.envType
stackType = "terraform"
}
}
.
.
.
.

node_groups_defaults = {
ami_type = "AL2_x86_64"
disk_size = 50
subnets = split(",",var.private_subnet_ids)
additional_tags = "${merge(
local.common_tags,
map(
"k8s.io/cluster-autoscaler/${local.cluster_name}", "owned",
"k8s.io/cluster-autoscaler/enabled","true",
"stackType", "terraform"
)
)}"
}

What's the expected behavior?

Tags should appear on ASG or EC2

Are you able to fix this problem and submit a PR? Link here if you have already.

No

Environment details

Terraform v0.12.24

terraform-aws-eks 11.0.0

  • Affected module version:
  • OS:
  • Terraform version:

Any other relevant info

@rekcah78
Copy link

rekcah78 commented May 6, 2020

this not a eks terraform module bug but AWS implementation for the managed nodes:

see: https://docs.aws.amazon.com/eks/latest/userguide/create-managed-node-group.html

Tags — (Optional) You can choose to tag your Amazon EKS managed node group. These tags do not propagate to other resources in the node group, such as Auto Scaling groups or instances. For more information, see Tagging your Amazon EKS resources.

@rekcah78
Copy link

rekcah78 commented May 6, 2020

aws/containers-roadmap#608

@atrepca
Copy link

atrepca commented May 22, 2020

For anyone looking for a workaround:

locals {
  asg_name = module.eks.node_groups["default"]["resources"][0]["autoscaling_groups"][0]["name"]
}

resource "null_resource" "add_custom_tags_to_asg" {
  triggers = {
    node_group = local.asg_name
  }
  provisioner "local-exec" {
    command = <<EOF
aws autoscaling create-or-update-tags \
  --tags ResourceId=${local.asg_name},ResourceType=auto-scaling-group,Key=CUSTOM_TAG_NAME,Value=CUSTOM_TAG_VALUE,PropagateAtLaunch=true
EOF
  }
}

You can add multiple tags; newly launched nodes will get the custom tags, thanks to PropagateAtLaunch=true.

@amitsehgal
Copy link
Author

amitsehgal commented May 29, 2020

it worked..thanks

@mteodori
Copy link

is the workaround above still needed?

@smartm13
Copy link

Thanks @atrepca for the quick WA.
To top it off, I appended && aws autoscaling start-instance-refresh --auto-scaling-group-name ${local.asg_name} --region ${var.region} to your local-exec.
This way, the old instances without tags gets immediately replaced with new correctly tagged ones.

FYI: I have also added this null_resource.add_custom_tags_to_asg in depends_on of further resources so that they start working on refreshed node group only.

And

is the workaround above still needed?

Unfortunately yes @mteodori, its still needed, additional_tags for managed node groups still wont propagate to ec2 out-of-the-box.

kingatlas added a commit to edgeimpulse/terraform-aws-eks that referenced this issue May 26, 2021
@gagarinfan
Copy link

Hi. I've similar problem but while having more than one node_group it gets more complicated to apply @atrepca 's solution. Maybe someone will find it useful.

Use case:

  • more than 1 node group (in my case 6)
  • a few tags in locals as map (5)

I need to iterate over each node_group and map with tags to apply all of them to every group.

resource "null_resource" "add_custom_tags_to_asg" {
  for_each = module.eks.node_groups


  provisioner "local-exec" {
    command = <<EOF
      %{ for tagName,tagValue in local.tags }
        aws autoscaling create-or-update-tags --tags \
        ResourceId=${each.value.resources[0].autoscaling_groups[0].name},\
        ResourceType=auto-scaling-group,\
        Key=${tagName},\
        Value=${tagValue},\
        PropagateAtLaunch=true
      %{ endfor ~}
    EOF
  }
}

@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 20, 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

6 participants