Skip to content

Commit

Permalink
Add support to provide an external AMI id (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: Victor Jimenez <vjimenez@vista.com>
  • Loading branch information
betabandido and Victor Jimenez authored Oct 11, 2023
1 parent bc1a715 commit 03b0c87
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 85 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ override.tf.json
.terraformrc
terraform.rc

.terraform.lock.hcl

### Vim ###
# Swap
[._]*.s[a-v][a-z]
Expand Down
80 changes: 0 additions & 80 deletions examples/basic/.terraform.lock.hcl

This file was deleted.

30 changes: 28 additions & 2 deletions examples/basic/cluster.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
locals {
cluster_name = "simple-eks-integration-test-for-eks-node-group"
cluster_version = "1.23"
cluster_version = "1.28"
}

module "cluster" {
source = "vistaprint/simple-eks/aws"
version = "0.4.0-rc1"
version = "0.4.0"

cluster_name = local.cluster_name
cluster_version = local.cluster_version
Expand Down Expand Up @@ -64,3 +64,29 @@ module "ebs_encrypted_node_group" {

depends_on = [module.cluster]
}

module "custom_ami_node_group" {
source = "../.."

cluster_name = local.cluster_name
node_group_version = local.cluster_version
node_group_name = "custom-ami"

instance_types = ["t3a.small"]

image_id = "ami-0d028bd9a57562372"

scaling_config = {
desired_size = 1
max_size = 1
min_size = 1
}

worker_role_arn = module.cluster.worker_role_arn
subnet_ids = module.cluster.private_subnet_ids

region = var.aws_region
profile = var.aws_profile

depends_on = [module.cluster]
}
8 changes: 6 additions & 2 deletions launch-template.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ locals {
x86_64_ami = "amazon-eks-node-${var.node_group_version}-v*"
arm64_ami = "amazon-eks-arm64-node-${var.node_group_version}-v*"

ami_id = var.image_id != null ? var.image_id : data.aws_ami.ami.0.id

node_labels = "--node-labels=${join(",", [
"eks.amazonaws.com/nodegroup-image=${data.aws_ami.ami.id}",
"eks.amazonaws.com/nodegroup-image=${local.ami_id}",
"eks.amazonaws.com/capacityType=${local.capacity_type}",
"eks.amazonaws.com/nodegroup=${var.node_group_name}"
])}"
Expand All @@ -29,6 +31,8 @@ locals {
}

data "aws_ami" "ami" {
count = var.image_id == null ? 1 : 0

most_recent = true
name_regex = var.architecture == "x86_64" ? local.x86_64_ami : local.arm64_ami
owners = ["amazon"]
Expand All @@ -39,7 +43,7 @@ resource "aws_launch_template" "worker_nodes" {

name = "${var.cluster_name}-${var.node_group_name}"

image_id = data.aws_ami.ami.id
image_id = local.ami_id

block_device_mappings {
device_name = "/dev/xvda"
Expand Down
2 changes: 1 addition & 1 deletion test/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func TestTerraformBasicExample(t *testing.T) {
terraform.InitAndApply(t, terraformOptions)

checkNodeGroupExists(t, "basic")
checkNodeGroupExists(t, "calico")
checkNodeGroupExists(t, "encrypt-ebs")
checkNodeGroupExists(t, "custom-ami")
}

func checkNodeGroupExists(t *testing.T, nodeGroupName string) {
Expand Down
7 changes: 7 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ variable "architecture" {
}
}

variable "image_id" {
type = string
default = null

description = "AMI id to use for the node group"
}

variable "worker_role_arn" {
type = string
}
Expand Down

0 comments on commit 03b0c87

Please sign in to comment.