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

Worker group tags #252

Merged

Conversation

stefansedich
Copy link
Contributor

@stefansedich stefansedich commented Jan 25, 2019

PR o'clock

Description

Adding ability to configure worker group ASG tags which resolves #89

Checklist

  • terraform fmt and terraform validate both work from the root and examples/eks_test_fixture directories (look in CI for an example)
  • Tests for the changes have been added and passing (for bug fixes/features)
  • Test results are pasted in this PR (in lieu of CI)
  • I've added my change to CHANGELOG.md
  • Any breaking changes are highlighted above

@stefansedich
Copy link
Contributor Author

stefansedich commented Jan 25, 2019

Looks like I broke the build, trying to understand why and will fix it up, looks like it does not like having no elements defined and I greatly misunderstood Terraform.

@stefansedich
Copy link
Contributor Author

@max-rocket-internet looks like this may have been a fail, closing off until I can work something out, unless there are some TF hacks you know of many of the things I tried don't seem to work in 0.11 and may in 0.12, unless we had the users always defining the tags with empty arrays to match the worker group count which would not be ideal.

@stefansedich
Copy link
Contributor Author

stefansedich commented Jan 26, 2019

@max-rocket-internet ok that involved ALOT of hair pulling but the best I could think of was that by default there is always one item in the list, then we use the matching item at the worker group index if we can find it otherwise we fallback to the first item in the list, this is not ideal but I tried a million other things and this was the only way I could get it working, any thoughts if this is an acceptable hack?

@stefansedich stefansedich reopened this Jan 26, 2019
Copy link
Contributor

@max-rocket-internet max-rocket-internet left a comment

Choose a reason for hiding this comment

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

I get this error when running with defaults (not adding any extra tags):

Error: Error running plan: 1 error(s) occurred:

* module.max_test.aws_autoscaling_group.workers: 1 error(s) occurred:

* module.max_test.aws_autoscaling_group.workers: concat: unexpected type list in list of type map in:

${concat(
    list(
      map("key", "Name", "value", "${aws_eks_cluster.this.name}-${lookup(var.worker_groups[count.index], "name", count.index)}-eks_asg", "propagate_at_launch", true),
      map("key", "kubernetes.io/cluster/${aws_eks_cluster.this.name}", "value", "owned", "propagate_at_launch", true),
      map("key", "k8s.io/cluster-autoscaler/${lookup(var.worker_groups[count.index], "autoscaling_enabled", local.workers_group_defaults["autoscaling_enabled"]) == 1 ? "enabled" : "disabled"  }", "value", "true", "propagate_at_launch", false)
    ),
    local.asg_tags,
    list(var.worker_group_tags[length(var.worker_group_tags) > count.index ? count.index : "0"]))
  }

@stefansedich
Copy link
Contributor Author

stefansedich commented Jan 28, 2019

@max-rocket-internet are you just running the examples? I can successfully run a terraform plan for the examples which are using defaults.

Edit: OK I see it now :shakes-fist:, for some reason my examples run fine but spun up a blank TF file and can see the issue.

For some reason and I don't understand why the default value for the variable and an explicitly set one behave differently, if I remove the wrapping list() it works fine for defaults, but breaks when you set tags and vice versa.

… around the issue where list indexing does not work with a list of lists
@stefansedich stefansedich reopened this Jan 28, 2019
@stefansedich
Copy link
Contributor Author

stefansedich commented Jan 28, 2019

Ok @max-rocket-internet turns out I ran into hashicorp/terraform#19033, this next idea works but changes things a little, instead of having an list of lists and relying on matching up to the index, I am using a map and using the worker groups name as the key.

Now it is also slightly hacky in that by default there exists an item "default", and if you do not define tags for all your worker groups the user will need to ensure they add the default item back, but it does also allow you to easily set the tags for one group and default the rest like so it is a little more flexible.

worker_group_tags = {
  "group_a" = [],
  "default" = []
}

My apologies with the brokenness, this PR has been a big learning experience for me as TF is relatively new to me and I probably jumped the gun a little bit, lesson learnt.

@max-rocket-internet
Copy link
Contributor

OK great! I think this looks pretty tidy 🙂

Can you fix conflict and update the README using terraform-docs?

@stefansedich
Copy link
Contributor Author

Thanks @max-rocket-internet should be good to go!

Copy link
Contributor

@max-rocket-internet max-rocket-internet left a comment

Choose a reason for hiding this comment

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

Well done @stefansedich! Thanks for the effort 😃

@max-rocket-internet max-rocket-internet merged commit 35747d7 into terraform-aws-modules:master Jan 31, 2019
tekn0ir pushed a commit to tekn0ir/terraform-aws-eks that referenced this pull request Feb 13, 2019
* master:
  Release v2.2.0 (terraform-aws-modules#270)
  Add optional permissions_boundary (terraform-aws-modules#265)
  Updating example IAM docs to include Launch Template actions (terraform-aws-modules#268)
  Added write_aws_auth_config option (terraform-aws-modules#228)
  Worker group tags (terraform-aws-modules#252)
  Adding the g3s.xlarge instance type ebs optimized mapping (terraform-aws-modules#258)
  Add enabled_metrics attributes to autoscaling_group (terraform-aws-modules#256)
  Use launch template defaults for launch template userdata (terraform-aws-modules#255)
  Enable create_before_destroy for ASG and enable force_delete to be configured (terraform-aws-modules#250)
@eug-maly eug-maly mentioned this pull request Aug 1, 2019
3 tasks
@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 Nov 23, 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

Successfully merging this pull request may close these issues.

Be able to define per ASGs tags
2 participants