diff --git a/modules/node_groups/README.md b/modules/node_groups/README.md index 10c4cba..81be4df 100644 --- a/modules/node_groups/README.md +++ b/modules/node_groups/README.md @@ -20,6 +20,7 @@ The role ARN specified in `var.default_iam_role_arn` will be used by default. In | additional\_tags | Additional tags to apply to node group | map(string) | Only `var.tags` applied | | ami\_release\_version | AMI version of workers | string | Provider default behavior | | ami\_type | AMI Type. See Terraform or AWS docs | string | Provider default behavior | +| ami\_id | ID of custom AMI. If you use a custom AMI, you need to supply bootstrap script via user-data or as AMI built-in. | string | Provider default behavior | | capacity\_type | Type of instance capacity to provision. Options are `ON_DEMAND` and `SPOT` | string | Provider default behavior | | create_launch_template | Create and use a default launch template | bool | `false` | | desired\_capacity | Desired number of workers | number | `var.workers_group_defaults[asg_desired_capacity]` | diff --git a/modules/node_groups/launch_template.tf b/modules/node_groups/launch_template.tf index 84fa755..1db5963 100644 --- a/modules/node_groups/launch_template.tf +++ b/modules/node_groups/launch_template.tf @@ -9,8 +9,10 @@ data "cloudinit_config" "workers_userdata" { content_type = "text/x-shellscript" content = templatefile("${path.module}/templates/userdata.sh.tpl", { - pre_userdata = each.value["pre_userdata"] - kubelet_extra_args = each.value["kubelet_extra_args"] + pre_userdata = each.value["pre_userdata"] + kubelet_extra_args = each.value["kubelet_extra_args"] + cluster_name = var.cluster_name + run_bootstrap_script = lookup(each.value, "ami_id", null) != null } ) } @@ -64,7 +66,7 @@ resource "aws_launch_template" "workers" { } # if you want to use a custom AMI - # image_id = var.ami_id + image_id = lookup(each.value, "ami_id", null) # If you use a custom AMI, you need to supply via user-data, the bootstrap script as EKS DOESNT merge its managed user-data then # you can add more than the minimum code you see in the template, e.g. install SSM agent, see https://github.com/aws/containers-roadmap/issues/593#issuecomment-577181345 diff --git a/modules/node_groups/templates/userdata.sh.tpl b/modules/node_groups/templates/userdata.sh.tpl index 3aecd0a..097c116 100644 --- a/modules/node_groups/templates/userdata.sh.tpl +++ b/modules/node_groups/templates/userdata.sh.tpl @@ -4,3 +4,6 @@ ${pre_userdata} sed -i '/^KUBELET_EXTRA_ARGS=/a KUBELET_EXTRA_ARGS+=" ${kubelet_extra_args}"' /etc/eks/bootstrap.sh +%{ if run_bootstrap_script } + /etc/eks/bootstrap.sh ${cluster_name} +%{ endif }