diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b5335fa..d2cfb32 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.3.0 + rev: v4.0.1 hooks: - id: check-added-large-files args: ['--maxkb=500'] @@ -18,7 +18,7 @@ repos: args: ['--allow-missing-credentials'] - id: trailing-whitespace - repo: git://github.com/antonbabenko/pre-commit-terraform - rev: v1.45.0 + rev: v1.50.0 hooks: - id: terraform_fmt - id: terraform_docs diff --git a/CHANGELOG.md b/CHANGELOG.md index 04c2f6c..d5b59b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +- Upgrade module to support tains and node group name prefix + + + +## [3.1.0] - 2020-12-02 + +- Add support for capacity_type ([#9](https://github.com/umotif-public/terraform-aws-eks-node-group/issues/9)) + + + +## [3.0.1] - 2020-11-09 + +- Update module to remove 0.14 limit ([#8](https://github.com/umotif-public/terraform-aws-eks-node-group/issues/8)) +- Update changelog @@ -52,7 +66,9 @@ All notable changes to this project will be documented in this file. - Initial commit -[Unreleased]: https://github.com/umotif-public/terraform-aws-eks-node-group/compare/3.0.0...HEAD +[Unreleased]: https://github.com/umotif-public/terraform-aws-eks-node-group/compare/3.1.0...HEAD +[3.1.0]: https://github.com/umotif-public/terraform-aws-eks-node-group/compare/3.0.1...3.1.0 +[3.0.1]: https://github.com/umotif-public/terraform-aws-eks-node-group/compare/3.0.0...3.0.1 [3.0.0]: https://github.com/umotif-public/terraform-aws-eks-node-group/compare/2.0.1...3.0.0 [2.0.1]: https://github.com/umotif-public/terraform-aws-eks-node-group/compare/2.0.0...2.0.1 [2.0.0]: https://github.com/umotif-public/terraform-aws-eks-node-group/compare/1.0.3...2.0.0 diff --git a/README.md b/README.md index 8a633c5..4087971 100644 --- a/README.md +++ b/README.md @@ -9,17 +9,19 @@ This module will create EKS managed Node Group that will join your existing Kube ## Terraform versions -Terraform 0.12. Pin module version to `~> v3.0`. Submit pull-requests to `master` branch. +Terraform 0.12. Pin module version to `~> v4.0`. Submit pull-requests to `master` branch. ## Usage ```hcl module "eks-node-group" { source = "umotif-public/eks-node-group/aws" - version = "~> 3.0.0" + version = "~> 4.0.0" cluster_name = aws_eks_cluster.cluster.id + node_group_name_prefix = "eks-test-" + subnet_ids = ["subnet-1","subnet-2","subnet-3"] desired_size = 1 @@ -31,10 +33,23 @@ module "eks-node-group" { ec2_ssh_key = "eks-test" - kubernetes_labels = { + labels = { lifecycle = "OnDemand" } + taints = [ + { + key = "test-1" + value = null + effect = "NO_SCHEDULE" + }, + { + key = "test-2" + value = "value-test" + effect = "NO_EXECUTE" + } + ] + force_update_version = true tags = { @@ -43,10 +58,6 @@ module "eks-node-group" { } ``` -## Assumptions - -Module is to be used with Terraform > 0.13. Fully working with Terraform 0.12 as well. - ## Examples * [EKS Node Group- single](https://github.com/umotif-public/terraform-aws-eks-node-group/tree/master/examples/single-node-group) @@ -63,50 +74,66 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [LinkedIn](http | Name | Version | |------|---------| -| terraform | >= 0.12.6 | -| aws | >= 3.19 | +| [terraform](#requirement\_terraform) | >= 0.12.6 | +| [aws](#requirement\_aws) | >= 3.43 | ## Providers | Name | Version | |------|---------| -| aws | >= 3.19 | -| random | n/a | +| [aws](#provider\_aws) | >= 3.43 | +| [random](#provider\_random) | n/a | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [aws_eks_node_group.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_node_group) | resource | +| [aws_iam_role.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | +| [aws_iam_role_policy_attachment.main_AmazonEC2ContainerRegistryReadOnly](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | +| [aws_iam_role_policy_attachment.main_AmazonEKSWorkerNodePolicy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | +| [aws_iam_role_policy_attachment.main_AmazonEKS_CNI_Policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | +| [random_id.main](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) | resource | ## Inputs | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| ami\_release\_version | AMI version of the EKS Node Group. Defaults to latest version for Kubernetes version | `string` | `null` | no | -| ami\_type | Type of Amazon Machine Image (AMI) associated with the EKS Node Group. Valid values: `AL2_x86_64`, `AL2_x86_64_GPU`. Terraform will only perform drift detection if a configuration value is provided | `string` | `null` | no | -| capacity\_type | Type of capacity associated with the EKS Node Group. Defaults to ON\_DEMAND. Valid values: ON\_DEMAND, SPOT. | `string` | `"ON_DEMAND"` | no | -| cluster\_name | The name of the EKS cluster | `string` | n/a | yes | -| create\_iam\_role | Create IAM role for node group. Set to false if pass `node_role_arn` as an argument | `bool` | `true` | no | -| desired\_size | Desired number of worker nodes | `number` | n/a | yes | -| 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` | `null` | no | -| ec2\_ssh\_key | SSH key name that should be used to access the worker nodes | `string` | `null` | no | -| force\_update\_version | Force version update if existing pods are unable to be drained due to a pod disruption budget issue. | `bool` | `false` | no | -| instance\_types | List of instance types associated with the EKS Node Group. Terraform will only perform drift detection if a configuration value is provided | `list(string)` | `null` | no | -| 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 | -| 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 | -| launch\_template | Configuration block with Launch Template settings. `name`, `id` and `version` parameters are available. | `map(string)` | `{}` | no | -| max\_size | Maximum number of worker nodes | `number` | n/a | yes | -| min\_size | Minimum number of worker nodes | `number` | n/a | yes | -| node\_group\_name | The name of the cluster node group. Defaults to - | `string` | `""` | no | -| node\_group\_role\_name | The name of the cluster node group role. Defaults to -managed-group-node | `string` | `""` | no | -| node\_role\_arn | IAM role arn that will be used by managed node group | `string` | `""` | no | -| 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 | -| subnet\_ids | A list of subnet IDs to launch resources in | `list(string)` | n/a | yes | -| tags | A map of tags (key-value pairs) passed to resources. | `map(string)` | `{}` | no | +| [ami\_release\_version](#input\_ami\_release\_version) | AMI version of the EKS Node Group. Defaults to latest version for Kubernetes version | `string` | `null` | no | +| [ami\_type](#input\_ami\_type) | Type of Amazon Machine Image (AMI) associated with the EKS Node Group. Valid values: `AL2_x86_64`, `AL2_x86_64_GPU`. Terraform will only perform drift detection if a configuration value is provided | `string` | `null` | no | +| [capacity\_type](#input\_capacity\_type) | Type of capacity associated with the EKS Node Group. Defaults to ON\_DEMAND. Valid values: ON\_DEMAND, SPOT. | `string` | `"ON_DEMAND"` | no | +| [cluster\_name](#input\_cluster\_name) | The name of the EKS cluster | `string` | n/a | yes | +| [create\_iam\_role](#input\_create\_iam\_role) | Create IAM role for node group. Set to false if pass `node_role_arn` as an argument | `bool` | `true` | no | +| [desired\_size](#input\_desired\_size) | Desired number of worker nodes | `number` | n/a | yes | +| [disk\_size](#input\_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` | `null` | no | +| [ec2\_ssh\_key](#input\_ec2\_ssh\_key) | SSH key name that should be used to access the worker nodes | `string` | `null` | no | +| [force\_update\_version](#input\_force\_update\_version) | Force version update if existing pods are unable to be drained due to a pod disruption budget issue. | `bool` | `false` | no | +| [instance\_types](#input\_instance\_types) | List of instance types associated with the EKS Node Group. Terraform will only perform drift detection if a configuration value is provided | `list(string)` | `null` | no | +| [kubernetes\_version](#input\_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 | +| [labels](#input\_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 | +| [launch\_template](#input\_launch\_template) | Configuration block with Launch Template settings. `name`, `id` and `version` parameters are available. | `map(string)` | `{}` | no | +| [max\_size](#input\_max\_size) | Maximum number of worker nodes | `number` | n/a | yes | +| [min\_size](#input\_min\_size) | Minimum number of worker nodes | `number` | n/a | yes | +| [node\_group\_name](#input\_node\_group\_name) | The name of the cluster node group. Defaults to - | `string` | `null` | no | +| [node\_group\_name\_prefix](#input\_node\_group\_name\_prefix) | Creates a unique name beginning with the specified prefix. Conflicts with node\_group\_name | `string` | `null` | no | +| [node\_group\_role\_name](#input\_node\_group\_role\_name) | The name of the cluster node group role. Defaults to -managed-group-node | `string` | `""` | no | +| [node\_role\_arn](#input\_node\_role\_arn) | IAM role arn that will be used by managed node group | `string` | `""` | no | +| [source\_security\_group\_ids](#input\_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 | +| [subnet\_ids](#input\_subnet\_ids) | A list of subnet IDs to launch resources in | `list(string)` | n/a | yes | +| [tags](#input\_tags) | A map of tags (key-value pairs) passed to resources. | `map(string)` | `{}` | no | +| [taints](#input\_taints) | List of objects containing Kubernetes taints which will be applied to the nodes in the node group. Maximum of 50 taints per node group. | `list(object({ key = string, value = any, effect = string }))` | `[]` | no | ## Outputs | Name | Description | |------|-------------| -| iam\_role\_arn | IAM role ARN used by node group. | -| iam\_role\_id | IAM role ID used by node group. | -| node\_group | Outputs from EKS node group. See `aws_eks_node_group` Terraform documentation for values | - +| [iam\_role\_arn](#output\_iam\_role\_arn) | IAM role ARN used by node group. | +| [iam\_role\_id](#output\_iam\_role\_id) | IAM role ID used by node group. | +| [node\_group](#output\_node\_group) | Outputs from EKS node group. See `aws_eks_node_group` Terraform documentation for values | ## License diff --git a/examples/multiaz-node-group/main.tf b/examples/multiaz-node-group/main.tf index 8e35a70..3a039ff 100644 --- a/examples/multiaz-node-group/main.tf +++ b/examples/multiaz-node-group/main.tf @@ -5,51 +5,25 @@ provider "aws" { ##### # VPC and subnets ##### -module "vpc" { - source = "terraform-aws-modules/vpc/aws" - version = "2.64.0" - - name = "simple-vpc" - - cidr = "10.0.0.0/16" - - azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"] - private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] - public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] - - private_subnet_tags = { - "kubernetes.io/role/internal-elb" = "1" - } - - public_subnet_tags = { - "kubernetes.io/role/elb" = "1" - } - - enable_dns_hostnames = true - enable_dns_support = true - enable_nat_gateway = true - enable_vpn_gateway = true - single_nat_gateway = true - one_nat_gateway_per_az = false +data "aws_vpc" "default" { + default = true +} - tags = { - "kubernetes.io/cluster/eks" = "shared", - Environment = "test" - } +data "aws_subnet_ids" "all" { + vpc_id = data.aws_vpc.default.id } ##### # EKS Cluster ##### - resource "aws_eks_cluster" "cluster" { enabled_cluster_log_types = [] - name = "eks" + name = "eks-module-test-cluster" role_arn = aws_iam_role.cluster.arn - version = "1.18" + version = "1.20" vpc_config { - subnet_ids = flatten([module.vpc.public_subnets, module.vpc.private_subnets]) + subnet_ids = data.aws_subnet_ids.all.ids security_group_ids = [] endpoint_private_access = "true" endpoint_public_access = "true" @@ -132,9 +106,12 @@ module "eks-node-group-a" { create_iam_role = false - cluster_name = aws_eks_cluster.cluster.id - node_role_arn = aws_iam_role.main.arn - subnet_ids = [module.vpc.private_subnets[0]] + cluster_name = aws_eks_cluster.cluster.id + + node_group_name_prefix = "eks-test-group-ab-" + node_role_arn = aws_iam_role.main.arn + + subnet_ids = [sort(data.aws_subnet_ids.all.ids)[0]] desired_size = 1 min_size = 1 @@ -144,7 +121,20 @@ module "eks-node-group-a" { ec2_ssh_key = "eks-test" - kubernetes_labels = { + taints = [ + { + key = "test-1" + value = null + effect = "NO_SCHEDULE" + }, + { + key = "test-2" + value = "value-test" + effect = "NO_EXECUTE" + } + ] + + labels = { lifecycle = "OnDemand" az = "eu-west-1a" } @@ -159,9 +149,12 @@ module "eks-node-group-b" { create_iam_role = false - cluster_name = aws_eks_cluster.cluster.id + cluster_name = aws_eks_cluster.cluster.id + + node_group_name = "eks-test-group-b" + node_role_arn = aws_iam_role.main.arn - subnet_ids = [module.vpc.private_subnets[1]] + subnet_ids = [sort(data.aws_subnet_ids.all.ids)[1]] desired_size = 1 min_size = 1 @@ -171,7 +164,7 @@ module "eks-node-group-b" { ec2_ssh_key = "eks-test" - kubernetes_labels = { + labels = { lifecycle = "OnDemand" az = "eu-west-1b" } @@ -188,7 +181,7 @@ module "eks-node-group-c" { cluster_name = aws_eks_cluster.cluster.id node_role_arn = aws_iam_role.main.arn - subnet_ids = [module.vpc.private_subnets[2]] + subnet_ids = [sort(data.aws_subnet_ids.all.ids)[2]] desired_size = 1 min_size = 1 @@ -196,7 +189,7 @@ module "eks-node-group-c" { ec2_ssh_key = "eks-test" - kubernetes_labels = { + labels = { lifecycle = "OnDemand" az = "eu-west-1c" } diff --git a/examples/single-named-node-group/main.tf b/examples/single-named-node-group/main.tf index 1695bb2..71ed49b 100644 --- a/examples/single-named-node-group/main.tf +++ b/examples/single-named-node-group/main.tf @@ -5,51 +5,25 @@ provider "aws" { ##### # VPC and subnets ##### -module "vpc" { - source = "terraform-aws-modules/vpc/aws" - version = "2.64.0" - - name = "simple-vpc" - - cidr = "10.0.0.0/16" - - azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"] - private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] - public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] - - private_subnet_tags = { - "kubernetes.io/role/internal-elb" = "1" - } - - public_subnet_tags = { - "kubernetes.io/role/elb" = "1" - } - - enable_dns_hostnames = true - enable_dns_support = true - enable_nat_gateway = true - enable_vpn_gateway = true - single_nat_gateway = true - one_nat_gateway_per_az = false +data "aws_vpc" "default" { + default = true +} - tags = { - "kubernetes.io/cluster/eks" = "shared", - Environment = "test" - } +data "aws_subnet_ids" "all" { + vpc_id = data.aws_vpc.default.id } ##### # EKS Cluster ##### - resource "aws_eks_cluster" "cluster" { enabled_cluster_log_types = [] - name = "eks" + name = "eks-module-test-cluster" role_arn = aws_iam_role.cluster.arn - version = "1.18" + version = "1.20" vpc_config { - subnet_ids = flatten([module.vpc.public_subnets, module.vpc.private_subnets]) + subnet_ids = data.aws_subnet_ids.all.ids security_group_ids = [] endpoint_private_access = "true" endpoint_public_access = "true" @@ -96,7 +70,7 @@ module "eks-node-group" { cluster_name = aws_eks_cluster.cluster.id - subnet_ids = flatten([module.vpc.private_subnets]) + subnet_ids = data.aws_subnet_ids.all.ids desired_size = 1 min_size = 1 @@ -104,7 +78,20 @@ module "eks-node-group" { ec2_ssh_key = "eks-test" - kubernetes_labels = { + taints = [ + { + key = "test-1" + value = null + effect = "NO_SCHEDULE" + }, + { + key = "test-2" + value = "value-test" + effect = "NO_EXECUTE" + } + ] + + labels = { lifecycle = "OnDemand" } diff --git a/examples/single-node-group-with-launch-template/main.tf b/examples/single-node-group-with-launch-template/main.tf index 43b7adb..ba5a842 100644 --- a/examples/single-node-group-with-launch-template/main.tf +++ b/examples/single-node-group-with-launch-template/main.tf @@ -5,51 +5,25 @@ provider "aws" { ##### # VPC and subnets ##### -module "vpc" { - source = "terraform-aws-modules/vpc/aws" - version = "2.64.0" - - name = "simple-vpc" - - cidr = "10.0.0.0/16" - - azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"] - private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] - public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] - - private_subnet_tags = { - "kubernetes.io/role/internal-elb" = "1" - } - - public_subnet_tags = { - "kubernetes.io/role/elb" = "1" - } - - enable_dns_hostnames = true - enable_dns_support = true - enable_nat_gateway = true - enable_vpn_gateway = true - single_nat_gateway = true - one_nat_gateway_per_az = false +data "aws_vpc" "default" { + default = true +} - tags = { - "kubernetes.io/cluster/eks" = "shared", - Environment = "test" - } +data "aws_subnet_ids" "all" { + vpc_id = data.aws_vpc.default.id } ##### # EKS Cluster ##### - resource "aws_eks_cluster" "cluster" { enabled_cluster_log_types = [] - name = "eks" + name = "eks-module-test-cluster" role_arn = aws_iam_role.cluster.arn - version = "1.18" + version = "1.20" vpc_config { - subnet_ids = flatten([module.vpc.public_subnets, module.vpc.private_subnets]) + subnet_ids = data.aws_subnet_ids.all.ids security_group_ids = [] endpoint_private_access = "true" endpoint_public_access = "true" @@ -134,7 +108,7 @@ module "eks-node-group" { cluster_name = aws_eks_cluster.cluster.id - subnet_ids = flatten([module.vpc.private_subnets]) + subnet_ids = data.aws_subnet_ids.all.ids desired_size = 1 min_size = 1 @@ -145,7 +119,7 @@ module "eks-node-group" { version = data.aws_launch_template.cluster.latest_version } - kubernetes_labels = { + labels = { lifecycle = "OnDemand" } diff --git a/examples/single-node-group/main.tf b/examples/single-node-group/main.tf index 5c46037..51de564 100644 --- a/examples/single-node-group/main.tf +++ b/examples/single-node-group/main.tf @@ -5,51 +5,25 @@ provider "aws" { ##### # VPC and subnets ##### -module "vpc" { - source = "terraform-aws-modules/vpc/aws" - version = "2.64.0" - - name = "simple-vpc" - - cidr = "10.0.0.0/16" - - azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"] - private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] - public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] - - private_subnet_tags = { - "kubernetes.io/role/internal-elb" = "1" - } - - public_subnet_tags = { - "kubernetes.io/role/elb" = "1" - } - - enable_dns_hostnames = true - enable_dns_support = true - enable_nat_gateway = true - enable_vpn_gateway = true - single_nat_gateway = true - one_nat_gateway_per_az = false +data "aws_vpc" "default" { + default = true +} - tags = { - "kubernetes.io/cluster/eks" = "shared", - Environment = "test" - } +data "aws_subnet_ids" "all" { + vpc_id = data.aws_vpc.default.id } ##### # EKS Cluster ##### - resource "aws_eks_cluster" "cluster" { enabled_cluster_log_types = [] - name = "eks" + name = "eks-module-test-cluster" role_arn = aws_iam_role.cluster.arn - version = "1.18" + version = "1.20" vpc_config { - subnet_ids = flatten([module.vpc.public_subnets, module.vpc.private_subnets]) + subnet_ids = data.aws_subnet_ids.all.ids security_group_ids = [] endpoint_private_access = "true" endpoint_public_access = "true" @@ -93,10 +67,10 @@ module "eks-node-group" { cluster_name = aws_eks_cluster.cluster.id - subnet_ids = flatten([module.vpc.private_subnets]) + subnet_ids = data.aws_subnet_ids.all.ids desired_size = 2 - min_size = 2 + min_size = 1 max_size = 2 capacity_type = "SPOT" @@ -104,7 +78,25 @@ module "eks-node-group" { ec2_ssh_key = "eks-test" - kubernetes_labels = { + taints = [ + { + key = "test-1" + value = null + effect = "NO_SCHEDULE" + }, + { + key = "test-2" + value = "value-test" + effect = "NO_EXECUTE" + }, + { + key = "test-3" + value = "value-test-3" + effect = "PREFER_NO_SCHEDULE" + } + ] + + labels = { lifecycle = "SPOT" } diff --git a/main.tf b/main.tf index e49ab9a..f79c438 100644 --- a/main.tf +++ b/main.tf @@ -1,5 +1,5 @@ resource "random_id" "main" { - count = var.node_group_name == "" ? 1 : 0 + count = var.node_group_name == null && var.node_group_name_prefix == null ? 1 : 0 byte_length = 4 @@ -21,9 +21,11 @@ resource "random_id" "main" { } resource "aws_eks_node_group" "main" { - cluster_name = var.cluster_name - node_group_name = var.node_group_name == "" ? join("-", [var.cluster_name, random_id.main[0].hex]) : var.node_group_name - node_role_arn = var.node_role_arn == "" ? join("", aws_iam_role.main.*.arn) : var.node_role_arn + cluster_name = var.cluster_name + + node_group_name_prefix = var.node_group_name_prefix + node_group_name = var.node_group_name == null && var.node_group_name_prefix == null ? join("-", [var.cluster_name, random_id.main[0].hex]) : var.node_group_name + node_role_arn = var.node_role_arn == "" ? join("", aws_iam_role.main.*.arn) : var.node_role_arn subnet_ids = var.subnet_ids @@ -31,7 +33,8 @@ resource "aws_eks_node_group" "main" { disk_size = var.disk_size instance_types = var.instance_types capacity_type = var.capacity_type - labels = var.kubernetes_labels + + labels = var.labels release_version = var.ami_release_version version = var.kubernetes_version @@ -46,6 +49,15 @@ resource "aws_eks_node_group" "main" { min_size = var.min_size } + dynamic "taint" { + for_each = var.taints + content { + key = lookup(taint.value, "key") + value = lookup(taint.value, "value") + effect = lookup(taint.value, "effect") + } + } + dynamic "remote_access" { for_each = var.ec2_ssh_key != null && var.ec2_ssh_key != "" ? ["true"] : [] content { diff --git a/variables.tf b/variables.tf index a7dbf6f..e3b4461 100644 --- a/variables.tf +++ b/variables.tf @@ -59,7 +59,7 @@ variable "instance_types" { default = null } -variable "kubernetes_labels" { +variable "labels" { type = map(string) description = "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" default = {} @@ -92,7 +92,13 @@ variable "create_iam_role" { variable "node_group_name" { type = string description = "The name of the cluster node group. Defaults to -" - default = "" + default = null +} + +variable "node_group_name_prefix" { + type = string + description = "Creates a unique name beginning with the specified prefix. Conflicts with node_group_name" + default = null } variable "node_group_role_name" { @@ -118,3 +124,9 @@ variable "capacity_type" { description = "Type of capacity associated with the EKS Node Group. Defaults to ON_DEMAND. Valid values: ON_DEMAND, SPOT." default = "ON_DEMAND" } + +variable "taints" { + type = list(object({ key = string, value = any, effect = string })) + description = "List of objects containing Kubernetes taints which will be applied to the nodes in the node group. Maximum of 50 taints per node group." + default = [] +} diff --git a/versions.tf b/versions.tf index 9d71257..aae7037 100644 --- a/versions.tf +++ b/versions.tf @@ -2,6 +2,6 @@ terraform { required_version = ">= 0.12.6" required_providers { - aws = ">= 3.19" + aws = ">= 3.43" } }