Skip to content

Commit 61ac930

Browse files
patrickjahnsNuru
andauthored
Fix allow several instance types (#54)
* feat: allow to specify more than a single instance type * Remove instance list from launch template Co-authored-by: Nuru <[email protected]>
1 parent caf738c commit 61ac930

File tree

8 files changed

+113
-39
lines changed

8 files changed

+113
-39
lines changed

.github/mergify.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,10 @@ pull_request_rules:
5656
changes_requested: true
5757
approved: true
5858
message: "This Pull Request has been updated, so we're dismissing all reviews."
59+
60+
- name: "close Pull Requests without files changed"
61+
conditions:
62+
- "#files=0"
63+
actions:
64+
close:
65+
message: "This pull request has been automatically closed by Mergify because there are no longer any changes."

.github/workflows/auto-format.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
jobs:
77
auto-format:
88
runs-on: ubuntu-latest
9-
container: cloudposse/build-harness:slim-latest
9+
container: cloudposse/build-harness:latest
1010
steps:
1111
# Checkout the pull request branch
1212
# "An action in a workflow run can’t trigger a new workflow run. For example, if an action pushes code using
@@ -29,6 +29,8 @@ jobs:
2929
- name: Auto Format
3030
if: github.event.pull_request.state == 'open'
3131
shell: bash
32+
env:
33+
GITHUB_TOKEN: "${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}"
3234
run: make BUILD_HARNESS_PATH=/build-harness PACKAGES_PREFER_HOST=true -f /build-harness/templates/Makefile.build-harness pr/auto-format/host
3335

3436
# Commit changes (if any) to the PR branch

.github/workflows/auto-release.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@ name: auto-release
33
on:
44
push:
55
branches:
6-
- master
6+
- master
77

88
jobs:
99
publish:
1010
runs-on: ubuntu-latest
1111
steps:
12-
# Drafts your next Release notes as Pull Requests are merged into "master"
13-
- uses: release-drafter/release-drafter@v5
14-
with:
15-
publish: true
16-
prerelease: false
17-
config-name: auto-release.yml
18-
env:
19-
GITHUB_TOKEN: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}
12+
# Get PR from merged commit to master
13+
- uses: actions-ecosystem/action-get-merged-pull-request@v1
14+
id: get-merged-pull-request
15+
with:
16+
github_token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}
17+
# Drafts your next Release notes as Pull Requests are merged into "master"
18+
- uses: release-drafter/release-drafter@v5
19+
if: "!contains(steps.get-merged-pull-request.outputs.labels, 'no-release')"
20+
with:
21+
publish: true
22+
prerelease: false
23+
config-name: auto-release.yml
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}

README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,31 @@ Available targets:
222222
| aws | >= 3.0 |
223223
| random | >= 2.0 |
224224

225+
## Modules
226+
227+
| Name | Source | Version |
228+
|------|--------|---------|
229+
| label | cloudposse/label/null | 0.24.1 |
230+
| this | cloudposse/label/null | 0.24.1 |
231+
232+
## Resources
233+
234+
| Name |
235+
|------|
236+
| [aws_ami](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) |
237+
| [aws_eks_cluster](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster) |
238+
| [aws_eks_node_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_node_group) |
239+
| [aws_iam_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) |
240+
| [aws_iam_policy_document](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) |
241+
| [aws_iam_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) |
242+
| [aws_iam_role_policy_attachment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) |
243+
| [aws_launch_template](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/launch_template) |
244+
| [aws_launch_template](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template) |
245+
| [aws_partition](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) |
246+
| [aws_security_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) |
247+
| [aws_security_group_rule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) |
248+
| [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) |
249+
225250
## Inputs
226251

