Skip to content

Commit

Permalink
Merge branch 'master' into node-group-random-pet
Browse files Browse the repository at this point in the history
  • Loading branch information
barryib authored May 19, 2021
2 parents d5a1818 + 06e9078 commit 37762ab
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 28 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ project adheres to [Semantic Versioning](http://semver.org/).



<a name="v16.0.1"></a>
## [v16.0.1] - 2021-05-19
BUG FIXES:
- Bump `terraform-aws-modules/http` provider version to support darwin arm64 release ([#1369](https://github.com/terraform-aws-modules/terraform-aws-eks/issues/1369))

DOCS:
- Use IRSA for Node Termination Handler IAM policy attachement in Instance Refresh example ([#1373](https://github.com/terraform-aws-modules/terraform-aws-eks/issues/1373))


<a name="v16.0.0"></a>
## [v16.0.0] - 2021-05-17
FEATURES:
Expand Down Expand Up @@ -301,7 +310,8 @@ CI:
- Restrict sementic PR to validate PR title only ([#804](https://github.com/terraform-aws-modules/terraform-aws-eks/issues/804))


[Unreleased]: https://github.com/terraform-aws-modules/terraform-aws-eks/compare/v16.0.0...HEAD
[Unreleased]: https://github.com/terraform-aws-modules/terraform-aws-eks/compare/v16.0.1...HEAD
[v16.0.1]: https://github.com/terraform-aws-modules/terraform-aws-eks/compare/v16.0.0...v16.0.1
[v16.0.0]: https://github.com/terraform-aws-modules/terraform-aws-eks/compare/v15.2.0...v16.0.0
[v15.2.0]: https://github.com/terraform-aws-modules/terraform-aws-eks/compare/v15.1.0...v15.2.0
[v15.1.0]: https://github.com/terraform-aws-modules/terraform-aws-eks/compare/v15.0.0...v15.1.0
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
| <a name="output_workers_asg_arns"></a> [workers\_asg\_arns](#output\_workers\_asg\_arns) | IDs of the autoscaling groups containing workers. |
| <a name="output_workers_asg_names"></a> [workers\_asg\_names](#output\_workers\_asg\_names) | Names of the autoscaling groups containing workers. |
| <a name="output_workers_default_ami_id"></a> [workers\_default\_ami\_id](#output\_workers\_default\_ami\_id) | ID of the default worker group AMI |
| <a name="output_workers_default_ami_id_windows"></a> [workers\_default\_ami\_id\_windows](#output\_workers\_default\_ami\_id\_windows) | ID of the default Windows worker group AMI |
| <a name="output_workers_launch_template_arns"></a> [workers\_launch\_template\_arns](#output\_workers\_launch\_template\_arns) | ARNs of the worker launch templates. |
| <a name="output_workers_launch_template_ids"></a> [workers\_launch\_template\_ids](#output\_workers\_launch\_template\_ids) | IDs of the worker launch templates. |
| <a name="output_workers_launch_template_latest_versions"></a> [workers\_launch\_template\_latest\_versions](#output\_workers\_launch\_template\_latest\_versions) | Latest versions of the worker launch templates. |
Expand Down
1 change: 1 addition & 0 deletions cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ resource "aws_eks_cluster" "this" {
}

resource "aws_security_group_rule" "cluster_private_access" {
description = "Allow private K8S API ingress from custom source."
count = var.create_eks && var.cluster_create_endpoint_private_access_sg_rule && var.cluster_endpoint_private_access ? 1 : 0
type = "ingress"
from_port = 443
Expand Down
4 changes: 4 additions & 0 deletions data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ data "aws_iam_policy_document" "workers_assume_role_policy" {
}

data "aws_ami" "eks_worker" {
count = local.worker_has_linux_ami ? 1 : 0

filter {
name = "name"
values = [local.worker_ami_name_filter]
Expand All @@ -25,6 +27,8 @@ data "aws_ami" "eks_worker" {
}

data "aws_ami" "eks_worker_windows" {
count = local.worker_has_windows_ami ? 1 : 0

filter {
name = "name"
values = [local.worker_ami_name_filter_windows]
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module "vpc" {
module "eks" {
source = "../.."
cluster_name = local.cluster_name
cluster_version = "1.17"
cluster_version = "1.20"
subnets = module.vpc.private_subnets

tags = {
Expand Down
2 changes: 1 addition & 1 deletion examples/fargate/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module "vpc" {
module "eks" {
source = "../.."
cluster_name = local.cluster_name
cluster_version = "1.17"
cluster_version = "1.20"
subnets = module.vpc.private_subnets

tags = {
Expand Down
11 changes: 6 additions & 5 deletions examples/instance_refresh/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,9 @@ resource "helm_release" "aws_node_termination_handler" {
# ensures that node termination does not require the lifecycle action to be completed,
# and thus allows the ASG to be destroyed cleanly.
resource "aws_autoscaling_lifecycle_hook" "aws_node_termination_handler" {
for_each = toset(module.eks.workers_asg_names)

count = length(module.eks.workers_asg_names)
name = "aws-node-termination-handler"
autoscaling_group_name = each.value
autoscaling_group_name = module.eks.workers_asg_names[count.index]
lifecycle_transition = "autoscaling:EC2_INSTANCE_TERMINATING"
heartbeat_timeout = 300
default_result = "CONTINUE"
Expand All @@ -229,7 +228,7 @@ resource "aws_autoscaling_lifecycle_hook" "aws_node_termination_handler" {
module "eks" {
source = "../.."
cluster_name = local.cluster_name
cluster_version = "1.19"
cluster_version = "1.20"
subnets = module.vpc.public_subnets
vpc_id = module.vpc.vpc_id
enable_irsa = true
Expand All @@ -239,9 +238,11 @@ module "eks" {
asg_max_size = 2
asg_desired_capacity = 2
instance_refresh_enabled = true
instance_refresh_triggers = ["tag"]
instance_refresh_instance_warmup = 60
public_ip = true
metadata_http_put_response_hop_limit = 3
update_default_version = true
instance_refresh_triggers = ["tag"]
tags = [
{
key = "aws-node-termination-handler/managed"
Expand Down
2 changes: 1 addition & 1 deletion examples/irsa/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module "vpc" {
module "eks" {
source = "../.."
cluster_name = local.cluster_name
cluster_version = "1.17"
cluster_version = "1.20"
subnets = module.vpc.public_subnets
vpc_id = module.vpc.vpc_id
enable_irsa = true
Expand Down
2 changes: 1 addition & 1 deletion examples/launch_templates/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module "vpc" {
module "eks" {
source = "../.."
cluster_name = local.cluster_name
cluster_version = "1.17"
cluster_version = "1.20"
subnets = module.vpc.public_subnets
vpc_id = module.vpc.vpc_id

Expand Down
2 changes: 1 addition & 1 deletion examples/launch_templates_with_managed_node_groups/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module "vpc" {
module "eks" {
source = "../.."
cluster_name = local.cluster_name
cluster_version = "1.17"
cluster_version = "1.20"
subnets = module.vpc.private_subnets
vpc_id = module.vpc.vpc_id

Expand Down
2 changes: 1 addition & 1 deletion examples/managed_node_groups/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module "vpc" {
module "eks" {
source = "../.."
cluster_name = local.cluster_name
cluster_version = "1.17"
cluster_version = "1.20"
subnets = module.vpc.private_subnets

tags = {
Expand Down
2 changes: 1 addition & 1 deletion examples/secrets_encryption/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module "vpc" {
module "eks" {
source = "../.."
cluster_name = local.cluster_name
cluster_version = "1.17"
cluster_version = "1.20"
subnets = module.vpc.private_subnets

cluster_encryption_config = [
Expand Down
2 changes: 1 addition & 1 deletion examples/spot_instances/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module "vpc" {
module "eks" {
source = "../.."
cluster_name = local.cluster_name
cluster_version = "1.17"
cluster_version = "1.20"
subnets = module.vpc.public_subnets
vpc_id = module.vpc.vpc_id

Expand Down
26 changes: 15 additions & 11 deletions local.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ locals {
worker_security_group_id = var.worker_create_security_group ? join("", aws_security_group.workers.*.id) : var.worker_security_group_id

default_iam_role_id = concat(aws_iam_role.workers.*.id, [""])[0]
default_ami_id_linux = coalesce(local.workers_group_defaults.ami_id, data.aws_ami.eks_worker.id)
default_ami_id_windows = coalesce(local.workers_group_defaults.ami_id_windows, data.aws_ami.eks_worker_windows.id)
default_ami_id_linux = local.workers_group_defaults.ami_id != "" ? local.workers_group_defaults.ami_id : concat(data.aws_ami.eks_worker.*.id, [""])[0]
default_ami_id_windows = local.workers_group_defaults.ami_id_windows != "" ? local.workers_group_defaults.ami_id_windows : concat(data.aws_ami.eks_worker_windows.*.id, [""])[0]

kubeconfig_name = var.kubeconfig_name == "" ? "eks_${var.cluster_name}" : var.kubeconfig_name

worker_group_count = length(var.worker_groups)
worker_group_launch_template_count = length(var.worker_groups_launch_template)

worker_has_linux_ami = length([for x in concat(var.worker_groups, var.worker_groups_launch_template) : x if lookup(x, "platform", "linux") == "linux"]) > 0
worker_has_windows_ami = length([for x in concat(var.worker_groups, var.worker_groups_launch_template) : x if lookup(x, "platform", "linux") == "windows"]) > 0

worker_ami_name_filter = var.worker_ami_name_filter != "" ? var.worker_ami_name_filter : "amazon-eks-node-${var.cluster_version}-v*"
# Windows nodes are available from k8s 1.14. If cluster version is less than 1.14, fix ami filter to some constant to not fail on 'terraform plan'.
worker_ami_name_filter_windows = (var.worker_ami_name_filter_windows != "" ?
Expand Down Expand Up @@ -72,15 +75,16 @@ locals {
additional_ebs_volumes = [] # A list of additional volumes to be attached to the instances on this Auto Scaling group. Each volume should be an object with the following: block_device_name (required), volume_size, volume_type, iops, encrypted, kms_key_id (only on launch-template), delete_on_termination. Optional values are grabbed from root volume or from defaults
warm_pool = null # If this block is configured, add a Warm Pool to the specified Auto Scaling group.
# Settings for launch templates
root_block_device_name = data.aws_ami.eks_worker.root_device_name # Root device name for workers. If non is provided, will assume default AMI was used.
root_kms_key_id = "" # The KMS key to use when encrypting the root storage device
launch_template_id = null # The id of the launch template used for managed node_groups
launch_template_version = "$Latest" # The lastest version of the launch template to use in the autoscaling group
launch_template_placement_tenancy = "default" # The placement tenancy for instances
launch_template_placement_group = null # The name of the placement group into which to launch the instances, if any.
root_encrypted = false # Whether the volume should be encrypted or not
eni_delete = true # Delete the Elastic Network Interface (ENI) on termination (if set to false you will have to manually delete before destroying)
cpu_credits = "standard" # T2/T3 unlimited mode, can be 'standard' or 'unlimited'. Used 'standard' mode as default to avoid paying higher costs
root_block_device_name = concat(data.aws_ami.eks_worker.*.root_device_name, [""])[0] # Root device name for workers. If non is provided, will assume default AMI was used.
root_kms_key_id = "" # The KMS key to use when encrypting the root storage device
launch_template_id = null # The id of the launch template used for managed node_groups
launch_template_version = "$Latest" # The latest version of the launch template to use in the autoscaling group
update_default_version = false # Update the autoscaling group launch template's default version upon each update
launch_template_placement_tenancy = "default" # The placement tenancy for instances
launch_template_placement_group = null # The name of the placement group into which to launch the instances, if any.
root_encrypted = false # Whether the volume should be encrypted or not
eni_delete = true # Delete the Elastic Network Interface (ENI) on termination (if set to false you will have to manually delete before destroying)
cpu_credits = "standard" # T2/T3 unlimited mode, can be 'standard' or 'unlimited'. Used 'standard' mode as default to avoid paying higher costs
market_type = null
metadata_http_endpoint = "enabled" # The state of the metadata service: enabled, disabled.
metadata_http_tokens = "optional" # If session tokens are required: optional, required.
Expand Down
7 changes: 6 additions & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ output "workers_user_data" {

output "workers_default_ami_id" {
description = "ID of the default worker group AMI"
value = data.aws_ami.eks_worker.id
value = local.default_ami_id_linux
}

output "workers_default_ami_id_windows" {
description = "ID of the default Windows worker group AMI"
value = local.default_ami_id_windows
}

output "workers_launch_template_ids" {
Expand Down
22 changes: 20 additions & 2 deletions workers_launch_template.tf
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,13 @@ resource "aws_autoscaling_group" "workers_launch_template" {
version = lookup(
var.worker_groups_launch_template[count.index],
"launch_template_version",
local.workers_group_defaults["launch_template_version"],
lookup(
var.worker_groups_launch_template[count.index],
"launch_template_version",
local.workers_group_defaults["launch_template_version"]
) == "$Latest"
? aws_launch_template.workers_launch_template.*.latest_version[count.index]
: aws_launch_template.workers_launch_template.*.default_version[count.index]
)
}

Expand Down Expand Up @@ -169,7 +175,13 @@ resource "aws_autoscaling_group" "workers_launch_template" {
version = lookup(
var.worker_groups_launch_template[count.index],
"launch_template_version",
local.workers_group_defaults["launch_template_version"],
lookup(
var.worker_groups_launch_template[count.index],
"launch_template_version",
local.workers_group_defaults["launch_template_version"]
) == "$Latest"
? aws_launch_template.workers_launch_template.*.latest_version[count.index]
: aws_launch_template.workers_launch_template.*.default_version[count.index]
)
}
}
Expand Down Expand Up @@ -278,6 +290,12 @@ resource "aws_launch_template" "workers_launch_template" {
count.index,
)}"

update_default_version = lookup(
var.worker_groups_launch_template[count.index],
"update_default_version",
local.workers_group_defaults["update_default_version"],
)

network_interfaces {
associate_public_ip_address = lookup(
var.worker_groups_launch_template[count.index],
Expand Down

0 comments on commit 37762ab

Please sign in to comment.