From da76d32abad5ac7a468953d8c3b2fc7bbec81387 Mon Sep 17 00:00:00 2001 From: Dalton Hubble Date: Tue, 29 Nov 2022 23:54:07 -0800 Subject: [PATCH] Migrate AWS launch configurations to launch templates * Same features, but AWS will soon require launch templates * Starting Dec 31, 2022 AWS will not add new instance types (e.g. graviton 4) to launch configuration support Rel: https://aws.amazon.com/blogs/compute/amazon-ec2-auto-scaling-will-no-longer-add-support-for-new-ec2-features-to-launch-configurations/ --- CHANGES.md | 5 ++ aws/fedora-coreos/kubernetes/controllers.tf | 1 + .../kubernetes/workers/workers.tf | 48 +++++++++++++------ aws/flatcar-linux/kubernetes/controllers.tf | 1 + .../kubernetes/workers/workers.tf | 48 +++++++++++++------ 5 files changed, 75 insertions(+), 28 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 804617df..bd939760 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,11 @@ Notable changes between versions. * Update Cilium from v1.12.3 to [v1.12.4](https://github.com/cilium/cilium/releases/tag/v1.12.4) * Update flannel from v0.15.1 to [v0.20.1](https://github.com/flannel-io/flannel/releases/tag/v0.20.1) +### AWS + +* Migrate AWS launch configurations to launch templates + * Starting Dec 31, 2022 AWS won't add new instance types/families to launch configurations + ### Addons * Update Prometheus from v2.40.1 to [v2.40.2](https://github.com/prometheus/prometheus/releases/tag/v2.40.2) diff --git a/aws/fedora-coreos/kubernetes/controllers.tf b/aws/fedora-coreos/kubernetes/controllers.tf index a6691f1b..ad4d8c84 100644 --- a/aws/fedora-coreos/kubernetes/controllers.tf +++ b/aws/fedora-coreos/kubernetes/controllers.tf @@ -31,6 +31,7 @@ resource "aws_instance" "controllers" { volume_size = var.disk_size iops = var.disk_iops encrypted = true + tags = {} } # network diff --git a/aws/fedora-coreos/kubernetes/workers/workers.tf b/aws/fedora-coreos/kubernetes/workers/workers.tf index 9508808b..1b0fc1e3 100644 --- a/aws/fedora-coreos/kubernetes/workers/workers.tf +++ b/aws/fedora-coreos/kubernetes/workers/workers.tf @@ -13,7 +13,10 @@ resource "aws_autoscaling_group" "workers" { vpc_zone_identifier = var.subnet_ids # template - launch_configuration = aws_launch_configuration.worker.name + launch_template { + id = aws_launch_template.worker.id + version = aws_launch_template.worker.latest_version + } # target groups to which instances should be added target_group_arns = flatten([ @@ -49,25 +52,42 @@ resource "aws_autoscaling_group" "workers" { } # Worker template -resource "aws_launch_configuration" "worker" { - name_prefix = "${var.name}-worker" - image_id = local.ami_id - instance_type = var.instance_type - spot_price = var.spot_price > 0 ? var.spot_price : null - enable_monitoring = false +resource "aws_launch_template" "worker" { + name_prefix = "${var.name}-worker" + image_id = local.ami_id + instance_type = var.instance_type + monitoring { + enabled = false + } - user_data = data.ct_config.worker.rendered + user_data = sensitive(base64encode(data.ct_config.worker.rendered)) # storage - root_block_device { - volume_type = var.disk_type - volume_size = var.disk_size - iops = var.disk_iops - encrypted = true + ebs_optimized = true + block_device_mappings { + device_name = "/dev/xvda" + ebs { + volume_type = var.disk_type + volume_size = var.disk_size + iops = var.disk_iops + encrypted = true + delete_on_termination = true + } } # network - security_groups = var.security_groups + vpc_security_group_ids = var.security_groups + + # spot + dynamic "instance_market_options" { + for_each = var.spot_price > 0 ? [1] : [] + content { + market_type = "spot" + spot_options { + max_price = var.spot_price + } + } + } lifecycle { // Override the default destroy and replace update behavior diff --git a/aws/flatcar-linux/kubernetes/controllers.tf b/aws/flatcar-linux/kubernetes/controllers.tf index 84b61d77..82d92ce8 100644 --- a/aws/flatcar-linux/kubernetes/controllers.tf +++ b/aws/flatcar-linux/kubernetes/controllers.tf @@ -32,6 +32,7 @@ resource "aws_instance" "controllers" { volume_size = var.disk_size iops = var.disk_iops encrypted = true + tags = {} } # network diff --git a/aws/flatcar-linux/kubernetes/workers/workers.tf b/aws/flatcar-linux/kubernetes/workers/workers.tf index 576de30b..67c015ca 100644 --- a/aws/flatcar-linux/kubernetes/workers/workers.tf +++ b/aws/flatcar-linux/kubernetes/workers/workers.tf @@ -13,7 +13,10 @@ resource "aws_autoscaling_group" "workers" { vpc_zone_identifier = var.subnet_ids # template - launch_configuration = aws_launch_configuration.worker.name + launch_template { + id = aws_launch_template.worker.id + version = aws_launch_template.worker.latest_version + } # target groups to which instances should be added target_group_arns = flatten([ @@ -49,25 +52,42 @@ resource "aws_autoscaling_group" "workers" { } # Worker template -resource "aws_launch_configuration" "worker" { - name_prefix = "${var.name}-worker" - image_id = local.ami_id - instance_type = var.instance_type - spot_price = var.spot_price > 0 ? var.spot_price : null - enable_monitoring = false +resource "aws_launch_template" "worker" { + name_prefix = "${var.name}-worker" + image_id = local.ami_id + instance_type = var.instance_type + monitoring { + enabled = false + } - user_data = data.ct_config.worker.rendered + user_data = sensitive(base64encode(data.ct_config.worker.rendered)) # storage - root_block_device { - volume_type = var.disk_type - volume_size = var.disk_size - iops = var.disk_iops - encrypted = true + ebs_optimized = true + block_device_mappings { + device_name = "/dev/xvda" + ebs { + volume_type = var.disk_type + volume_size = var.disk_size + iops = var.disk_iops + encrypted = true + delete_on_termination = true + } } # network - security_groups = var.security_groups + vpc_security_group_ids = var.security_groups + + # spot + dynamic "instance_market_options" { + for_each = var.spot_price > 0 ? [1] : [] + content { + market_type = "spot" + spot_options { + max_price = var.spot_price + } + } + } lifecycle { // Override the default destroy and replace update behavior