Skip to content

Commit

Permalink
feat: fetch latest focal image if not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
argoyle committed Dec 4, 2023
1 parent ff310a0 commit a61db15
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
25 changes: 25 additions & 0 deletions ami.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
data "aws_ami" "default_image" {
most_recent = true
name_regex = "^ubuntu/.*focal-20.04-amd64-server-\\d+(\\.\\d+)?$"
owners = ["099720109477"]

filter {
name = "name"
values = ["ubuntu/*focal*"]
}

filter {
name = "architecture"
values = ["x86_64"]
}

filter {
name = "root-device-type"
values = ["ebs"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}
}
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 = var.master_image != null ? var.master_image : var.image
image = coalesce(var.master_image, var.image, "${data.aws_ami.default_image.owner_id}/${data.aws_ami.default_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 = var.node_image != null ? var.node_image : var.image
image = coalesce(var.node_image, var.image, "${data.aws_ami.default_image.owner_id}/${data.aws_ami.default_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 = each.value.image != null ? each.value.image : var.image
image = coalesce(each.value.image, var.image, "${data.aws_ami.default_image.owner_id}/${data.aws_ami.default_image.name}")
min_size = each.value.min_size
max_size = each.value.max_size
machine_type = each.value.types[0]
Expand Down

0 comments on commit a61db15

Please sign in to comment.