2018-02-27 07:16:34 +01:00
|
|
|
# Workers AutoScaling Group
|
|
|
|
resource "aws_autoscaling_group" "workers" {
|
2018-03-04 02:52:01 +01:00
|
|
|
name = "${var.name}-worker ${aws_launch_configuration.worker.name}"
|
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
|
|
|
|
|
|
|
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"
|
|
|
|
|
2019-05-28 05:42:48 +02:00
|
|
|
tags = [
|
|
|
|
{
|
|
|
|
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" {
|
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
|
|
|
|
2019-05-28 05:42:48 +02:00
|
|
|
user_data = data.ct_config.worker-ignition.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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-28 01:24:59 +02:00
|
|
|
# Worker Ignition config
|
|
|
|
data "ct_config" "worker-ignition" {
|
2019-05-28 05:42:48 +02:00
|
|
|
content = data.template_file.worker-config.rendered
|
2018-10-28 01:24:59 +02:00
|
|
|
pretty_print = false
|
2020-03-29 20:46:22 +02:00
|
|
|
snippets = var.snippets
|
2018-10-28 01:24:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Worker Container Linux config
|
|
|
|
data "template_file" "worker-config" {
|
2019-12-28 21:07:10 +01:00
|
|
|
template = file("${path.module}/cl/worker.yaml")
|
2018-02-27 07:16:34 +01:00
|
|
|
|
|
|
|
vars = {
|
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-06-12 08:24:01 +02:00
|
|
|
cgroup_driver = local.flavor == "flatcar" && local.channel == "edge" ? "systemd" : "cgroupfs"
|
2019-09-28 23:59:24 +02:00
|
|
|
node_labels = join(",", var.node_labels)
|
2018-02-27 07:16:34 +01:00
|
|
|
}
|
|
|
|
}
|
2019-05-28 05:42:48 +02:00
|
|
|
|