-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Optional Create before destroy. Add Launch Template and related features. #31
Conversation
/test all |
/terraform-fmt |
/test all |
/test all |
/test all |
/test all |
/test all |
|
||
need_userdata = (var.userdata_override == null) && (length(local.userdata_vars.before_cluster_joining_userdata) > 0) || local.need_bootstrap | ||
|
||
userdata = local.need_userdata ? base64encode(templatefile("${path.module}/userdata.tpl", merge(local.userdata_vars, local.cluster_data))) : var.userdata_override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should instead use https://registry.terraform.io/providers/hashicorp/cloudinit/latest/docs/data-sources/cloudinit_config that is designed for things like user_data.
Definitely lots of complexity, but understandably so -- I was able to successfully test and confirm some of the functionality. Looks good to me! |
// 3. data.eks_cluster.this.kubernetes_version | ||
need_cluster_kubernetes_version = local.need_ami_id && length(compact([var.ami_release_version, var.kubernetes_version])) == 0 | ||
|
||
ami_kubernetes_version = local.need_ami_id ? (local.need_cluster_kubernetes_version ? data.aws_eks_cluster.this[0].version : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try(data.aws_eks_cluster.this[0].version, "")
otherwise it will fail when enabled=false
launch_template_version = local.use_launch_template ? ( | ||
length(local.configured_launch_template_version) > 0 ? local.configured_launch_template_version : | ||
( | ||
length(local.configured_launch_template_name) > 0 ? data.aws_launch_template.this[0].latest_version : aws_launch_template.default[0].latest_version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
length(local.configured_launch_template_name) > 0 ? try(data.aws_launch_template.this[0].latest_version, "") : try(aws_launch_template.default[0].latest_version, "")
id = coalesce(var.launch_template_id, aws_launch_template.default[0].id) | ||
latest_version = coalesce(var.launch_template_version, aws_launch_template.default[0].latest_version) | ||
} | ||
data "aws_eks_cluster" "this" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before, the pattern was to name a single resource default
.
this
would be good as well, we just have two naming conventions now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to use "this" in new modules rather than default, and for backward compatibility and consistency mostly continued to use "default", but here referring to the "default cluster" just seemed confusing and wrong.
} | ||
|
||
cluster_data = { | ||
cluster_endpoint = local.get_cluster_data ? data.aws_eks_cluster.this[0].endpoint : null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try(data.aws_eks_cluster.this[0].endpoint, "")
} | ||
|
||
output "eks_node_group_arn" { | ||
description = "Amazon Resource Name (ARN) of the EKS Node Group" | ||
value = join("", aws_eks_node_group.default.*.arn) | ||
value = join("", aws_eks_node_group.default.*.arn, aws_eks_node_group.cbd.*.arn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it work with two lists?
according to the docs, join
takes a delimiter and a list
https://www.terraform.io/docs/configuration/functions/join.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, not documented properly, but in TF 0.13 it is join(string, list...)
> join(", ", ["one"], ["two", "three"], ["blue"])
one, two, three, blue
} | ||
|
||
output "eks_node_group_status" { | ||
description = "Status of the EKS Node Group" | ||
value = join("", aws_eks_node_group.default.*.status) | ||
value = join("", aws_eks_node_group.default.*.status, aws_eks_node_group.cbd.*.status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it work with two lists?
according to the docs, join
takes a delimiter and a list
https://www.terraform.io/docs/configuration/functions/join.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it works
what
Implement "create before destroy" for zero downtime node group updates. This is optional and off by default, because on first use it will cause any existing node groups created with this module to be destroyed and then replaced, causing the same kind of outage this feature will prevent after it is activated.
Add features previously missing here but present in terraform-aws-eks-workers, to the extent supported by AWS, such as
bootstrap.sh
optionskubelet
optionswhy
create_before_destroy = true
.caveats
When using create before destroy
We cannot automatically detect when the node_group will be destroyed and generate a new name for it. Instead, we have tried to cause a new name to be generated when anything changes that would cause a the node group to be destroyed. This may not be perfect. If the name changes unnecessarily, it will trigger a node group replacement, which should be tolerable. If the name fails to change when it needs to, the Terraform
apply
will fail with an error about the resource already existing. Please let us know what change we missed so we can update the module. Meanwhile, you can get around this by manually "tainting" therandom_pet
as explained below.For a short period of time you will be running 2 node groups.
minAvailable: 25%
(which rounds up tominAvailable: 1
), preventing the pod from being drained from a node, you may have issues with node groups being replaced.random_pet
resource because while Terraform tries to replace the tainted new node group, it will try to do so with the same name (and fail) unless you also taintrandom_pet
. Assuming you invoked the module asmodule "eks_node_group"
, you would taintrandom_pet
withUsing new features
Many of the new features of this module rely on new AWS features, and it is unclear to what extent they actually work.
Most of the new features require this module to create a Launch Template, and of course you can now supply your own launch template (referenced by name). There is some overlap between settings that can be made directly on an EKS managed node group and some that can be made in a launch template. This results in settings being allowed in one place and not in the other: these limitations and prohibitions are detailed in the AWS documentation. This module attempts to resolve these differences in many cases, but some limitations remain:
ec2_ssh_key
settingnull
.bootstrap.sh
, most of the new features will not work. You will need to implement them yourself on your AMI. You can provide arbitrary (Base64 encoded) User Data to your AMI viauserdata_override
.subnet_ids
and the module will apply the via the node group configuration.references
Many of the new features are made possible by EKS adding support for launch templates.