Skip to content
This repository has been archived by the owner on Oct 30, 2022. It is now read-only.

Add support for Launch templates #2

Merged
merged 3 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
| Name | Version |
|------|---------|
| terraform | >= 0.12.9 |
| aws | >= 2.55.0 |
| aws | >= 3.3.0 |
| kubernetes | >= 1.11.1 |
| local | >= 1.4 |
| null | >= 2.1 |
Expand All @@ -151,7 +151,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a

| Name | Version |
|------|---------|
| aws | >= 2.55.0 |
| aws | >= 3.3.0 |
| kubernetes | >= 1.11.1 |
| local | >= 1.4 |
| null | >= 2.1 |
Expand Down
2 changes: 1 addition & 1 deletion examples/irsa/irsa.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module "iam_assumable_role_admin" {
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
version = "~> v2.6.0"
version = "~> v2.0"
create_role = true
role_name = "cluster-autoscaler"
provider_url = replace(module.eks.cluster_oidc_issuer_url, "https://", "")
Expand Down
1 change: 1 addition & 0 deletions local.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ locals {
# Settings for launch templates
root_block_device_name = data.aws_ami.eks_worker.root_device_name # Root device name for workers. If non is provided, will assume default AMI was used.
root_kms_key_id = "" # The KMS key to use when encrypting the root storage device
launch_template_id = "" # The id of the launch template used for managed node_groups
launch_template_version = "$Latest" # The lastest version of the launch template to use in the autoscaling group
launch_template_placement_tenancy = "default" # The placement tenancy for instances
launch_template_placement_group = null # The name of the placement group into which to launch the instances, if any.
Expand Down
16 changes: 9 additions & 7 deletions modules/node_groups/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ locals {
# Merge defaults and per-group values to make code cleaner
node_groups_expanded = { for k, v in var.node_groups : k => merge(
{
desired_capacity = var.workers_group_defaults["asg_desired_capacity"]
iam_role_arn = var.default_iam_role_arn
instance_type = var.workers_group_defaults["instance_type"]
key_name = var.workers_group_defaults["key_name"]
max_capacity = var.workers_group_defaults["asg_max_size"]
min_capacity = var.workers_group_defaults["asg_min_size"]
subnets = var.workers_group_defaults["subnets"]
desired_capacity = var.workers_group_defaults["asg_desired_capacity"]
iam_role_arn = var.default_iam_role_arn
instance_type = var.workers_group_defaults["instance_type"]
key_name = var.workers_group_defaults["key_name"]
launch_template_id = var.workers_group_defaults["launch_template_id"]
launch_template_version = var.workers_group_defaults["launch_template_version"]
max_capacity = var.workers_group_defaults["asg_max_size"]
min_capacity = var.workers_group_defaults["asg_min_size"]
subnets = var.workers_group_defaults["subnets"]
},
var.node_groups_defaults,
v,
Expand Down
14 changes: 13 additions & 1 deletion modules/node_groups/node_groups.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ resource "aws_eks_node_group" "workers" {

ami_type = lookup(each.value, "ami_type", null)
disk_size = lookup(each.value, "disk_size", null)
instance_types = [each.value["instance_type"]]
instance_types = each.value["launch_template_id"] != "" ? [] : [each.value["instance_type"]]
release_version = lookup(each.value, "ami_release_version", null)

dynamic "remote_access" {
Expand All @@ -30,6 +30,18 @@ resource "aws_eks_node_group" "workers" {
}
}

dynamic "launch_template" {
for_each = each.value["launch_template_id"] != "" ? [{
id = each.value["launch_template_id"]
version = each.value["launch_template_version"]
}] : []

content {
id = launch_template.value["id"]
version = launch_template.value["version"]
}
}

version = lookup(each.value, "version", null)

labels = merge(
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_version = ">= 0.12.9"

required_providers {
aws = ">= 2.55.0"
aws = ">= 3.3.0"
local = ">= 1.4"
null = ">= 2.1"
template = ">= 2.1"
Expand Down