2018-08-20 03:48:22 +02:00
|
|
|
locals {
|
|
|
|
# coreos-stable -> Container Linux Stable
|
2020-03-11 07:55:23 +01:00
|
|
|
# flatcar-stable -> Flatcar Linux Stable
|
|
|
|
flavor = split("-", var.os_image)[0]
|
2019-12-28 21:07:10 +01:00
|
|
|
channel = split("-", var.os_image)[1]
|
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" {
|
2019-05-28 06:43:08 +02:00
|
|
|
resource_group_name = var.resource_group_name
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2020-04-01 06:42:51 +02:00
|
|
|
name = "${var.name}-worker"
|
|
|
|
location = var.region
|
|
|
|
sku = var.vm_type
|
2020-03-08 03:40:39 +01:00
|
|
|
instances = var.worker_count
|
|
|
|
# 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
|
2020-04-01 06:42:51 +02:00
|
|
|
custom_data = base64encode(data.ct_config.worker-ignition.rendered)
|
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-05-10 02:37:35 +02:00
|
|
|
# CoreOS Container Linux or Flatcar Container Linux
|
|
|
|
source_image_reference {
|
|
|
|
publisher = local.flavor == "flatcar" ? "Kinvolk" : "CoreOS"
|
|
|
|
offer = local.flavor == "flatcar" ? "flatcar-container-linux-free" : "CoreOS"
|
|
|
|
sku = local.channel
|
|
|
|
version = "latest"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Gross hack for Flatcar Linux
|
|
|
|
dynamic "plan" {
|
|
|
|
for_each = local.flavor == "flatcar" ? [1] : []
|
2020-03-11 07:55:23 +01:00
|
|
|
|
|
|
|
content {
|
2020-05-10 02:37:35 +02:00
|
|
|
name = local.channel
|
|
|
|
publisher = "kinvolk"
|
|
|
|
product = "flatcar-container-linux-free"
|
2020-03-11 07:55:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-08 03:40:39 +01:00
|
|
|
# Azure requires setting admin_ssh_key, though Ignition custom_data handles it too
|
|
|
|
admin_username = "core"
|
|
|
|
admin_ssh_key {
|
2020-04-01 06:42:51 +02:00
|
|
|
username = "core"
|
2020-03-08 03:40:39 +01:00
|
|
|
public_key = var.ssh_authorized_key
|
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 {
|
|
|
|
name = "ip0"
|
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
|
2019-05-28 06:43:08 +02:00
|
|
|
load_balancer_backend_address_pool_ids = [var.backend_address_pool_id]
|
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
|
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" {
|
2019-05-28 06:43:08 +02:00
|
|
|
resource_group_name = var.resource_group_name
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2018-08-28 06:30:26 +02:00
|
|
|
name = "${var.name}-maintain-desired"
|
2019-05-28 06:43:08 +02:00
|
|
|
location = var.region
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Worker Ignition configs
|
2018-10-28 01:24:59 +02:00
|
|
|
data "ct_config" "worker-ignition" {
|
2019-05-28 06:43:08 +02:00
|
|
|
content = data.template_file.worker-config.rendered
|
2018-08-20 03:48:22 +02:00
|
|
|
pretty_print = false
|
2020-03-29 20:46:22 +02:00
|
|
|
snippets = var.snippets
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Worker Container Linux configs
|
2018-10-28 01:24:59 +02:00
|
|
|
data "template_file" "worker-config" {
|
2019-12-28 21:07:10 +01:00
|
|
|
template = file("${path.module}/cl/worker.yaml")
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
vars = {
|
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)
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-28 06:43:08 +02:00
|
|
|
|