From 11c13c967b5847e200a6e7d3b180df050d81f37e Mon Sep 17 00:00:00 2001 From: Peter Svensson Date: Wed, 17 Jul 2024 11:10:29 +0200 Subject: [PATCH] feat: support changing architecture for nodes --- ami.tf | 32 +++++++++++++++++++++++++++++--- k8s.tf | 6 +++--- vars.tf | 12 ++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/ami.tf b/ami.tf index 17c75e4..70a4be1 100644 --- a/ami.tf +++ b/ami.tf @@ -1,6 +1,6 @@ -data "aws_ami" "default_image" { +data "aws_ami" "default_node_image" { most_recent = true - name_regex = "^ubuntu/.*focal-20.04-amd64-server-\\d+(\\.\\d+)?$" + name_regex = "^ubuntu/.*focal-20.04-.*-server-\\d+(\\.\\d+)?$" owners = ["099720109477"] filter { @@ -10,7 +10,33 @@ data "aws_ami" "default_image" { filter { name = "architecture" - values = ["x86_64"] + values = [var.architecture] + } + + filter { + name = "root-device-type" + values = ["ebs"] + } + + filter { + name = "virtualization-type" + values = ["hvm"] + } +} + +data "aws_ami" "default_master_image" { + most_recent = true + name_regex = "^ubuntu/.*focal-20.04-.*-server-\\d+(\\.\\d+)?$" + owners = ["099720109477"] + + filter { + name = "name" + values = ["ubuntu/*focal*"] + } + + filter { + name = "architecture" + values = [coalesce(var.master_architecture, var.architecture)] } filter { diff --git a/k8s.tf b/k8s.tf index 7d5d9ad..3cd0cb3 100644 --- a/k8s.tf +++ b/k8s.tf @@ -237,7 +237,7 @@ resource "kops_instance_group" "masters" { cluster_name = kops_cluster.k8s.id name = "${var.control_plane_prefix}-${var.region}${each.key}" role = "ControlPlane" - image = coalesce(var.master_image, var.image, "${data.aws_ami.default_image.owner_id}/${data.aws_ami.default_image.name}") + image = coalesce(var.master_image, var.image, "${data.aws_ami.default_master_image.owner_id}/${data.aws_ami.default_master_image.name}") min_size = 1 max_size = 1 machine_type = var.master_types[0] @@ -272,7 +272,7 @@ resource "kops_instance_group" "nodes" { cluster_name = kops_cluster.k8s.id name = "nodes-${each.key}" role = "Node" - image = coalesce(var.node_image, var.image, "${data.aws_ami.default_image.owner_id}/${data.aws_ami.default_image.name}") + image = coalesce(var.node_image, var.image, "${data.aws_ami.default_node_image.owner_id}/${data.aws_ami.default_node_image.name}") min_size = lookup(local.min_nodes, each.key) max_size = lookup(local.max_nodes, each.key) machine_type = var.node_types[0] @@ -311,7 +311,7 @@ resource "kops_instance_group" "additional_nodes" { cluster_name = kops_cluster.k8s.id name = "nodes-${each.key}" role = "Node" - image = coalesce(each.value.image, var.image, "${data.aws_ami.default_image.owner_id}/${data.aws_ami.default_image.name}") + image = coalesce(each.value.image, var.image, "${data.aws_ami.default_node_image.owner_id}/${data.aws_ami.default_node_image.name}") min_size = each.value.min_size max_size = each.value.max_size machine_type = each.value.types[0] diff --git a/vars.tf b/vars.tf index e67ed38..b1ca709 100644 --- a/vars.tf +++ b/vars.tf @@ -48,6 +48,18 @@ variable "dns_zone" { description = "Name of DNS zone to use for cluster" } +variable "architecture" { + type = string + description = "The architecture to use for finding ami image for nodes" + default = "x86_64" +} + +variable "master_architecture" { + type = string + description = "The architecture to use for finding ami image for control plane" + default = null +} + variable "image" { type = string description = "The image to use for instances (can be overridden by master_image, node_image and image in additional_nodes)"