2018-08-20 03:48:22 +02:00
|
|
|
# Discrete DNS records for each controller's private IPv4 for etcd usage
|
|
|
|
resource "azurerm_dns_a_record" "etcds" {
|
2019-05-28 06:43:08 +02:00
|
|
|
count = var.controller_count
|
|
|
|
resource_group_name = var.dns_zone_group
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
# DNS Zone name where record should be created
|
2019-05-28 06:43:08 +02:00
|
|
|
zone_name = var.dns_zone
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
# DNS record
|
2019-05-28 06:43:08 +02:00
|
|
|
name = format("%s-etcd%d", var.cluster_name, count.index)
|
2018-08-20 03:48:22 +02:00
|
|
|
ttl = 300
|
|
|
|
|
|
|
|
# private IPv4 address for etcd
|
2019-05-28 06:43:08 +02:00
|
|
|
records = [element(
|
|
|
|
azurerm_network_interface.controllers.*.private_ip_address,
|
|
|
|
count.index,
|
|
|
|
)]
|
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
|
|
|
}
|
|
|
|
|
|
|
|
# Controller availability set to spread controllers
|
|
|
|
resource "azurerm_availability_set" "controllers" {
|
2019-05-28 06:43:08 +02:00
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
name = "${var.cluster_name}-controllers"
|
2019-05-28 06:43:08 +02:00
|
|
|
location = var.region
|
2018-08-20 03:48:22 +02:00
|
|
|
platform_fault_domain_count = 2
|
|
|
|
platform_update_domain_count = 4
|
|
|
|
managed = true
|
|
|
|
}
|
|
|
|
|
|
|
|
# Controller instances
|
|
|
|
resource "azurerm_virtual_machine" "controllers" {
|
2019-05-28 06:43:08 +02:00
|
|
|
count = var.controller_count
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
name = "${var.cluster_name}-controller-${count.index}"
|
2019-05-28 06:43:08 +02:00
|
|
|
location = var.region
|
|
|
|
availability_set_id = azurerm_availability_set.controllers.id
|
|
|
|
vm_size = var.controller_type
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
# boot
|
|
|
|
storage_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_os_disk {
|
|
|
|
name = "${var.cluster_name}-controller-${count.index}"
|
|
|
|
create_option = "FromImage"
|
|
|
|
caching = "ReadWrite"
|
2019-05-28 06:43:08 +02:00
|
|
|
disk_size_gb = var.disk_size
|
2018-08-20 03:48:22 +02:00
|
|
|
os_type = "Linux"
|
|
|
|
managed_disk_type = "Premium_LRS"
|
|
|
|
}
|
|
|
|
|
|
|
|
# network
|
2019-05-28 06:43:08 +02:00
|
|
|
network_interface_ids = [element(azurerm_network_interface.controllers.*.id, count.index)]
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
os_profile {
|
|
|
|
computer_name = "${var.cluster_name}-controller-${count.index}"
|
|
|
|
admin_username = "core"
|
2019-05-28 06:43:08 +02:00
|
|
|
custom_data = element(data.ct_config.controller-ignitions.*.rendered, count.index)
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# lifecycle
|
|
|
|
delete_os_disk_on_termination = true
|
|
|
|
delete_data_disks_on_termination = true
|
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
ignore_changes = [
|
2019-05-28 06:43:08 +02:00
|
|
|
storage_os_disk,
|
|
|
|
os_profile,
|
2018-08-20 03:48:22 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Controller NICs with public and private IPv4
|
|
|
|
resource "azurerm_network_interface" "controllers" {
|
2019-05-28 06:43:08 +02:00
|
|
|
count = var.controller_count
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
name = "${var.cluster_name}-controller-${count.index}"
|
2019-05-28 06:43:08 +02:00
|
|
|
location = azurerm_resource_group.cluster.location
|
|
|
|
network_security_group_id = azurerm_network_security_group.controller.id
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
ip_configuration {
|
|
|
|
name = "ip0"
|
2019-05-28 06:43:08 +02:00
|
|
|
subnet_id = azurerm_subnet.controller.id
|
2018-08-20 03:48:22 +02:00
|
|
|
private_ip_address_allocation = "dynamic"
|
|
|
|
|
|
|
|
# public IPv4
|
2019-05-28 06:43:08 +02:00
|
|
|
public_ip_address_id = element(azurerm_public_ip.controllers.*.id, count.index)
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-28 06:46:10 +01:00
|
|
|
# Add controller NICs to the controller backend address pool
|
|
|
|
resource "azurerm_network_interface_backend_address_pool_association" "controllers" {
|
2019-07-21 19:32:58 +02:00
|
|
|
count = var.controller_count
|
|
|
|
|
|
|
|
network_interface_id = azurerm_network_interface.controllers[count.index].id
|
2018-10-28 06:46:10 +01:00
|
|
|
ip_configuration_name = "ip0"
|
2019-05-28 06:43:08 +02:00
|
|
|
backend_address_pool_id = azurerm_lb_backend_address_pool.controller.id
|
2018-10-28 06:46:10 +01:00
|
|
|
}
|
|
|
|
|
2018-08-20 03:48:22 +02:00
|
|
|
# Controller public IPv4 addresses
|
|
|
|
resource "azurerm_public_ip" "controllers" {
|
2019-05-28 06:43:08 +02:00
|
|
|
count = var.controller_count
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2019-01-28 02:52:35 +01:00
|
|
|
name = "${var.cluster_name}-controller-${count.index}"
|
2019-05-28 06:43:08 +02:00
|
|
|
location = azurerm_resource_group.cluster.location
|
2019-01-28 02:52:35 +01:00
|
|
|
sku = "Standard"
|
|
|
|
allocation_method = "Static"
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Controller Ignition configs
|
|
|
|
data "ct_config" "controller-ignitions" {
|
2019-05-28 06:43:08 +02:00
|
|
|
count = var.controller_count
|
|
|
|
content = element(
|
|
|
|
data.template_file.controller-configs.*.rendered,
|
|
|
|
count.index,
|
|
|
|
)
|
2018-08-20 03:48:22 +02:00
|
|
|
pretty_print = false
|
2019-05-28 06:43:08 +02:00
|
|
|
snippets = var.controller_clc_snippets
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Controller Container Linux configs
|
|
|
|
data "template_file" "controller-configs" {
|
2019-05-28 06:43:08 +02:00
|
|
|
count = var.controller_count
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2019-05-28 06:43:08 +02:00
|
|
|
template = file("${path.module}/cl/controller.yaml.tmpl")
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
vars = {
|
|
|
|
# Cannot use cyclic dependencies on controllers or their DNS records
|
|
|
|
etcd_name = "etcd${count.index}"
|
|
|
|
etcd_domain = "${var.cluster_name}-etcd${count.index}.${var.dns_zone}"
|
|
|
|
# etcd0=https://cluster-etcd0.example.com,etcd1=https://cluster-etcd1.example.com,...
|
2019-05-28 06:43:08 +02:00
|
|
|
etcd_initial_cluster = join(",", data.template_file.etcds.*.rendered)
|
|
|
|
kubeconfig = indent(10, module.bootkube.kubeconfig-kubelet)
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data "template_file" "etcds" {
|
2019-05-28 06:43:08 +02:00
|
|
|
count = var.controller_count
|
2018-08-20 03:48:22 +02:00
|
|
|
template = "etcd$${index}=https://$${cluster_name}-etcd$${index}.$${dns_zone}:2380"
|
|
|
|
|
2019-03-12 09:19:54 +01:00
|
|
|
vars = {
|
2019-05-28 06:43:08 +02:00
|
|
|
index = count.index
|
|
|
|
cluster_name = var.cluster_name
|
|
|
|
dns_zone = var.dns_zone
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-28 06:43:08 +02:00
|
|
|
|