2018-08-20 03:48:22 +02:00
|
|
|
locals {
|
|
|
|
# Channel for a Container Linux derivative
|
|
|
|
# coreos-stable -> Container Linux Stable
|
2019-05-28 06:43:08 +02:00
|
|
|
channel = element(split("-", var.os_image), 1)
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Workers scale set
|
|
|
|
resource "azurerm_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
|
|
|
|
2018-08-28 06:30:26 +02:00
|
|
|
name = "${var.name}-workers"
|
2019-05-28 06:43:08 +02:00
|
|
|
location = var.region
|
2018-08-28 06:30:26 +02:00
|
|
|
single_placement_group = false
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
sku {
|
2019-05-28 06:43:08 +02:00
|
|
|
name = var.vm_type
|
2018-08-20 03:48:22 +02:00
|
|
|
tier = "standard"
|
2019-05-28 06:43:08 +02:00
|
|
|
capacity = var.worker_count
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# boot
|
|
|
|
storage_profile_image_reference {
|
|
|
|
publisher = "CoreOS"
|
|
|
|
offer = "CoreOS"
|
2019-05-28 06:43:08 +02:00
|
|
|
sku = local.channel
|
2018-08-20 03:48:22 +02:00
|
|
|
version = "latest"
|
|
|
|
}
|
|
|
|
|
|
|
|
# storage
|
|
|
|
storage_profile_os_disk {
|
|
|
|
create_option = "FromImage"
|
|
|
|
caching = "ReadWrite"
|
|
|
|
os_type = "linux"
|
|
|
|
managed_disk_type = "Standard_LRS"
|
|
|
|
}
|
|
|
|
|
|
|
|
os_profile {
|
|
|
|
computer_name_prefix = "${var.name}-worker-"
|
|
|
|
admin_username = "core"
|
2019-05-28 06:43:08 +02:00
|
|
|
custom_data = data.ct_config.worker-ignition.rendered
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Azure mandates setting an ssh_key, even though Ignition custom_data handles it too
|
|
|
|
os_profile_linux_config {
|
|
|
|
disable_password_authentication = true
|
|
|
|
|
|
|
|
ssh_keys {
|
|
|
|
path = "/home/core/.ssh/authorized_keys"
|
2019-05-28 06:43:08 +02:00
|
|
|
key_data = var.ssh_authorized_key
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# network
|
|
|
|
network_profile {
|
|
|
|
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
|
|
|
|
upgrade_policy_mode = "Manual"
|
2019-05-28 07:55:16 +02:00
|
|
|
# eviction policy may only be set when priority is Low
|
2019-05-28 06:43:08 +02:00
|
|
|
priority = var.priority
|
2019-05-28 07:55:16 +02:00
|
|
|
eviction_policy = var.priority == "Low" ? "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
|
2019-05-28 06:43:08 +02:00
|
|
|
target_resource_id = azurerm_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
|
2019-05-28 06:43:08 +02:00
|
|
|
snippets = var.clc_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-05-28 06:43:08 +02:00
|
|
|
template = file("${path.module}/cl/worker.yaml.tmpl")
|
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
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-28 06:43:08 +02:00
|
|
|
|