2018-08-20 03:48:22 +02:00
|
|
|
locals {
|
2020-03-11 07:55:23 +01:00
|
|
|
# flatcar-stable -> Flatcar Linux Stable
|
2022-10-14 05:49:01 +02:00
|
|
|
channel = split("-", var.os_image)[1]
|
|
|
|
offer_suffix = var.arch == "arm64" ? "corevm" : "free"
|
|
|
|
urn = var.arch == "arm64" ? local.channel : "${local.channel}-gen2"
|
2023-09-17 23:21:42 +02:00
|
|
|
|
|
|
|
azure_authorized_key = var.azure_authorized_key == "" ? var.ssh_authorized_key : var.azure_authorized_key
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Workers scale set
|
2020-03-08 03:40:39 +01:00
|
|
|
resource "azurerm_linux_virtual_machine_scale_set" "workers" {
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "${var.name}-worker"
|
2019-05-28 06:43:08 +02:00
|
|
|
resource_group_name = var.resource_group_name
|
2024-07-09 06:20:46 +02:00
|
|
|
location = var.location
|
2024-07-06 02:21:50 +02:00
|
|
|
sku = var.vm_type
|
|
|
|
instances = var.worker_count
|
2020-03-08 03:40:39 +01:00
|
|
|
# instance name prefix for instances in the set
|
2020-04-01 06:42:51 +02:00
|
|
|
computer_name_prefix = "${var.name}-worker"
|
2018-08-28 06:30:26 +02:00
|
|
|
single_placement_group = false
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2020-03-08 03:40:39 +01:00
|
|
|
# storage
|
|
|
|
os_disk {
|
|
|
|
storage_account_type = "Standard_LRS"
|
2020-04-01 06:42:51 +02:00
|
|
|
caching = "ReadWrite"
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
2020-09-25 04:55:32 +02:00
|
|
|
# Flatcar Container Linux
|
2020-05-10 02:37:35 +02:00
|
|
|
source_image_reference {
|
2022-10-13 18:47:45 +02:00
|
|
|
publisher = "kinvolk"
|
2022-10-14 05:49:01 +02:00
|
|
|
offer = "flatcar-container-linux-${local.offer_suffix}"
|
|
|
|
sku = local.urn
|
2020-05-10 02:37:35 +02:00
|
|
|
version = "latest"
|
|
|
|
}
|
|
|
|
|
2022-10-14 05:49:01 +02:00
|
|
|
dynamic "plan" {
|
|
|
|
for_each = var.arch == "arm64" ? [] : [1]
|
|
|
|
content {
|
|
|
|
publisher = "kinvolk"
|
|
|
|
product = "flatcar-container-linux-${local.offer_suffix}"
|
|
|
|
name = local.urn
|
|
|
|
}
|
2020-03-11 07:55:23 +01:00
|
|
|
}
|
|
|
|
|
2018-08-20 03:48:22 +02:00
|
|
|
# network
|
2020-03-08 03:40:39 +01:00
|
|
|
network_interface {
|
2018-08-20 03:48:22 +02:00
|
|
|
name = "nic0"
|
|
|
|
primary = true
|
2019-05-28 06:43:08 +02:00
|
|
|
network_security_group_id = var.security_group_id
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
ip_configuration {
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "ipv4"
|
|
|
|
version = "IPv4"
|
2018-10-28 01:42:36 +02:00
|
|
|
primary = true
|
2019-05-28 06:43:08 +02:00
|
|
|
subnet_id = var.subnet_id
|
2018-08-20 03:48:22 +02:00
|
|
|
# backend address pool to which the NIC should be added
|
2024-07-06 02:21:50 +02:00
|
|
|
load_balancer_backend_address_pool_ids = var.backend_address_pool_ids.ipv4
|
|
|
|
}
|
|
|
|
ip_configuration {
|
|
|
|
name = "ipv6"
|
|
|
|
version = "IPv6"
|
|
|
|
subnet_id = var.subnet_id
|
|
|
|
# backend address pool to which the NIC should be added
|
|
|
|
load_balancer_backend_address_pool_ids = var.backend_address_pool_ids.ipv6
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
# boot
|
|
|
|
custom_data = base64encode(data.ct_config.worker.rendered)
|
|
|
|
boot_diagnostics {
|
|
|
|
# defaults to a managed storage account
|
|
|
|
}
|
|
|
|
|
|
|
|
# Azure requires an RSA admin_ssh_key
|
|
|
|
admin_username = "core"
|
|
|
|
admin_ssh_key {
|
|
|
|
username = "core"
|
|
|
|
public_key = local.azure_authorized_key
|
|
|
|
}
|
|
|
|
|
2018-08-20 03:48:22 +02:00
|
|
|
# lifecycle
|
2020-03-08 03:40:39 +01:00
|
|
|
upgrade_mode = "Manual"
|
|
|
|
# eviction policy may only be set when priority is Spot
|
2019-11-14 08:44:02 +01:00
|
|
|
priority = var.priority
|
2020-03-08 03:40:39 +01:00
|
|
|
eviction_policy = var.priority == "Spot" ? "Delete" : null
|
2023-06-12 04:20:45 +02:00
|
|
|
termination_notification {
|
|
|
|
enabled = true
|
|
|
|
}
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Scale up or down to maintain desired number, tolerating deallocations.
|
2019-05-27 08:14:50 +02:00
|
|
|
resource "azurerm_monitor_autoscale_setting" "workers" {
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "${var.name}-maintain-desired"
|
2019-05-28 06:43:08 +02:00
|
|
|
resource_group_name = var.resource_group_name
|
2024-07-09 06:20:46 +02:00
|
|
|
location = var.location
|
2018-08-20 03:48:22 +02:00
|
|
|
# autoscale
|
|
|
|
enabled = true
|
2020-03-08 03:40:39 +01:00
|
|
|
target_resource_id = azurerm_linux_virtual_machine_scale_set.workers.id
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
profile {
|
|
|
|
name = "default"
|
|
|
|
capacity {
|
2019-05-28 06:43:08 +02:00
|
|
|
minimum = var.worker_count
|
|
|
|
default = var.worker_count
|
|
|
|
maximum = var.worker_count
|
2018-08-20 03:48:22 +02: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 06:43:08 +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-08-20 03:48:22 +02:00
|
|
|
}
|