227252
| Name | Description | Type | Default | Required |
@@ -234,14 +259,14 @@ Available targets:
234259
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
235260
| before\_cluster\_joining\_userdata | Additional `bash` commands to execute on each worker node before joining the EKS cluster (before executing the `bootstrap.sh` script). For more info, see https://kubedex.com/90-days-of-aws-eks-in-production | `string` | `""` | no |
236261
| bootstrap\_additional\_options | Additional options to bootstrap.sh. DO NOT include `--kubelet-additional-args`, use `kubelet_additional_args` var instead. | `string` | `""` | no |
237-
| capacity\_type | Type of capacity associated with the EKS Node Group. Valid values: ON\_DEMAND, SPOT. <br>Terraform will only perform drift detection if a configuration value is provided. | `string` | `"ON_DEMAND"` | no |
262+
| capacity\_type | Type of capacity associated with the EKS Node Group. Valid values: "ON\_DEMAND", "SPOT", or `null`.<br>Terraform will only perform drift detection if a configuration value is provided. | `string` | `null` | no |
238263
| cluster\_autoscaler\_enabled | Set true to label the node group so that the [Kubernetes Cluster Autoscaler](https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/cloudprovider/aws/README.md#auto-discovery-setup) will discover and autoscale it | `bool` | `null` | no |
239264
| cluster\_name | The name of the EKS cluster | `string` | n/a | yes |
240265
| context | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {}<br>}</pre> | no |
241266
| create\_before\_destroy | Set true in order to create the new node group before destroying the old one.<br>If false, the old node group will be destroyed first, causing downtime.<br>Changing this setting will always cause node group to be replaced. | `bool` | `false` | no |
242267
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
243268
| desired\_size | Initial desired number of worker nodes (external changes ignored) | `number` | n/a | yes |
244-
| disk\_size | Disk size in GiB for worker nodes. Defaults to 20. Ignored it `launch_template_id` is supplied.<br>Terraform will only perform drift detection if a configuration value is provided. | `number` | `20` | no |
269+
| disk\_size | Disk size in GiB for worker nodes. Defaults to 20. Ignored when `launch_template_id` is supplied.<br>Terraform will only perform drift detection if a configuration value is provided. | `number` | `20` | no |
245270
| disk\_type | If provided, will be used as volume type of created ebs disk on EC2 instances | `string` | `null` | no |
246271
| ec2\_ssh\_key | SSH key pair name to use to access the worker nodes | `string` | `null` | no |
247272
| enable\_cluster\_autoscaler | (Deprecated, use `cluster_autoscaler_enabled`) Set true to allow Kubernetes Cluster Auto Scaler to scale the node group | `bool` | `null` | no |
@@ -250,7 +275,7 @@ Available targets:
250275
| existing\_workers\_role\_policy\_arns | List of existing policy ARNs that will be attached to the workers default role on creation | `list(string)` | `[]` | no |
251276
| existing\_workers\_role\_policy\_arns\_count | Obsolete and ignored. Allowed for backward compatibility. | `number` | `0` | no |
252277
| id\_length\_limit | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for default, which is `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
253-
| instance\_types | Single instance type to use for this node group, passed as a list. Defaults to ["t3.medium"].<br>It is a list because Launch Templates take a list, and it is a single type because EKS only supports a single type per node group. | `list(string)` | <pre>[<br> "t3.medium"<br>]</pre> | no |
278+
| instance\_types | Instance types to use for this node group (up to 20). Defaults to ["t3.medium"].<br>Ignored when `launch_template_id` is supplied. | `list(string)` | <pre>[<br> "t3.medium"<br>]</pre> | no |
254279
| kubelet\_additional\_options | Additional flags to pass to kubelet.<br>DO NOT include `--node-labels` or `--node-taints`,<br>use `kubernetes_labels` and `kubernetes_taints` to specify those." | `string` | `""` | no |
255280
| kubernetes\_labels | Key-value mapping of Kubernetes labels. Only labels that are applied with the EKS API are managed by this argument.<br>Other Kubernetes labels applied to the EKS Node Group will not be managed. | `map(string)` | `{}` | no |
256281
| kubernetes\_taints | Key-value mapping of Kubernetes taints. | `map(string)` | `{}` | no |
@@ -288,7 +313,6 @@ Available targets:
288313
| eks\_node\_group\_role\_arn | ARN of the worker nodes IAM role |
289314
| eks\_node\_group\_role\_name | Name of the worker nodes IAM role |
290315
| eks\_node\_group\_status | Status of the EKS Node Group |
291-
292316
<!-- markdownlint-restore -->
293317

294318

docs/terraform.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,31 @@
1616
| aws | >= 3.0 |
1717
| random | >= 2.0 |
1818

19+
## Modules
20+
21+
| Name | Source | Version |
22+
|------|--------|---------|
23+
| label | cloudposse/label/null | 0.24.1 |
24+
| this | cloudposse/label/null | 0.24.1 |
25+
26+
## Resources
27+
28+
| Name |
29+
|------|
30+
| [aws_ami](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) |
31+
| [aws_eks_cluster](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster) |
32+
| [aws_eks_node_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_node_group) |
33+
| [aws_iam_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) |
34+
| [aws_iam_policy_document](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) |
35+
| [aws_iam_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) |
36+
| [aws_iam_role_policy_attachment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) |
37+
| [aws_launch_template](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/launch_template) |
38+
| [aws_launch_template](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template) |
39+
| [aws_partition](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) |
40+
| [aws_security_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) |
41+
| [aws_security_group_rule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) |
42+
| [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) |
43+
1944
## Inputs
2045

2146
| Name | Description | Type | Default | Required |
@@ -28,14 +53,14 @@
2853
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
2954
| before\_cluster\_joining\_userdata | Additional `bash` commands to execute on each worker node before joining the EKS cluster (before executing the `bootstrap.sh` script). For more info, see https://kubedex.com/90-days-of-aws-eks-in-production | `string` | `""` | no |
3055
| bootstrap\_additional\_options | Additional options to bootstrap.sh. DO NOT include `--kubelet-additional-args`, use `kubelet_additional_args` var instead. | `string` | `""` | no |
31-
| capacity\_type | Type of capacity associated with the EKS Node Group. Valid values: ON\_DEMAND, SPOT. <br>Terraform will only perform drift detection if a configuration value is provided. | `string` | `"ON_DEMAND"` | no |
56+
| capacity\_type | Type of capacity associated with the EKS Node Group. Valid values: "ON\_DEMAND", "SPOT", or `null`.<br>Terraform will only perform drift detection if a configuration value is provided. | `string` | `null` | no |
3257
| cluster\_autoscaler\_enabled | Set true to label the node group so that the [Kubernetes Cluster Autoscaler](https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/cloudprovider/aws/README.md#auto-discovery-setup) will discover and autoscale it | `bool` | `null` | no |
3358
| cluster\_name | The name of the EKS cluster | `string` | n/a | yes |
3459
| context | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {}<br>}</pre> | no |
3560
| create\_before\_destroy | Set true in order to create the new node group before destroying the old one.<br>If false, the old node group will be destroyed first, causing downtime.<br>Changing this setting will always cause node group to be replaced. | `bool` | `false` | no |
3661
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
3762
| desired\_size | Initial desired number of worker nodes (external changes ignored) | `number` | n/a | yes |
38-
| disk\_size | Disk size in GiB for worker nodes. Defaults to 20. Ignored it `launch_template_id` is supplied.<br>Terraform will only perform drift detection if a configuration value is provided. | `number` | `20` | no |
63+
| disk\_size | Disk size in GiB for worker nodes. Defaults to 20. Ignored when `launch_template_id` is supplied.<br>Terraform will only perform drift detection if a configuration value is provided. | `number` | `20` | no |
3964
| disk\_type | If provided, will be used as volume type of created ebs disk on EC2 instances | `string` | `null` | no |
4065
| ec2\_ssh\_key | SSH key pair name to use to access the worker nodes | `string` | `null` | no |
4166
| enable\_cluster\_autoscaler | (Deprecated, use `cluster_autoscaler_enabled`) Set true to allow Kubernetes Cluster Auto Scaler to scale the node group | `bool` | `null` | no |
@@ -44,7 +69,7 @@
4469
| existing\_workers\_role\_policy\_arns | List of existing policy ARNs that will be attached to the workers default role on creation | `list(string)` | `[]` | no |
4570
| existing\_workers\_role\_policy\_arns\_count | Obsolete and ignored. Allowed for backward compatibility. | `number` | `0` | no |
4671
| id\_length\_limit | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for default, which is `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
47-
| instance\_types | Single instance type to use for this node group, passed as a list. Defaults to ["t3.medium"].<br>It is a list because Launch Templates take a list, and it is a single type because EKS only supports a single type per node group. | `list(string)` | <pre>[<br> "t3.medium"<br>]</pre> | no |
72+
| instance\_types | Instance types to use for this node group (up to 20). Defaults to ["t3.medium"].<br>Ignored when `launch_template_id` is supplied. | `list(string)` | <pre>[<br> "t3.medium"<br>]</pre> | no |
4873
| kubelet\_additional\_options | Additional flags to pass to kubelet.<br>DO NOT include `--node-labels` or `--node-taints`,<br>use `kubernetes_labels` and `kubernetes_taints` to specify those." | `string` | `""` | no |
4974
| kubernetes\_labels | Key-value mapping of Kubernetes labels. Only labels that are applied with the EKS API are managed by this argument.<br>Other Kubernetes labels applied to the EKS Node Group will not be managed. | `map(string)` | `{}` | no |
5075
| kubernetes\_taints | Key-value mapping of Kubernetes taints. | `map(string)` | `{}` | no |
@@ -82,5 +107,4 @@
82107
| eks\_node\_group\_role\_arn | ARN of the worker nodes IAM role |
83108
| eks\_node\_group\_role\_name | Name of the worker nodes IAM role |
84109
| eks\_node\_group\_status | Status of the EKS Node Group |
85-
86110
<!-- markdownlint-restore -->

