From 32632bde67fa97277cee3838330d1dac634d59a6 Mon Sep 17 00:00:00 2001 From: Marcin Cuber Date: Wed, 2 Dec 2020 11:39:37 +0000 Subject: [PATCH] Add support for capacity_type (#9) --- .pre-commit-config.yaml | 2 +- README.md | 16 +++++++++------- examples/multiaz-node-group/main.tf | 4 ++-- examples/single-named-node-group/main.tf | 4 ++-- .../main.tf | 4 ++-- examples/single-node-group/main.tf | 15 +++++++++------ main.tf | 2 ++ variables.tf | 6 ++++++ versions.tf | 2 +- 9 files changed, 34 insertions(+), 21 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2fe97d5..b5335fa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: args: ['--allow-missing-credentials'] - id: trailing-whitespace - repo: git://github.com/antonbabenko/pre-commit-terraform - rev: v1.44.0 + rev: v1.45.0 hooks: - id: terraform_fmt - id: terraform_docs diff --git a/README.md b/README.md index f80d7b5..1d59761 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,8 @@ module "eks-node-group" { min_size = 1 max_size = 1 - instance_types = ["t3.large"] + instance_types = ["t3.large","t2.large"] + capacity_type = "SPOT" ec2_ssh_key = "eks-test" @@ -61,13 +62,13 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [LinkedIn](http | Name | Version | |------|---------| | terraform | >= 0.12.6 | -| aws | >= 2.63 | +| aws | >= 3.19 | ## Providers | Name | Version | |------|---------| -| aws | >= 2.63 | +| aws | >= 3.19 | | random | n/a | ## Inputs @@ -75,17 +76,18 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [LinkedIn](http | 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. 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 | +| 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` | `20` | no | +| 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 | -| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | `bool` | `true` | 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 | 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)` |
[
"t3.medium"
]
| 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 | diff --git a/examples/multiaz-node-group/main.tf b/examples/multiaz-node-group/main.tf index eb5b281..8e35a70 100644 --- a/examples/multiaz-node-group/main.tf +++ b/examples/multiaz-node-group/main.tf @@ -7,7 +7,7 @@ provider "aws" { ##### module "vpc" { source = "terraform-aws-modules/vpc/aws" - version = "2.48.0" + version = "2.64.0" name = "simple-vpc" @@ -46,7 +46,7 @@ resource "aws_eks_cluster" "cluster" { enabled_cluster_log_types = [] name = "eks" role_arn = aws_iam_role.cluster.arn - version = "1.17" + version = "1.18" vpc_config { subnet_ids = flatten([module.vpc.public_subnets, module.vpc.private_subnets]) diff --git a/examples/single-named-node-group/main.tf b/examples/single-named-node-group/main.tf index e0aaabf..1695bb2 100644 --- a/examples/single-named-node-group/main.tf +++ b/examples/single-named-node-group/main.tf @@ -7,7 +7,7 @@ provider "aws" { ##### module "vpc" { source = "terraform-aws-modules/vpc/aws" - version = "2.48.0" + version = "2.64.0" name = "simple-vpc" @@ -46,7 +46,7 @@ resource "aws_eks_cluster" "cluster" { enabled_cluster_log_types = [] name = "eks" role_arn = aws_iam_role.cluster.arn - version = "1.17" + version = "1.18" vpc_config { subnet_ids = flatten([module.vpc.public_subnets, module.vpc.private_subnets]) diff --git a/examples/single-node-group-with-launch-template/main.tf b/examples/single-node-group-with-launch-template/main.tf index 41f5c2a..43b7adb 100644 --- a/examples/single-node-group-with-launch-template/main.tf +++ b/examples/single-node-group-with-launch-template/main.tf @@ -7,7 +7,7 @@ provider "aws" { ##### module "vpc" { source = "terraform-aws-modules/vpc/aws" - version = "2.48.0" + version = "2.64.0" name = "simple-vpc" @@ -46,7 +46,7 @@ resource "aws_eks_cluster" "cluster" { enabled_cluster_log_types = [] name = "eks" role_arn = aws_iam_role.cluster.arn - version = "1.17" + version = "1.18" vpc_config { subnet_ids = flatten([module.vpc.public_subnets, module.vpc.private_subnets]) diff --git a/examples/single-node-group/main.tf b/examples/single-node-group/main.tf index 7344d99..5c46037 100644 --- a/examples/single-node-group/main.tf +++ b/examples/single-node-group/main.tf @@ -7,7 +7,7 @@ provider "aws" { ##### module "vpc" { source = "terraform-aws-modules/vpc/aws" - version = "2.48.0" + version = "2.64.0" name = "simple-vpc" @@ -46,7 +46,7 @@ resource "aws_eks_cluster" "cluster" { enabled_cluster_log_types = [] name = "eks" role_arn = aws_iam_role.cluster.arn - version = "1.17" + version = "1.18" vpc_config { subnet_ids = flatten([module.vpc.public_subnets, module.vpc.private_subnets]) @@ -95,14 +95,17 @@ module "eks-node-group" { subnet_ids = flatten([module.vpc.private_subnets]) - desired_size = 1 - min_size = 1 - max_size = 1 + desired_size = 2 + min_size = 2 + max_size = 2 + + capacity_type = "SPOT" + instance_types = ["t3.medium", "t2.medium"] ec2_ssh_key = "eks-test" kubernetes_labels = { - lifecycle = "OnDemand" + lifecycle = "SPOT" } tags = { diff --git a/main.tf b/main.tf index 8cbcefc..e49ab9a 100644 --- a/main.tf +++ b/main.tf @@ -7,6 +7,7 @@ resource "random_id" "main" { ami_type = var.ami_type disk_size = var.disk_size instance_types = var.instance_types != null ? join("|", var.instance_types) : "" + capacity_type = var.capacity_type node_role_arn = var.node_role_arn ec2_ssh_key = var.ec2_ssh_key @@ -29,6 +30,7 @@ resource "aws_eks_node_group" "main" { ami_type = var.ami_type disk_size = var.disk_size instance_types = var.instance_types + capacity_type = var.capacity_type labels = var.kubernetes_labels release_version = var.ami_release_version diff --git a/variables.tf b/variables.tf index 12b0fdd..a7dbf6f 100644 --- a/variables.tf +++ b/variables.tf @@ -112,3 +112,9 @@ variable "launch_template" { description = "Configuration block with Launch Template settings. `name`, `id` and `version` parameters are available." default = {} } + +variable "capacity_type" { + type = string + description = "Type of capacity associated with the EKS Node Group. Defaults to ON_DEMAND. Valid values: ON_DEMAND, SPOT." + default = "ON_DEMAND" +} diff --git a/versions.tf b/versions.tf index e49b526..9d71257 100644 --- a/versions.tf +++ b/versions.tf @@ -2,6 +2,6 @@ terraform { required_version = ">= 0.12.6" required_providers { - aws = ">= 3.3" + aws = ">= 3.19" } }