Skip to content

Commit e3a603c

Browse files
authored
Ignore external changes to desired group size (#19)
1 parent e248c50 commit e3a603c

File tree

5 files changed

+106
-68
lines changed

5 files changed

+106
-68
lines changed

README.md

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ For automated tests of the complete example using [bats](https://github.com/bats
165165
name = var.name
166166
attributes = var.attributes
167167
tags = var.tags
168-
vpc_id = module.vpc.vpc_id
169168
subnet_ids = module.subnets.public_subnet_ids
170169
instance_types = var.instance_types
171170
desired_size = var.desired_size
@@ -191,45 +190,60 @@ Available targets:
191190
lint Lint terraform code
192191
193192
```
193+
## Requirements
194+
195+
| Name | Version |
196+
|------|---------|
197+
| terraform | ~> 0.12.0 |
198+
| aws | ~> 2.0 |
199+
| local | ~> 1.3 |
200+
| template | ~> 2.0 |
201+
202+
## Providers
203+
204+
| Name | Version |
205+
|------|---------|
206+
| aws | ~> 2.0 |
207+
194208
## Inputs
195209

196210
| Name | Description | Type | Default | Required |
197-
|------|-------------|:----:|:-----:|:-----:|
198-
| ami_release_version | AMI version of the EKS Node Group. Defaults to latest version for Kubernetes version | string | `null` | no |
199-
| ami_type | Type of Amazon Machine Image (AMI) associated with the EKS Node Group. Defaults to `AL2_x86_64`. Valid values: `AL2_x86_64`, `AL2_x86_64_GPU`. Terraform will only perform drift detection if a configuration value is provided | string | `AL2_x86_64` | no |
200-
| attributes | Additional attributes (e.g. `1`) | list(string) | `<list>` | no |
201-
| cluster_name | The name of the EKS cluster | string | - | yes |
202-
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
203-
| desired_size | Desired number of worker nodes | number | - | yes |
204-
| disk_size | Disk size in GiB for worker nodes. Defaults to 20. Terraform will only perform drift detection if a configuration value is provided | number | `20` | no |
205-
| ec2_ssh_key | SSH key name that should be used to access the worker nodes | string | `null` | no |
206-
| enable_cluster_autoscaler | Whether to enable node group to scale the Auto Scaling Group | bool | `false` | no |
207-
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | bool | `true` | no |
208-
| existing_workers_role_policy_arns | List of existing policy ARNs that will be attached to the workers default role on creation | list(string) | `<list>` | no |
209-
| existing_workers_role_policy_arns_count | Count of existing policy ARNs that will be attached to the workers default role on creation. Needed to prevent Terraform error `count can't be computed` | number | `0` | no |
210-
| instance_types | Set of instance types associated with the EKS Node Group. Defaults to ["t3.medium"]. Terraform will only perform drift detection if a configuration value is provided | list(string) | - | yes |
211-
| kubernetes_labels | Key-value mapping of Kubernetes labels. Only labels that are applied with the EKS API are managed by this argument. Other Kubernetes labels applied to the EKS Node Group will not be managed | map(string) | `<map>` | no |
212-
| kubernetes_version | Kubernetes version. Defaults to EKS Cluster Kubernetes version. Terraform will only perform drift detection if a configuration value is provided | string | `null` | no |
213-
| max_size | Maximum number of worker nodes | number | - | yes |
214-
| min_size | Minimum number of worker nodes | number | - | yes |
215-
| module_depends_on | Can be any value desired. Module will wait for this value to be computed before creating node group. | any | `null` | no |
216-
| name | Solution name, e.g. 'app' or 'cluster' | string | - | yes |
217-
| namespace | Namespace, which could be your organization name, e.g. 'eg' or 'cp' | string | `` | no |
218-
| source_security_group_ids | Set of EC2 Security Group IDs to allow SSH access (port 22) from on the worker nodes. If you specify `ec2_ssh_key`, but do not specify this configuration when you create an EKS Node Group, port 22 on the worker nodes is opened to the Internet (0.0.0.0/0) | list(string) | `<list>` | no |
219-
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | `` | no |
220-
| subnet_ids | A list of subnet IDs to launch resources in | list(string) | - | yes |
221-
| tags | Additional tags (e.g. `{ BusinessUnit = "XYZ" }` | map(string) | `<map>` | no |
211+
|------|-------------|------|---------|:--------:|
212+
| ami\_release\_version | AMI version of the EKS Node Group. Defaults to latest version for Kubernetes version | `string` | `null` | no |
213+
| ami\_type | Type of Amazon Machine Image (AMI) associated with the EKS Node Group. Defaults to `AL2_x86_64`. Valid values: `AL2_x86_64`, `AL2_x86_64_GPU`. Terraform will only perform drift detection if a configuration value is provided | `string` | `"AL2_x86_64"` | no |
214+
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
215+
| cluster\_name | The name of the EKS cluster | `string` | n/a | yes |
216+
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | `string` | `"-"` | no |
217+
| desired\_size | Desired number of worker nodes (external changes ignored) | `number` | n/a | yes |
218+
| disk\_size | Disk size in GiB for worker nodes. Defaults to 20. Terraform will only perform drift detection if a configuration value is provided | `number` | `20` | no |
219+
| ec2\_ssh\_key | SSH key name that should be used to access the worker nodes | `string` | `null` | no |
220+
| enable\_cluster\_autoscaler | Whether to enable node group to scale the Auto Scaling Group | `bool` | `false` | no |
221+
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | `bool` | `true` | no |
222+
| existing\_workers\_role\_policy\_arns | List of existing policy ARNs that will be attached to the workers default role on creation | `list(string)` | `[]` | no |
223+
| existing\_workers\_role\_policy\_arns\_count | Count of existing policy ARNs that will be attached to the workers default role on creation. Needed to prevent Terraform error `count can't be computed` | `number` | `0` | no |
224+
| instance\_types | Set of instance types associated with the EKS Node Group. Defaults to ["t3.medium"]. Terraform will only perform drift detection if a configuration value is provided | `list(string)` | n/a | yes |
225+
| kubernetes\_labels | Key-value mapping of Kubernetes labels. Only labels that are applied with the EKS API are managed by this argument. Other Kubernetes labels applied to the EKS Node Group will not be managed | `map(string)` | `{}` | no |
226+
| kubernetes\_version | Kubernetes version. Defaults to EKS Cluster Kubernetes version. Terraform will only perform drift detection if a configuration value is provided | `string` | `null` | no |
227+
| max\_size | Maximum number of worker nodes | `number` | n/a | yes |
228+
| min\_size | Minimum number of worker nodes | `number` | n/a | yes |
229+
| module\_depends\_on | Can be any value desired. Module will wait for this value to be computed before creating node group. | `any` | `null` | no |
230+
| name | Solution name, e.g. 'app' or 'cluster' | `string` | n/a | yes |
231+
| namespace | Namespace, which could be your organization name, e.g. 'eg' or 'cp' | `string` | `""` | no |
232+
| source\_security\_group\_ids | Set of EC2 Security Group IDs to allow SSH access (port 22) from on the worker nodes. If you specify `ec2_ssh_key`, but do not specify this configuration when you create an EKS Node Group, port 22 on the worker nodes is opened to the Internet (0.0.0.0/0) | `list(string)` | `[]` | no |
233+
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | `string` | `""` | no |
234+
| subnet\_ids | A list of subnet IDs to launch resources in | `list(string)` | n/a | yes |
235+
| tags | Additional tags (e.g. `{ BusinessUnit = "XYZ" }` | `map(string)` | `{}` | no |
222236

223237
## Outputs
224238

225239
| Name | Description |
226240
|------|-------------|
227-
| eks_node_group_arn | Amazon Resource Name (ARN) of the EKS Node Group |
228-
| eks_node_group_id | EKS Cluster name and EKS Node Group name separated by a colon |
229-
| eks_node_group_resources | List of objects containing information about underlying resources of the EKS Node Group |
230-
| eks_node_group_role_arn | ARN of the worker nodes IAM role |
231-
| eks_node_group_role_name | Name of the worker nodes IAM role |
232-
| eks_node_group_status | Status of the EKS Node Group |
241+
| eks\_node\_group\_arn | Amazon Resource Name (ARN) of the EKS Node Group |
242+
| eks\_node\_group\_id | EKS Cluster name and EKS Node Group name separated by a colon |
243+
| eks\_node\_group\_resources | List of objects containing information about underlying resources of the EKS Node Group |
244+
| eks\_node\_group\_role\_arn | ARN of the worker nodes IAM role |
245+
| eks\_node\_group\_role\_name | Name of the worker nodes IAM role |
246+
| eks\_node\_group\_status | Status of the EKS Node Group |
233247

234248

235249

README.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ usage: |-
147147
name = var.name
148148
attributes = var.attributes
149149
tags = var.tags
150-
vpc_id = module.vpc.vpc_id
151150
subnet_ids = module.subnets.public_subnet_ids
152151
instance_types = var.instance_types
153152
desired_size = var.desired_size

docs/terraform.md

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,55 @@
1+
## Requirements
2+
3+
| Name | Version |
4+
|------|---------|
5+
| terraform | ~> 0.12.0 |
6+
| aws | ~> 2.0 |
7+
| local | ~> 1.3 |
8+
| template | ~> 2.0 |
9+
10+
## Providers
11+
12+
| Name | Version |
13+
|------|---------|
14+
| aws | ~> 2.0 |
15+
116
## Inputs
217

318
| Name | Description | Type | Default | Required |
4-
|------|-------------|:----:|:-----:|:-----:|
5-
| ami_release_version | AMI version of the EKS Node Group. Defaults to latest version for Kubernetes version | string | `null` | no |
6-
| ami_type | Type of Amazon Machine Image (AMI) associated with the EKS Node Group. Defaults to `AL2_x86_64`. Valid values: `AL2_x86_64`, `AL2_x86_64_GPU`. Terraform will only perform drift detection if a configuration value is provided | string | `AL2_x86_64` | no |
7-
| attributes | Additional attributes (e.g. `1`) | list(string) | `<list>` | no |
8-
| cluster_name | The name of the EKS cluster | string | - | yes |
9-
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
10-
| desired_size | Desired number of worker nodes | number | - | yes |
11-
| disk_size | Disk size in GiB for worker nodes. Defaults to 20. Terraform will only perform drift detection if a configuration value is provided | number | `20` | no |
12-
| ec2_ssh_key | SSH key name that should be used to access the worker nodes | string | `null` | no |
13-
| enable_cluster_autoscaler | Whether to enable node group to scale the Auto Scaling Group | bool | `false` | no |
14-
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | bool | `true` | no |
15-
| existing_workers_role_policy_arns | List of existing policy ARNs that will be attached to the workers default role on creation | list(string) | `<list>` | no |
16-
| existing_workers_role_policy_arns_count | Count of existing policy ARNs that will be attached to the workers default role on creation. Needed to prevent Terraform error `count can't be computed` | number | `0` | no |
17-
| instance_types | Set of instance types associated with the EKS Node Group. Defaults to ["t3.medium"]. Terraform will only perform drift detection if a configuration value is provided | list(string) | - | yes |
18-
| kubernetes_labels | Key-value mapping of Kubernetes labels. Only labels that are applied with the EKS API are managed by this argument. Other Kubernetes labels applied to the EKS Node Group will not be managed | map(string) | `<map>` | no |
19-
| kubernetes_version | Kubernetes version. Defaults to EKS Cluster Kubernetes version. Terraform will only perform drift detection if a configuration value is provided | string | `null` | no |
20-
| max_size | Maximum number of worker nodes | number | - | yes |
21-
| min_size | Minimum number of worker nodes | number | - | yes |
22-
| module_depends_on | Can be any value desired. Module will wait for this value to be computed before creating node group. | any | `null` | no |
23-
| name | Solution name, e.g. 'app' or 'cluster' | string | - | yes |
24-
| namespace | Namespace, which could be your organization name, e.g. 'eg' or 'cp' | string | `` | no |
25-
| source_security_group_ids | Set of EC2 Security Group IDs to allow SSH access (port 22) from on the worker nodes. If you specify `ec2_ssh_key`, but do not specify this configuration when you create an EKS Node Group, port 22 on the worker nodes is opened to the Internet (0.0.0.0/0) | list(string) | `<list>` | no |
26-
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | `` | no |
27-
| subnet_ids | A list of subnet IDs to launch resources in | list(string) | - | yes |
28-
| tags | Additional tags (e.g. `{ BusinessUnit = "XYZ" }` | map(string) | `<map>` | no |
19+
|------|-------------|------|---------|:--------:|
20+
| ami\_release\_version | AMI version of the EKS Node Group. Defaults to latest version for Kubernetes version | `string` | `null` | no |
21+
| ami\_type | Type of Amazon Machine Image (AMI) associated with the EKS Node Group. Defaults to `AL2_x86_64`. Valid values: `AL2_x86_64`, `AL2_x86_64_GPU`. Terraform will only perform drift detection if a configuration value is provided | `string` | `"AL2_x86_64"` | no |
22+
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
23+
| cluster\_name | The name of the EKS cluster | `string` | n/a | yes |
24+
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | `string` | `"-"` | no |
25+
| desired\_size | Desired number of worker nodes (external changes ignored) | `number` | n/a | yes |
26+
| disk\_size | Disk size in GiB for worker nodes. Defaults to 20. Terraform will only perform drift detection if a configuration value is provided | `number` | `20` | no |
27+
| ec2\_ssh\_key | SSH key name that should be used to access the worker nodes | `string` | `null` | no |
28+
| enable\_cluster\_autoscaler | Whether to enable node group to scale the Auto Scaling Group | `bool` | `false` | no |
29+
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | `bool` | `true` | no |
30+
| existing\_workers\_role\_policy\_arns | List of existing policy ARNs that will be attached to the workers default role on creation | `list(string)` | `[]` | no |
31+
| existing\_workers\_role\_policy\_arns\_count | Count of existing policy ARNs that will be attached to the workers default role on creation. Needed to prevent Terraform error `count can't be computed` | `number` | `0` | no |
32+
| instance\_types | Set of instance types associated with the EKS Node Group. Defaults to ["t3.medium"]. Terraform will only perform drift detection if a configuration value is provided | `list(string)` | n/a | yes |
33+
| kubernetes\_labels | Key-value mapping of Kubernetes labels. Only labels that are applied with the EKS API are managed by this argument. Other Kubernetes labels applied to the EKS Node Group will not be managed | `map(string)` | `{}` | no |
34+
| kubernetes\_version | Kubernetes version. Defaults to EKS Cluster Kubernetes version. Terraform will only perform drift detection if a configuration value is provided | `string` | `null` | no |
35+
| max\_size | Maximum number of worker nodes | `number` | n/a | yes |
36+
| min\_size | Minimum number of worker nodes | `number` | n/a | yes |
37+
| module\_depends\_on | Can be any value desired. Module will wait for this value to be computed before creating node group. | `any` | `null` | no |
38+
| name | Solution name, e.g. 'app' or 'cluster' | `string` | n/a | yes |
39+
| namespace | Namespace, which could be your organization name, e.g. 'eg' or 'cp' | `string` | `""` | no |
40+
| source\_security\_group\_ids | Set of EC2 Security Group IDs to allow SSH access (port 22) from on the worker nodes. If you specify `ec2_ssh_key`, but do not specify this configuration when you create an EKS Node Group, port 22 on the worker nodes is opened to the Internet (0.0.0.0/0) | `list(string)` | `[]` | no |
41+
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | `string` | `""` | no |
42+
| subnet\_ids | A list of subnet IDs to launch resources in | `list(string)` | n/a | yes |
43+
| tags | Additional tags (e.g. `{ BusinessUnit = "XYZ" }` | `map(string)` | `{}` | no |
2944

3045
## Outputs
3146

3247
| Name | Description |
3348
|------|-------------|
34-
| eks_node_group_arn | Amazon Resource Name (ARN) of the EKS Node Group |
35-
| eks_node_group_id | EKS Cluster name and EKS Node Group name separated by a colon |
36-
| eks_node_group_resources | List of objects containing information about underlying resources of the EKS Node Group |
37-
| eks_node_group_role_arn | ARN of the worker nodes IAM role |
38-
| eks_node_group_role_name | Name of the worker nodes IAM role |
39-
| eks_node_group_status | Status of the EKS Node Group |
49+
| eks\_node\_group\_arn | Amazon Resource Name (ARN) of the EKS Node Group |
50+
| eks\_node\_group\_id | EKS Cluster name and EKS Node Group name separated by a colon |
51+
| eks\_node\_group\_resources | List of objects containing information about underlying resources of the EKS Node Group |
52+
| eks\_node\_group\_role\_arn | ARN of the worker nodes IAM role |
53+
| eks\_node\_group\_role\_name | Name of the worker nodes IAM role |
54+
| eks\_node\_group\_status | Status of the EKS Node Group |
4055

main.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ locals {
1111
"k8s.io/cluster-autoscaler/enabled" = "${var.enable_cluster_autoscaler}"
1212
}
1313
)
14+
aws_policy_prefix = format("arn:%s:iam::aws:policy", join("", data.aws_partition.current.*.partition))
1415
}
1516

1617
module "label" {
@@ -24,6 +25,11 @@ module "label" {
2425
enabled = var.enabled
2526
}
2627

28+
29+
data "aws_partition" "current" {
30+
count = var.enabled ? 1 : 0
31+
}
32+
2733
data "aws_iam_policy_document" "assume_role" {
2834
count = var.enabled ? 1 : 0
2935

@@ -75,7 +81,7 @@ resource "aws_iam_role" "default" {
7581

7682
resource "aws_iam_role_policy_attachment" "amazon_eks_worker_node_policy" {
7783
count = var.enabled ? 1 : 0
78-
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"
84+
policy_arn = format("%s/%s", local.aws_policy_prefix, "AmazonEKSWorkerNodePolicy")
7985
role = join("", aws_iam_role.default.*.name)
8086
}
8187

@@ -87,13 +93,13 @@ resource "aws_iam_role_policy_attachment" "amazon_eks_worker_node_autoscaler_pol
8793

8894
resource "aws_iam_role_policy_attachment" "amazon_eks_cni_policy" {
8995
count = var.enabled ? 1 : 0
90-
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
96+
policy_arn = format("%s/%s", local.aws_policy_prefix, "AmazonEKS_CNI_Policy")
9197
role = join("", aws_iam_role.default.*.name)
9298
}
9399

94100
resource "aws_iam_role_policy_attachment" "amazon_ec2_container_registry_read_only" {
95101
count = var.enabled ? 1 : 0
96-
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
102+
policy_arn = format("%s/%s", local.aws_policy_prefix, "AmazonEC2ContainerRegistryReadOnly")
97103
role = join("", aws_iam_role.default.*.name)
98104
}
99105

@@ -144,4 +150,8 @@ resource "aws_eks_node_group" "default" {
144150
# the cluster is fully created and configured before creating any node groups
145151
var.module_depends_on
146152
]
153+
154+
lifecycle {
155+
ignore_changes = [scaling_config[0].desired_size]
156+
}
147157
}

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ variable "ec2_ssh_key" {
5858

5959
variable "desired_size" {
6060
type = number
61-
description = "Desired number of worker nodes"
61+
description = "Desired number of worker nodes (external changes ignored)"
6262
}
6363

6464
variable "max_size" {

0 commit comments

Comments
 (0)