2019-09-25 12:17:59 +00:00
|
|
|
data "openstack_images_image_v2" "vm_image" {
|
2020-06-05 07:05:43 +00:00
|
|
|
name = var.image
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data "openstack_images_image_v2" "gfs_image" {
|
2020-06-05 07:05:43 +00:00
|
|
|
name = var.image_gfs == "" ? var.image : var.image_gfs
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 12:48:47 +00:00
|
|
|
resource "openstack_compute_keypair_v2" "k8s" {
|
2018-01-05 11:09:04 +00:00
|
|
|
name = "kubernetes-${var.cluster_name}"
|
2020-06-05 07:05:43 +00:00
|
|
|
public_key = chomp(file(var.public_key_path))
|
2017-12-05 12:48:47 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 09:35:02 +00:00
|
|
|
resource "openstack_networking_secgroup_v2" "k8s_master" {
|
2019-04-17 09:10:03 +00:00
|
|
|
name = "${var.cluster_name}-k8s-master"
|
|
|
|
description = "${var.cluster_name} - Kubernetes Master"
|
|
|
|
delete_default_rules = true
|
2018-09-28 09:35:02 +00:00
|
|
|
}
|
2018-01-05 11:09:04 +00:00
|
|
|
|
2020-11-05 13:30:54 +00:00
|
|
|
resource "openstack_networking_secgroup_v2" "k8s_master_extra" {
|
|
|
|
count = "%{if var.extra_sec_groups}1%{else}0%{endif}"
|
|
|
|
name = "${var.cluster_name}-k8s-master-${var.extra_sec_groups_name}"
|
|
|
|
description = "${var.cluster_name} - Kubernetes Master nodes - rules not managed by terraform"
|
|
|
|
delete_default_rules = true
|
|
|
|
}
|
|
|
|
|
2018-09-28 09:35:02 +00:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "k8s_master" {
|
2020-06-05 07:05:43 +00:00
|
|
|
count = length(var.master_allowed_remote_ips)
|
2019-02-18 05:04:41 +00:00
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = "tcp"
|
|
|
|
port_range_min = "6443"
|
|
|
|
port_range_max = "6443"
|
2020-06-05 07:05:43 +00:00
|
|
|
remote_ip_prefix = var.master_allowed_remote_ips[count.index]
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.k8s_master.id
|
2017-12-05 12:48:47 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 09:07:13 +00:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "k8s_master_ports" {
|
|
|
|
count = length(var.master_allowed_ports)
|
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = lookup(var.master_allowed_ports[count.index], "protocol", "tcp")
|
|
|
|
port_range_min = lookup(var.master_allowed_ports[count.index], "port_range_min")
|
|
|
|
port_range_max = lookup(var.master_allowed_ports[count.index], "port_range_max")
|
|
|
|
remote_ip_prefix = lookup(var.master_allowed_ports[count.index], "remote_ip_prefix", "0.0.0.0/0")
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.k8s_master.id
|
|
|
|
}
|
|
|
|
|
2018-09-28 09:35:02 +00:00
|
|
|
resource "openstack_networking_secgroup_v2" "bastion" {
|
2019-04-17 09:10:03 +00:00
|
|
|
name = "${var.cluster_name}-bastion"
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.number_of_bastions != "" ? 1 : 0
|
2019-04-17 09:10:03 +00:00
|
|
|
description = "${var.cluster_name} - Bastion Server"
|
|
|
|
delete_default_rules = true
|
2018-09-28 09:35:02 +00:00
|
|
|
}
|
2018-01-05 11:09:04 +00:00
|
|
|
|
2018-09-28 09:35:02 +00:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "bastion" {
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.number_of_bastions != "" ? length(var.bastion_allowed_remote_ips) : 0
|
2019-02-18 05:04:41 +00:00
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = "tcp"
|
|
|
|
port_range_min = "22"
|
|
|
|
port_range_max = "22"
|
2020-06-05 07:05:43 +00:00
|
|
|
remote_ip_prefix = var.bastion_allowed_remote_ips[count.index]
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.bastion[0].id
|
2017-12-05 12:48:47 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 09:35:02 +00:00
|
|
|
resource "openstack_networking_secgroup_v2" "k8s" {
|
2019-04-17 09:10:03 +00:00
|
|
|
name = "${var.cluster_name}-k8s"
|
|
|
|
description = "${var.cluster_name} - Kubernetes"
|
|
|
|
delete_default_rules = true
|
2018-09-28 09:35:02 +00:00
|
|
|
}
|
2018-01-05 11:09:04 +00:00
|
|
|
|
2018-09-28 09:35:02 +00:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "k8s" {
|
2019-02-18 05:04:41 +00:00
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
2020-06-05 07:05:43 +00:00
|
|
|
remote_group_id = openstack_networking_secgroup_v2.k8s.id
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.k8s.id
|
2017-12-05 12:48:47 +00:00
|
|
|
}
|
2018-09-28 09:35:02 +00:00
|
|
|
|
2019-04-15 14:22:08 +00:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "k8s_allowed_remote_ips" {
|
2020-06-05 07:05:43 +00:00
|
|
|
count = length(var.k8s_allowed_remote_ips)
|
2019-04-15 14:22:08 +00:00
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = "tcp"
|
|
|
|
port_range_min = "22"
|
|
|
|
port_range_max = "22"
|
2020-06-05 07:05:43 +00:00
|
|
|
remote_ip_prefix = var.k8s_allowed_remote_ips[count.index]
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.k8s.id
|
2019-04-15 14:22:08 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 09:10:03 +00:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "egress" {
|
2020-06-05 07:05:43 +00:00
|
|
|
count = length(var.k8s_allowed_egress_ips)
|
2019-04-17 09:10:03 +00:00
|
|
|
direction = "egress"
|
|
|
|
ethertype = "IPv4"
|
2020-06-05 07:05:43 +00:00
|
|
|
remote_ip_prefix = var.k8s_allowed_egress_ips[count.index]
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.k8s.id
|
2019-04-17 09:10:03 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 09:35:02 +00:00
|
|
|
resource "openstack_networking_secgroup_v2" "worker" {
|
2019-04-17 09:10:03 +00:00
|
|
|
name = "${var.cluster_name}-k8s-worker"
|
|
|
|
description = "${var.cluster_name} - Kubernetes worker nodes"
|
|
|
|
delete_default_rules = true
|
2018-09-28 09:35:02 +00:00
|
|
|
}
|
2018-07-27 12:57:29 +00:00
|
|
|
|
2020-11-05 13:30:54 +00:00
|
|
|
resource "openstack_networking_secgroup_v2" "worker_extra" {
|
|
|
|
count = "%{if var.extra_sec_groups}1%{else}0%{endif}"
|
|
|
|
name = "${var.cluster_name}-k8s-worker-${var.extra_sec_groups_name}"
|
|
|
|
description = "${var.cluster_name} - Kubernetes worker nodes - rules not managed by terraform"
|
|
|
|
delete_default_rules = true
|
|
|
|
}
|
|
|
|
|
2018-09-28 09:35:02 +00:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "worker" {
|
2020-06-05 07:05:43 +00:00
|
|
|
count = length(var.worker_allowed_ports)
|
2019-02-18 05:04:41 +00:00
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
2020-06-05 07:05:43 +00:00
|
|
|
protocol = lookup(var.worker_allowed_ports[count.index], "protocol", "tcp")
|
|
|
|
port_range_min = lookup(var.worker_allowed_ports[count.index], "port_range_min")
|
|
|
|
port_range_max = lookup(var.worker_allowed_ports[count.index], "port_range_max")
|
|
|
|
remote_ip_prefix = lookup(var.worker_allowed_ports[count.index], "remote_ip_prefix", "0.0.0.0/0")
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.worker.id
|
2018-07-27 12:57:29 +00:00
|
|
|
}
|
2017-12-05 12:48:47 +00:00
|
|
|
|
2019-12-09 09:15:10 +00:00
|
|
|
resource "openstack_compute_servergroup_v2" "k8s_master" {
|
2020-03-27 12:46:24 +00:00
|
|
|
count = "%{if var.use_server_groups}1%{else}0%{endif}"
|
|
|
|
name = "k8s-master-srvgrp"
|
2019-12-09 09:15:10 +00:00
|
|
|
policies = ["anti-affinity"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_servergroup_v2" "k8s_node" {
|
2020-03-27 12:46:24 +00:00
|
|
|
count = "%{if var.use_server_groups}1%{else}0%{endif}"
|
|
|
|
name = "k8s-node-srvgrp"
|
2019-12-09 09:15:10 +00:00
|
|
|
policies = ["anti-affinity"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_servergroup_v2" "k8s_etcd" {
|
2020-03-27 12:46:24 +00:00
|
|
|
count = "%{if var.use_server_groups}1%{else}0%{endif}"
|
|
|
|
name = "k8s-etcd-srvgrp"
|
2019-12-09 09:15:10 +00:00
|
|
|
policies = ["anti-affinity"]
|
|
|
|
}
|
|
|
|
|
2020-11-05 13:30:54 +00:00
|
|
|
locals {
|
|
|
|
# master groups
|
|
|
|
master_sec_groups = compact([
|
|
|
|
openstack_networking_secgroup_v2.k8s_master.name,
|
|
|
|
openstack_networking_secgroup_v2.k8s.name,
|
|
|
|
var.extra_sec_groups ?openstack_networking_secgroup_v2.k8s_master_extra[0].name : "",
|
|
|
|
])
|
|
|
|
# worker groups
|
|
|
|
worker_sec_groups = compact([
|
|
|
|
openstack_networking_secgroup_v2.k8s.name,
|
|
|
|
openstack_networking_secgroup_v2.worker.name,
|
2021-02-12 20:43:05 +00:00
|
|
|
var.extra_sec_groups ? openstack_networking_secgroup_v2.worker_extra[0].name : "",
|
2020-11-05 13:30:54 +00:00
|
|
|
])
|
|
|
|
}
|
|
|
|
|
2017-12-05 12:48:47 +00:00
|
|
|
resource "openstack_compute_instance_v2" "bastion" {
|
2020-03-27 12:46:24 +00:00
|
|
|
name = "${var.cluster_name}-bastion-${count.index + 1}"
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.number_of_bastions
|
|
|
|
image_name = var.image
|
|
|
|
flavor_id = var.flavor_bastion
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2018-01-05 11:09:04 +00:00
|
|
|
|
2020-02-24 09:20:49 +00:00
|
|
|
dynamic "block_device" {
|
|
|
|
for_each = var.bastion_root_volume_size_in_gb > 0 ? [var.image] : []
|
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
uuid = data.openstack_images_image_v2.vm_image.id
|
2020-02-24 09:20:49 +00:00
|
|
|
source_type = "image"
|
2020-06-05 07:05:43 +00:00
|
|
|
volume_size = var.bastion_root_volume_size_in_gb
|
2020-02-24 09:20:49 +00:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
|
|
|
}
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
network {
|
2020-06-05 07:05:43 +00:00
|
|
|
name = var.network_name
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-05 07:05:43 +00:00
|
|
|
security_groups = [openstack_networking_secgroup_v2.k8s.name,
|
|
|
|
element(openstack_networking_secgroup_v2.bastion.*.name, count.index),
|
2019-09-25 12:17:59 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 07:05:43 +00:00
|
|
|
ssh_user = var.ssh_user
|
2019-09-25 12:17:59 +00:00
|
|
|
kubespray_groups = "bastion"
|
2020-06-05 07:05:43 +00:00
|
|
|
depends_on = var.network_id
|
|
|
|
use_access_ip = var.use_access_ip
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "local-exec" {
|
|
|
|
command = "sed s/USER/${var.ssh_user}/ ../../contrib/terraform/openstack/ansible_bastion_template.txt | sed s/BASTION_ADDRESS/${var.bastion_fips[0]}/ > group_vars/no-floating.yml"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 12:48:47 +00:00
|
|
|
resource "openstack_compute_instance_v2" "k8s_master" {
|
2020-03-27 12:46:24 +00:00
|
|
|
name = "${var.cluster_name}-k8s-master-${count.index + 1}"
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.number_of_k8s_masters
|
|
|
|
availability_zone = element(var.az_list, count.index)
|
|
|
|
image_name = var.image
|
|
|
|
flavor_id = var.flavor_k8s_master
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2018-01-05 11:09:04 +00:00
|
|
|
|
|
|
|
|
2020-02-24 09:20:49 +00:00
|
|
|
dynamic "block_device" {
|
|
|
|
for_each = var.master_root_volume_size_in_gb > 0 ? [var.image] : []
|
2019-12-09 09:15:10 +00:00
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
uuid = data.openstack_images_image_v2.vm_image.id
|
2020-02-24 09:20:49 +00:00
|
|
|
source_type = "image"
|
2020-06-05 07:05:43 +00:00
|
|
|
volume_size = var.master_root_volume_size_in_gb
|
2020-08-18 07:49:29 +00:00
|
|
|
volume_type = var.master_volume_type
|
2020-02-24 09:20:49 +00:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
2019-12-09 09:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 12:17:59 +00:00
|
|
|
network {
|
2020-06-05 07:05:43 +00:00
|
|
|
name = var.network_name
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 13:30:54 +00:00
|
|
|
security_groups = local.master_sec_groups
|
2020-02-24 09:20:49 +00:00
|
|
|
|
2019-12-09 09:15:10 +00:00
|
|
|
dynamic "scheduler_hints" {
|
|
|
|
for_each = var.use_server_groups ? [openstack_compute_servergroup_v2.k8s_master[0]] : []
|
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
group = openstack_compute_servergroup_v2.k8s_master[0].id
|
2019-12-09 09:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 12:17:59 +00:00
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 07:05:43 +00:00
|
|
|
ssh_user = var.ssh_user
|
2019-09-25 12:17:59 +00:00
|
|
|
kubespray_groups = "etcd,kube-master,${var.supplementary_master_groups},k8s-cluster,vault"
|
2020-06-05 07:05:43 +00:00
|
|
|
depends_on = var.network_id
|
|
|
|
use_access_ip = var.use_access_ip
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
2020-02-24 09:20:49 +00:00
|
|
|
|
2019-09-25 12:17:59 +00:00
|
|
|
provisioner "local-exec" {
|
2020-03-27 12:46:24 +00:00
|
|
|
command = "sed s/USER/${var.ssh_user}/ ../../contrib/terraform/openstack/ansible_bastion_template.txt | sed s/BASTION_ADDRESS/${element(concat(var.bastion_fips, var.k8s_master_fips), 0)}/ > group_vars/no-floating.yml"
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 12:48:47 +00:00
|
|
|
resource "openstack_compute_instance_v2" "k8s_master_no_etcd" {
|
2020-03-27 12:46:24 +00:00
|
|
|
name = "${var.cluster_name}-k8s-master-ne-${count.index + 1}"
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.number_of_k8s_masters_no_etcd
|
|
|
|
availability_zone = element(var.az_list, count.index)
|
|
|
|
image_name = var.image
|
|
|
|
flavor_id = var.flavor_k8s_master
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2019-09-25 12:17:59 +00:00
|
|
|
|
|
|
|
|
2020-02-24 09:20:49 +00:00
|
|
|
dynamic "block_device" {
|
|
|
|
for_each = var.master_root_volume_size_in_gb > 0 ? [var.image] : []
|
2019-12-09 09:15:10 +00:00
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
uuid = data.openstack_images_image_v2.vm_image.id
|
2020-02-24 09:20:49 +00:00
|
|
|
source_type = "image"
|
2020-06-05 07:05:43 +00:00
|
|
|
volume_size = var.master_root_volume_size_in_gb
|
2020-08-18 07:49:29 +00:00
|
|
|
volume_type = var.master_volume_type
|
2020-02-24 09:20:49 +00:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
2019-12-09 09:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 12:17:59 +00:00
|
|
|
|
2018-01-05 11:09:04 +00:00
|
|
|
network {
|
2020-06-05 07:05:43 +00:00
|
|
|
name = var.network_name
|
2018-01-05 11:09:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 13:30:54 +00:00
|
|
|
security_groups = local.master_sec_groups
|
2020-03-27 12:46:24 +00:00
|
|
|
|
2019-12-09 09:15:10 +00:00
|
|
|
dynamic "scheduler_hints" {
|
|
|
|
for_each = var.use_server_groups ? [openstack_compute_servergroup_v2.k8s_master[0]] : []
|
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
group = openstack_compute_servergroup_v2.k8s_master[0].id
|
2019-12-09 09:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-05 11:09:04 +00:00
|
|
|
metadata = {
|
2020-06-05 07:05:43 +00:00
|
|
|
ssh_user = var.ssh_user
|
2018-04-30 15:11:07 +00:00
|
|
|
kubespray_groups = "kube-master,${var.supplementary_master_groups},k8s-cluster,vault"
|
2020-06-05 07:05:43 +00:00
|
|
|
depends_on = var.network_id
|
|
|
|
use_access_ip = var.use_access_ip
|
2018-01-05 11:09:04 +00:00
|
|
|
}
|
|
|
|
|
2018-04-30 15:11:07 +00:00
|
|
|
provisioner "local-exec" {
|
2020-03-27 12:46:24 +00:00
|
|
|
command = "sed s/USER/${var.ssh_user}/ ../../contrib/terraform/openstack/ansible_bastion_template.txt | sed s/BASTION_ADDRESS/${element(concat(var.bastion_fips, var.k8s_master_fips), 0)}/ > group_vars/no-floating.yml"
|
2018-04-30 15:11:07 +00:00
|
|
|
}
|
2017-12-05 12:48:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_instance_v2" "etcd" {
|
2020-03-27 12:46:24 +00:00
|
|
|
name = "${var.cluster_name}-etcd-${count.index + 1}"
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.number_of_etcd
|
|
|
|
availability_zone = element(var.az_list, count.index)
|
|
|
|
image_name = var.image
|
|
|
|
flavor_id = var.flavor_etcd
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2020-03-27 12:46:24 +00:00
|
|
|
|
2020-02-24 09:20:49 +00:00
|
|
|
dynamic "block_device" {
|
|
|
|
for_each = var.etcd_root_volume_size_in_gb > 0 ? [var.image] : []
|
2019-12-09 09:15:10 +00:00
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
uuid = data.openstack_images_image_v2.vm_image.id
|
2020-02-24 09:20:49 +00:00
|
|
|
source_type = "image"
|
2020-06-05 07:05:43 +00:00
|
|
|
volume_size = var.etcd_root_volume_size_in_gb
|
2020-02-24 09:20:49 +00:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
2019-12-09 09:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 12:17:59 +00:00
|
|
|
network {
|
2020-06-05 07:05:43 +00:00
|
|
|
name = var.network_name
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-05 07:05:43 +00:00
|
|
|
security_groups = [openstack_networking_secgroup_v2.k8s.name]
|
2020-02-24 09:20:49 +00:00
|
|
|
|
2019-12-09 09:15:10 +00:00
|
|
|
dynamic "scheduler_hints" {
|
|
|
|
for_each = var.use_server_groups ? [openstack_compute_servergroup_v2.k8s_etcd[0]] : []
|
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
group = openstack_compute_servergroup_v2.k8s_etcd[0].id
|
2019-12-09 09:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 12:17:59 +00:00
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 07:05:43 +00:00
|
|
|
ssh_user = var.ssh_user
|
2019-09-25 12:17:59 +00:00
|
|
|
kubespray_groups = "etcd,vault,no-floating"
|
2020-06-05 07:05:43 +00:00
|
|
|
depends_on = var.network_id
|
|
|
|
use_access_ip = var.use_access_ip
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 12:48:47 +00:00
|
|
|
resource "openstack_compute_instance_v2" "k8s_master_no_floating_ip" {
|
2020-03-27 12:46:24 +00:00
|
|
|
name = "${var.cluster_name}-k8s-master-nf-${count.index + 1}"
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.number_of_k8s_masters_no_floating_ip
|
|
|
|
availability_zone = element(var.az_list, count.index)
|
|
|
|
image_name = var.image
|
|
|
|
flavor_id = var.flavor_k8s_master
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2019-09-25 12:17:59 +00:00
|
|
|
|
2020-02-24 09:20:49 +00:00
|
|
|
dynamic "block_device" {
|
|
|
|
for_each = var.master_root_volume_size_in_gb > 0 ? [var.image] : []
|
2019-12-09 09:15:10 +00:00
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
uuid = data.openstack_images_image_v2.vm_image.id
|
2020-02-24 09:20:49 +00:00
|
|
|
source_type = "image"
|
2020-06-05 07:05:43 +00:00
|
|
|
volume_size = var.master_root_volume_size_in_gb
|
2020-08-18 07:49:29 +00:00
|
|
|
volume_type = var.master_volume_type
|
2020-02-24 09:20:49 +00:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
2019-12-09 09:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 12:17:59 +00:00
|
|
|
|
2018-01-05 11:09:04 +00:00
|
|
|
network {
|
2020-06-05 07:05:43 +00:00
|
|
|
name = var.network_name
|
2018-01-05 11:09:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 13:30:54 +00:00
|
|
|
security_groups = local.master_sec_groups
|
2020-03-27 12:46:24 +00:00
|
|
|
|
2019-12-09 09:15:10 +00:00
|
|
|
dynamic "scheduler_hints" {
|
|
|
|
for_each = var.use_server_groups ? [openstack_compute_servergroup_v2.k8s_master[0]] : []
|
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
group = openstack_compute_servergroup_v2.k8s_master[0].id
|
2019-12-09 09:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-05 11:09:04 +00:00
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 07:05:43 +00:00
|
|
|
ssh_user = var.ssh_user
|
2018-04-30 15:11:07 +00:00
|
|
|
kubespray_groups = "etcd,kube-master,${var.supplementary_master_groups},k8s-cluster,vault,no-floating"
|
2020-06-05 07:05:43 +00:00
|
|
|
depends_on = var.network_id
|
|
|
|
use_access_ip = var.use_access_ip
|
2018-01-05 11:09:04 +00:00
|
|
|
}
|
2017-12-05 12:48:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_instance_v2" "k8s_master_no_floating_ip_no_etcd" {
|
2020-03-27 12:46:24 +00:00
|
|
|
name = "${var.cluster_name}-k8s-master-ne-nf-${count.index + 1}"
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.number_of_k8s_masters_no_floating_ip_no_etcd
|
|
|
|
availability_zone = element(var.az_list, count.index)
|
|
|
|
image_name = var.image
|
|
|
|
flavor_id = var.flavor_k8s_master
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2018-01-05 11:09:04 +00:00
|
|
|
|
2020-02-24 09:20:49 +00:00
|
|
|
dynamic "block_device" {
|
|
|
|
for_each = var.master_root_volume_size_in_gb > 0 ? [var.image] : []
|
2019-12-09 09:15:10 +00:00
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
uuid = data.openstack_images_image_v2.vm_image.id
|
2020-02-24 09:20:49 +00:00
|
|
|
source_type = "image"
|
2020-06-05 07:05:43 +00:00
|
|
|
volume_size = var.master_root_volume_size_in_gb
|
2020-08-18 07:49:29 +00:00
|
|
|
volume_type = var.master_volume_type
|
2020-02-24 09:20:49 +00:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
2019-12-09 09:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-05 12:48:47 +00:00
|
|
|
|
2019-09-25 12:17:59 +00:00
|
|
|
network {
|
2020-06-05 07:05:43 +00:00
|
|
|
name = var.network_name
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 13:30:54 +00:00
|
|
|
security_groups = local.master_sec_groups
|
2020-03-27 12:46:24 +00:00
|
|
|
|
2019-12-09 09:15:10 +00:00
|
|
|
dynamic "scheduler_hints" {
|
|
|
|
for_each = var.use_server_groups ? [openstack_compute_servergroup_v2.k8s_master[0]] : []
|
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
group = openstack_compute_servergroup_v2.k8s_master[0].id
|
2019-12-09 09:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 12:17:59 +00:00
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 07:05:43 +00:00
|
|
|
ssh_user = var.ssh_user
|
2019-09-25 12:17:59 +00:00
|
|
|
kubespray_groups = "kube-master,${var.supplementary_master_groups},k8s-cluster,vault,no-floating"
|
2020-06-05 07:05:43 +00:00
|
|
|
depends_on = var.network_id
|
|
|
|
use_access_ip = var.use_access_ip
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 12:48:47 +00:00
|
|
|
resource "openstack_compute_instance_v2" "k8s_node" {
|
2020-03-27 12:46:24 +00:00
|
|
|
name = "${var.cluster_name}-k8s-node-${count.index + 1}"
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.number_of_k8s_nodes
|
|
|
|
availability_zone = element(var.az_list_node, count.index)
|
|
|
|
image_name = var.image
|
|
|
|
flavor_id = var.flavor_k8s_node
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2018-01-05 11:09:04 +00:00
|
|
|
|
2020-02-24 09:20:49 +00:00
|
|
|
dynamic "block_device" {
|
|
|
|
for_each = var.node_root_volume_size_in_gb > 0 ? [var.image] : []
|
2019-12-09 09:15:10 +00:00
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
uuid = data.openstack_images_image_v2.vm_image.id
|
2020-02-24 09:20:49 +00:00
|
|
|
source_type = "image"
|
2020-06-05 07:05:43 +00:00
|
|
|
volume_size = var.node_root_volume_size_in_gb
|
2020-02-24 09:20:49 +00:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
2019-12-09 09:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 12:17:59 +00:00
|
|
|
network {
|
2020-06-05 07:05:43 +00:00
|
|
|
name = var.network_name
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 13:30:54 +00:00
|
|
|
security_groups = local.worker_sec_groups
|
2020-02-24 09:20:49 +00:00
|
|
|
|
2019-12-09 09:15:10 +00:00
|
|
|
dynamic "scheduler_hints" {
|
|
|
|
for_each = var.use_server_groups ? [openstack_compute_servergroup_v2.k8s_node[0]] : []
|
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
group = openstack_compute_servergroup_v2.k8s_node[0].id
|
2019-12-09 09:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 12:17:59 +00:00
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 07:05:43 +00:00
|
|
|
ssh_user = var.ssh_user
|
2019-09-25 12:17:59 +00:00
|
|
|
kubespray_groups = "kube-node,k8s-cluster,${var.supplementary_node_groups}"
|
2020-06-05 07:05:43 +00:00
|
|
|
depends_on = var.network_id
|
|
|
|
use_access_ip = var.use_access_ip
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "local-exec" {
|
2020-03-27 12:46:24 +00:00
|
|
|
command = "sed s/USER/${var.ssh_user}/ ../../contrib/terraform/openstack/ansible_bastion_template.txt | sed s/BASTION_ADDRESS/${element(concat(var.bastion_fips, var.k8s_node_fips), 0)}/ > group_vars/no-floating.yml"
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 12:48:47 +00:00
|
|
|
resource "openstack_compute_instance_v2" "k8s_node_no_floating_ip" {
|
2020-03-27 12:46:24 +00:00
|
|
|
name = "${var.cluster_name}-k8s-node-nf-${count.index + 1}"
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.number_of_k8s_nodes_no_floating_ip
|
|
|
|
availability_zone = element(var.az_list_node, count.index)
|
|
|
|
image_name = var.image
|
|
|
|
flavor_id = var.flavor_k8s_node
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2019-09-25 12:17:59 +00:00
|
|
|
|
2020-02-24 09:20:49 +00:00
|
|
|
dynamic "block_device" {
|
|
|
|
for_each = var.node_root_volume_size_in_gb > 0 ? [var.image] : []
|
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
uuid = data.openstack_images_image_v2.vm_image.id
|
2020-02-24 09:20:49 +00:00
|
|
|
source_type = "image"
|
2020-06-05 07:05:43 +00:00
|
|
|
volume_size = var.node_root_volume_size_in_gb
|
2020-02-24 09:20:49 +00:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 12:17:59 +00:00
|
|
|
network {
|
2020-06-05 07:05:43 +00:00
|
|
|
name = var.network_name
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 13:30:54 +00:00
|
|
|
security_groups = local.worker_sec_groups
|
2020-03-27 12:46:24 +00:00
|
|
|
|
2019-12-09 09:15:10 +00:00
|
|
|
dynamic "scheduler_hints" {
|
|
|
|
for_each = var.use_server_groups ? [openstack_compute_servergroup_v2.k8s_node[0]] : []
|
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
group = openstack_compute_servergroup_v2.k8s_node[0].id
|
2019-12-09 09:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 12:17:59 +00:00
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 07:05:43 +00:00
|
|
|
ssh_user = var.ssh_user
|
2019-09-25 12:17:59 +00:00
|
|
|
kubespray_groups = "kube-node,k8s-cluster,no-floating,${var.supplementary_node_groups}"
|
2020-06-05 07:05:43 +00:00
|
|
|
depends_on = var.network_id
|
|
|
|
use_access_ip = var.use_access_ip
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 14:52:45 +00:00
|
|
|
resource "openstack_compute_instance_v2" "k8s_nodes" {
|
|
|
|
for_each = var.number_of_k8s_nodes == 0 && var.number_of_k8s_nodes_no_floating_ip == 0 ? var.k8s_nodes : {}
|
|
|
|
name = "${var.cluster_name}-k8s-node-${each.key}"
|
2020-06-05 07:05:43 +00:00
|
|
|
availability_zone = each.value.az
|
|
|
|
image_name = var.image
|
|
|
|
flavor_id = each.value.flavor
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2020-04-16 14:52:45 +00:00
|
|
|
|
|
|
|
dynamic "block_device" {
|
|
|
|
for_each = var.node_root_volume_size_in_gb > 0 ? [var.image] : []
|
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
uuid = data.openstack_images_image_v2.vm_image.id
|
2020-04-16 14:52:45 +00:00
|
|
|
source_type = "image"
|
2020-06-05 07:05:43 +00:00
|
|
|
volume_size = var.node_root_volume_size_in_gb
|
2020-04-16 14:52:45 +00:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
network {
|
2020-06-05 07:05:43 +00:00
|
|
|
name = var.network_name
|
2020-04-16 14:52:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 13:30:54 +00:00
|
|
|
security_groups = local.worker_sec_groups
|
2020-04-16 14:52:45 +00:00
|
|
|
|
|
|
|
dynamic "scheduler_hints" {
|
|
|
|
for_each = var.use_server_groups ? [openstack_compute_servergroup_v2.k8s_node[0]] : []
|
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
group = openstack_compute_servergroup_v2.k8s_node[0].id
|
2020-04-16 14:52:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 07:05:43 +00:00
|
|
|
ssh_user = var.ssh_user
|
2020-04-16 14:52:45 +00:00
|
|
|
kubespray_groups = "kube-node,k8s-cluster,%{if each.value.floating_ip == false}no-floating,%{endif}${var.supplementary_node_groups}"
|
2020-06-05 07:05:43 +00:00
|
|
|
depends_on = var.network_id
|
|
|
|
use_access_ip = var.use_access_ip
|
2020-04-16 14:52:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "local-exec" {
|
|
|
|
command = "%{if each.value.floating_ip}sed s/USER/${var.ssh_user}/ ../../contrib/terraform/openstack/ansible_bastion_template.txt | sed s/BASTION_ADDRESS/${element(concat(var.bastion_fips, [for key, value in var.k8s_nodes_fips : value.address]), 0)}/ > group_vars/no-floating.yml%{else}true%{endif}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 09:20:49 +00:00
|
|
|
resource "openstack_compute_instance_v2" "glusterfs_node_no_floating_ip" {
|
2020-03-27 12:46:24 +00:00
|
|
|
name = "${var.cluster_name}-gfs-node-nf-${count.index + 1}"
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.number_of_gfs_nodes_no_floating_ip
|
|
|
|
availability_zone = element(var.az_list, count.index)
|
|
|
|
image_name = var.image_gfs
|
|
|
|
flavor_id = var.flavor_gfs_node
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2018-01-05 11:09:04 +00:00
|
|
|
|
2020-02-24 09:20:49 +00:00
|
|
|
dynamic "block_device" {
|
|
|
|
for_each = var.gfs_root_volume_size_in_gb > 0 ? [var.image] : []
|
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
uuid = data.openstack_images_image_v2.vm_image.id
|
2020-02-24 09:20:49 +00:00
|
|
|
source_type = "image"
|
2020-06-05 07:05:43 +00:00
|
|
|
volume_size = var.gfs_root_volume_size_in_gb
|
2020-02-24 09:20:49 +00:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
|
|
|
}
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 11:09:04 +00:00
|
|
|
network {
|
2020-06-05 07:05:43 +00:00
|
|
|
name = var.network_name
|
2018-01-05 11:09:04 +00:00
|
|
|
}
|
|
|
|
|
2020-06-05 07:05:43 +00:00
|
|
|
security_groups = [openstack_networking_secgroup_v2.k8s.name]
|
2020-03-27 12:46:24 +00:00
|
|
|
|
2019-12-09 09:15:10 +00:00
|
|
|
dynamic "scheduler_hints" {
|
|
|
|
for_each = var.use_server_groups ? [openstack_compute_servergroup_v2.k8s_node[0]] : []
|
|
|
|
content {
|
2020-06-05 07:05:43 +00:00
|
|
|
group = openstack_compute_servergroup_v2.k8s_node[0].id
|
2019-12-09 09:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-05 11:09:04 +00:00
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 07:05:43 +00:00
|
|
|
ssh_user = var.ssh_user_gfs
|
2020-02-24 09:20:49 +00:00
|
|
|
kubespray_groups = "gfs-cluster,network-storage,no-floating"
|
2020-06-05 07:05:43 +00:00
|
|
|
depends_on = var.network_id
|
|
|
|
use_access_ip = var.use_access_ip
|
2018-01-05 11:09:04 +00:00
|
|
|
}
|
2017-12-05 12:48:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_floatingip_associate_v2" "bastion" {
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.number_of_bastions
|
|
|
|
floating_ip = var.bastion_fips[count.index]
|
|
|
|
instance_id = element(openstack_compute_instance_v2.bastion.*.id, count.index)
|
|
|
|
wait_until_associated = var.wait_for_floatingip
|
2017-12-05 12:48:47 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 12:17:59 +00:00
|
|
|
|
2017-12-05 12:48:47 +00:00
|
|
|
resource "openstack_compute_floatingip_associate_v2" "k8s_master" {
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.number_of_k8s_masters
|
|
|
|
instance_id = element(openstack_compute_instance_v2.k8s_master.*.id, count.index)
|
|
|
|
floating_ip = var.k8s_master_fips[count.index]
|
|
|
|
wait_until_associated = var.wait_for_floatingip
|
2017-12-05 12:48:47 +00:00
|
|
|
}
|
|
|
|
|
2019-04-29 05:58:20 +00:00
|
|
|
resource "openstack_compute_floatingip_associate_v2" "k8s_master_no_etcd" {
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.master_root_volume_size_in_gb == 0 ? var.number_of_k8s_masters_no_etcd : 0
|
|
|
|
instance_id = element(openstack_compute_instance_v2.k8s_master_no_etcd.*.id, count.index)
|
|
|
|
floating_ip = var.k8s_master_no_etcd_fips[count.index]
|
2019-04-29 05:58:20 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 12:48:47 +00:00
|
|
|
resource "openstack_compute_floatingip_associate_v2" "k8s_node" {
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.node_root_volume_size_in_gb == 0 ? var.number_of_k8s_nodes : 0
|
|
|
|
floating_ip = var.k8s_node_fips[count.index]
|
|
|
|
instance_id = element(openstack_compute_instance_v2.k8s_node[*].id, count.index)
|
|
|
|
wait_until_associated = var.wait_for_floatingip
|
2020-04-16 14:52:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_floatingip_associate_v2" "k8s_nodes" {
|
|
|
|
for_each = var.number_of_k8s_nodes == 0 && var.number_of_k8s_nodes_no_floating_ip == 0 ? { for key, value in var.k8s_nodes : key => value if value.floating_ip } : {}
|
2020-06-05 07:05:43 +00:00
|
|
|
floating_ip = var.k8s_nodes_fips[each.key].address
|
|
|
|
instance_id = openstack_compute_instance_v2.k8s_nodes[each.key].id
|
|
|
|
wait_until_associated = var.wait_for_floatingip
|
2017-12-05 12:48:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_blockstorage_volume_v2" "glusterfs_volume" {
|
2020-03-27 12:46:24 +00:00
|
|
|
name = "${var.cluster_name}-glusterfs_volume-${count.index + 1}"
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.gfs_root_volume_size_in_gb == 0 ? var.number_of_gfs_nodes_no_floating_ip : 0
|
2019-09-25 12:17:59 +00:00
|
|
|
description = "Non-ephemeral volume for GlusterFS"
|
2020-06-05 07:05:43 +00:00
|
|
|
size = var.gfs_volume_size_in_gb
|
2019-09-25 12:17:59 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 12:48:47 +00:00
|
|
|
resource "openstack_compute_volume_attach_v2" "glusterfs_volume" {
|
2020-06-05 07:05:43 +00:00
|
|
|
count = var.gfs_root_volume_size_in_gb == 0 ? var.number_of_gfs_nodes_no_floating_ip : 0
|
|
|
|
instance_id = element(openstack_compute_instance_v2.glusterfs_node_no_floating_ip.*.id, count.index)
|
|
|
|
volume_id = element(openstack_blockstorage_volume_v2.glusterfs_volume.*.id, count.index)
|
2020-04-16 14:52:45 +00:00
|
|
|
}
|