2018-02-27 07:16:34 +01:00
|
|
|
# Workers AutoScaling Group
|
|
|
|
resource "aws_autoscaling_group" "workers" {
|
2022-08-09 05:46:08 +02:00
|
|
|
name = "${var.name}-worker"
|
2018-02-27 07:16:34 +01:00
|
|
|
|
|
|
|
# count
|
2019-05-28 05:42:48 +02:00
|
|
|
desired_capacity = var.worker_count
|
|
|
|
min_size = var.worker_count
|
|
|
|
max_size = var.worker_count + 2
|
2018-02-27 07:16:34 +01:00
|
|
|
default_cooldown = 30
|
|
|
|
health_check_grace_period = 30
|
|
|
|
|
|
|
|
# network
|
2019-05-28 05:42:48 +02:00
|
|
|
vpc_zone_identifier = var.subnet_ids
|
2018-02-27 07:16:34 +01:00
|
|
|
|
|
|
|
# template
|
2019-05-28 05:42:48 +02:00
|
|
|
launch_configuration = aws_launch_configuration.worker.name
|
2018-02-27 07:16:34 +01:00
|
|
|
|
|
|
|
# target groups to which instances should be added
|
2019-05-28 05:42:48 +02:00
|
|
|
target_group_arns = flatten([
|
|
|
|
aws_lb_target_group.workers-http.id,
|
|
|
|
aws_lb_target_group.workers-https.id,
|
|
|
|
var.target_groups,
|
|
|
|
])
|
2018-02-27 07:16:34 +01:00
|
|
|
|
2022-08-15 06:37:26 +02:00
|
|
|
instance_refresh {
|
|
|
|
strategy = "Rolling"
|
|
|
|
preferences {
|
|
|
|
instance_warmup = 120
|
|
|
|
min_healthy_percentage = 90
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 07:16:34 +01:00
|
|
|
lifecycle {
|
|
|
|
# override the default destroy and replace update behavior
|
|
|
|
create_before_destroy = true
|
|
|
|
}
|
|
|
|
|
2018-04-29 22:19:00 +02:00
|
|
|
# Waiting for instance creation delays adding the ASG to state. If instances
|
|
|
|
# can't be created (e.g. spot price too low), the ASG will be orphaned.
|
|
|
|
# Orphaned ASGs escape cleanup, can't be updated, and keep bidding if spot is
|
|
|
|
# used. Disable wait to avoid issues and align with other clouds.
|
|
|
|
wait_for_capacity_timeout = "0"
|
|
|
|
|
2022-02-17 18:02:42 +01:00
|
|
|
tag {
|
|
|
|
key = "Name"
|
|
|
|
value = "${var.name}-worker"
|
|
|
|
propagate_at_launch = true
|
|
|
|
}
|
2018-02-27 07:16:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Worker template
|
|
|
|
resource "aws_launch_configuration" "worker" {
|
2022-08-09 05:46:08 +02:00
|
|
|
name_prefix = "${var.name}-worker"
|
2019-05-28 05:42:48 +02:00
|
|
|
image_id = local.ami_id
|
|
|
|
instance_type = var.instance_type
|
2019-09-29 20:14:36 +02:00
|
|
|
spot_price = var.spot_price > 0 ? var.spot_price : null
|
2018-06-22 08:57:38 +02:00
|
|
|
enable_monitoring = false
|
2018-02-27 07:16:34 +01:00
|
|
|
|
2022-08-03 03:15:03 +02:00
|
|
|
user_data = data.ct_config.worker.rendered
|
2018-02-27 07:16:34 +01:00
|
|
|
|
|
|
|
# storage
|
|
|
|
root_block_device {
|
2019-05-28 05:42:48 +02:00
|
|
|
volume_type = var.disk_type
|
|
|
|
volume_size = var.disk_size
|
|
|
|
iops = var.disk_iops
|
2019-08-08 05:56:55 +02:00
|
|
|
encrypted = true
|
2018-02-27 07:16:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# network
|
2019-05-28 05:42:48 +02:00
|
|
|
security_groups = var.security_groups
|
2018-02-27 07:16:34 +01:00
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
// Override the default destroy and replace update behavior
|
|
|
|
create_before_destroy = true
|
2019-05-28 05:42:48 +02:00
|
|
|
ignore_changes = [image_id]
|
2018-02-27 07:16:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-03 03:15:03 +02:00
|
|
|
# Flatcar Linux worker
|
|
|
|
data "ct_config" "worker" {
|
2022-08-03 03:12:37 +02:00
|
|
|
content = templatefile("${path.module}/butane/worker.yaml", {
|
2019-05-28 05:42:48 +02:00
|
|
|
kubeconfig = indent(10, var.kubeconfig)
|
|
|
|
ssh_authorized_key = var.ssh_authorized_key
|
|
|
|
cluster_dns_service_ip = cidrhost(var.service_cidr, 10)
|
|
|
|
cluster_domain_suffix = var.cluster_domain_suffix
|
2019-09-28 23:59:24 +02:00
|
|
|
node_labels = join(",", var.node_labels)
|
2021-04-11 21:08:56 +02:00
|
|
|
node_taints = join(",", var.node_taints)
|
2022-08-03 03:15:03 +02:00
|
|
|
})
|
|
|
|
strict = true
|
|
|
|
snippets = var.snippets
|
2018-02-27 07:16:34 +01:00
|
|
|
}
|