Skip to content

Commit

Permalink
feat: support changing architecture for nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-svensson committed Jul 17, 2024
1 parent 7d4815c commit 11c13c9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
32 changes: 29 additions & 3 deletions ami.tf
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions k8s.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
12 changes: 12 additions & 0 deletions vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down

0 comments on commit 11c13c9

Please sign in to comment.