mirror of
https://github.com/ysoftdevs/terraform-aws-eks.git
synced 2026-02-24 03:24:50 +01:00
add option to recreate ASG when LT or LC changes (#465)
This commit is contained in:
committed by
Max Williams
parent
5636447de6
commit
d8ed7d0b66
@@ -16,6 +16,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- Added support for workers iam role tag in `./workers.tf` (@lucas-giaco)
|
||||
- Added `required_providers` to enforce provider minimum versions (by @dpiddockcmp)
|
||||
- Updated `local.spot_allocation_strategy` docstring to indicate availability of new `capacity-optimized` option. (by @sc250024)
|
||||
- Added option to recreate ASG when LT or LC changes (by @barryib)
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
1
local.tf
1
local.tf
@@ -21,6 +21,7 @@ locals {
|
||||
asg_max_size = "3" # Maximum worker capacity in the autoscaling group.
|
||||
asg_min_size = "1" # Minimum worker capacity in the autoscaling group.
|
||||
asg_force_delete = false # Enable forced deletion for the autoscaling group.
|
||||
asg_recreate_on_change = false # Recreate the autoscaling group when LT or LC change.
|
||||
instance_type = "m4.large" # Size of the workers instances.
|
||||
spot_price = "" # Cost of spot instance.
|
||||
placement_tenancy = "" # The tenancy of the instance. Valid values are "default" or "dedicated".
|
||||
|
||||
@@ -6,5 +6,6 @@ terraform {
|
||||
local = ">= 1.2"
|
||||
null = ">= 2.1"
|
||||
template = ">= 2.1"
|
||||
random = ">= 2.1"
|
||||
}
|
||||
}
|
||||
|
||||
33
workers.tf
33
workers.tf
@@ -1,8 +1,17 @@
|
||||
# Worker Groups using Launch Configurations
|
||||
|
||||
resource "aws_autoscaling_group" "workers" {
|
||||
count = local.worker_group_count
|
||||
name_prefix = "${aws_eks_cluster.this.name}-${lookup(var.worker_groups[count.index], "name", count.index)}"
|
||||
count = local.worker_group_count
|
||||
name_prefix = join(
|
||||
"-",
|
||||
compact(
|
||||
[
|
||||
aws_eks_cluster.this.name,
|
||||
lookup(var.worker_groups[count.index], "name", count.index),
|
||||
lookup(var.worker_groups[count.index], "asg_recreate_on_change", local.workers_group_defaults["asg_recreate_on_change"]) ? random_pet.workers[count.index].id : ""
|
||||
]
|
||||
)
|
||||
)
|
||||
desired_capacity = lookup(
|
||||
var.worker_groups[count.index],
|
||||
"asg_desired_capacity",
|
||||
@@ -210,6 +219,25 @@ resource "aws_launch_configuration" "workers" {
|
||||
}
|
||||
}
|
||||
|
||||
resource "random_pet" "workers" {
|
||||
count = local.worker_group_count
|
||||
|
||||
separator = "-"
|
||||
length = 2
|
||||
|
||||
keepers = {
|
||||
lt_name = join(
|
||||
"-",
|
||||
compact(
|
||||
[
|
||||
aws_launch_configuration.workers[count.index].name,
|
||||
aws_launch_configuration.workers[count.index].latest_version
|
||||
]
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_security_group" "workers" {
|
||||
count = var.worker_create_security_group ? 1 : 0
|
||||
name_prefix = aws_eks_cluster.this.name
|
||||
@@ -390,4 +418,3 @@ data "aws_iam_policy_document" "worker_autoscaling" {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,16 @@
|
||||
|
||||
resource "aws_autoscaling_group" "workers_launch_template" {
|
||||
count = local.worker_group_launch_template_count
|
||||
name_prefix = "${aws_eks_cluster.this.name}-${lookup(
|
||||
var.worker_groups_launch_template[count.index],
|
||||
"name",
|
||||
count.index,
|
||||
)}"
|
||||
name_prefix = join(
|
||||
"-",
|
||||
compact(
|
||||
[
|
||||
aws_eks_cluster.this.name,
|
||||
lookup(var.worker_groups_launch_template[count.index], "name", count.index),
|
||||
lookup(var.worker_groups_launch_template[count.index], "asg_recreate_on_change", local.workers_group_defaults["asg_recreate_on_change"]) ? random_pet.workers_launch_template[count.index].id : ""
|
||||
]
|
||||
)
|
||||
)
|
||||
desired_capacity = lookup(
|
||||
var.worker_groups_launch_template[count.index],
|
||||
"asg_desired_capacity",
|
||||
@@ -296,6 +301,25 @@ resource "aws_launch_template" "workers_launch_template" {
|
||||
}
|
||||
}
|
||||
|
||||
resource "random_pet" "workers_launch_template" {
|
||||
count = local.worker_group_launch_template_count
|
||||
|
||||
separator = "-"
|
||||
length = 2
|
||||
|
||||
keepers = {
|
||||
lt_name = join(
|
||||
"-",
|
||||
compact(
|
||||
[
|
||||
aws_launch_template.workers_launch_template[count.index].name,
|
||||
aws_launch_template.workers_launch_template[count.index].latest_version
|
||||
]
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_iam_instance_profile" "workers_launch_template" {
|
||||
count = var.manage_worker_iam_resources ? local.worker_group_launch_template_count : 0
|
||||
name_prefix = aws_eks_cluster.this.name
|
||||
|
||||
@@ -2,11 +2,17 @@
|
||||
|
||||
resource "aws_autoscaling_group" "workers_launch_template_mixed" {
|
||||
count = local.worker_group_launch_template_mixed_count
|
||||
name_prefix = "${aws_eks_cluster.this.name}-${lookup(
|
||||
var.worker_groups_launch_template_mixed[count.index],
|
||||
"name",
|
||||
count.index,
|
||||
)}"
|
||||
name_prefix = join(
|
||||
"-",
|
||||
compact(
|
||||
[
|
||||
aws_eks_cluster.this.name,
|
||||
lookup(var.worker_groups_launch_template_mixed[count.index], "name", count.index),
|
||||
lookup(var.worker_groups_launch_template_mixed[count.index], "asg_recreate_on_change", local.workers_group_defaults["asg_recreate_on_change"]) ? random_pet.workers_launch_template_mixed[count.index].id : ""
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
desired_capacity = lookup(
|
||||
var.worker_groups_launch_template_mixed[count.index],
|
||||
"asg_desired_capacity",
|
||||
@@ -338,6 +344,25 @@ resource "aws_launch_template" "workers_launch_template_mixed" {
|
||||
}
|
||||
}
|
||||
|
||||
resource "random_pet" "workers_launch_template_mixed" {
|
||||
count = local.worker_group_launch_template_mixed_count
|
||||
|
||||
separator = "-"
|
||||
length = 2
|
||||
|
||||
keepers = {
|
||||
lt_name = join(
|
||||
"-",
|
||||
compact(
|
||||
[
|
||||
aws_launch_template.workers_launch_template_mixed[count.index].name,
|
||||
aws_launch_template.workers_launch_template_mixed[count.index].latest_version
|
||||
]
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_iam_instance_profile" "workers_launch_template_mixed" {
|
||||
count = var.manage_worker_iam_resources ? local.worker_group_launch_template_mixed_count : 0
|
||||
name_prefix = aws_eks_cluster.this.name
|
||||
|
||||
Reference in New Issue
Block a user