launch-template.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ resource "aws_launch_template" "default" {
7171
name_prefix = module.label.id
7272
update_default_version = true
7373

74-
instance_type = var.instance_types[0]
75-
image_id = local.launch_template_ami == "" ? null : local.launch_template_ami
76-
key_name = local.have_ssh_key ? var.ec2_ssh_key : null
74+
# Never include instance type in launch template because it is limited to just one
75+
# https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateNodegroup.html#API_CreateNodegroup_RequestSyntax
76+
image_id = local.launch_template_ami == "" ? null : local.launch_template_ami
77+
key_name = local.have_ssh_key ? var.ec2_ssh_key : null
7778

7879
dynamic "tag_specifications" {
7980
for_each = var.resources_to_tag

main.tf

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@ data "aws_eks_cluster" "this" {
5757
locals {
5858
ng_needs_remote_access = local.have_ssh_key && ! local.use_launch_template
5959
ng = {
60-
cluster_name = var.cluster_name
61-
node_role_arn = join("", aws_iam_role.default.*.arn)
62-
subnet_ids = var.subnet_ids
63-
disk_size = local.use_launch_template ? null : var.disk_size
64-
instance_types = local.use_launch_template ? null : var.instance_types
60+
cluster_name = var.cluster_name
61+
node_role_arn = join("", aws_iam_role.default.*.arn)
62+
# Keep sorted so that change in order does not trigger replacement via random_pet
63+
subnet_ids = sort(var.subnet_ids)
64+
disk_size = local.use_launch_template ? null : var.disk_size
65+
# Always supply instance types via the node group, not the launch template,
66+
# because node group supports up to 20 types but launch template does not.
67+
# See https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateNodegroup.html#API_CreateNodegroup_RequestSyntax
68+
# Keep sorted so that change in order does not trigger replacement via random_pet
69+
instance_types = sort(var.instance_types)
6570
ami_type = local.launch_template_ami == "" ? var.ami_type : null
6671
capacity_type = var.capacity_type
6772
labels = var.kubernetes_labels == null ? {} : var.kubernetes_labels
@@ -77,9 +82,10 @@ locals {
7782
}
7883

7984
# Configure remote access via Launch Template if we are using one
80-
need_remote_access = local.ng_needs_remote_access
81-
ec2_ssh_key = local.have_ssh_key ? var.ec2_ssh_key : "none"
82-
source_security_group_ids = local.ng_needs_remote_access ? var.source_security_group_ids : []
85+
need_remote_access = local.ng_needs_remote_access
86+
ec2_ssh_key = local.have_ssh_key ? var.ec2_ssh_key : "none"
87+
# Keep sorted so that change in order does not trigger replacement via random_pet
88+
source_security_group_ids = local.ng_needs_remote_access ? sort(var.source_security_group_ids) : []
8389
}
8490
}
8591

@@ -93,7 +99,7 @@ resource "random_pet" "cbd" {
9399
node_role_arn = local.ng.node_role_arn
94100
subnet_ids = join(",", local.ng.subnet_ids)
95101
disk_size = local.ng.disk_size
96-
instance_types = local.ng.instance_types == null ? "" : local.ng.instance_types[0]
102+
instance_types = join(",", local.ng.instance_types)
97103
ami_type = local.ng.ami_type
98104
release_version = local.ng.release_version
99105
version = local.ng.version

0 commit comments

Comments
 (0)