2019-09-25 20:17:59 +08:00
|
|
|
data "openstack_images_image_v2" "vm_image" {
|
2021-02-16 23:05:06 +08:00
|
|
|
count = var.image_uuid == "" ? 1 : 0
|
2021-03-15 22:05:06 +08:00
|
|
|
most_recent = true
|
2020-06-05 15:05:43 +08:00
|
|
|
name = var.image
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
data "openstack_images_image_v2" "gfs_image" {
|
2021-02-16 23:05:06 +08:00
|
|
|
count = var.image_gfs_uuid == "" ? var.image_uuid == "" ? 1 : 0 : 0
|
2021-03-15 22:05:06 +08:00
|
|
|
most_recent = true
|
2020-06-05 15:05:43 +08:00
|
|
|
name = var.image_gfs == "" ? var.image : var.image_gfs
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
|
2021-02-16 23:05:06 +08:00
|
|
|
data "openstack_images_image_v2" "image_master" {
|
|
|
|
count = var.image_master_uuid == "" ? var.image_uuid == "" ? 1 : 0 : 0
|
|
|
|
name = var.image_master == "" ? var.image : var.image_master
|
|
|
|
}
|
|
|
|
|
2022-12-07 10:28:38 +08:00
|
|
|
data "cloudinit_config" "cloudinit" {
|
|
|
|
part {
|
|
|
|
content_type = "text/cloud-config"
|
2023-01-05 20:16:00 +08:00
|
|
|
content = templatefile("${path.module}/templates/cloudinit.yaml.tmpl", {
|
|
|
|
# template_file doesn't support lists
|
|
|
|
extra_partitions = ""
|
|
|
|
})
|
2022-12-07 10:28:38 +08:00
|
|
|
}
|
2022-02-03 00:50:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
data "openstack_networking_network_v2" "k8s_network" {
|
2022-05-03 23:51:56 +08:00
|
|
|
count = var.use_existing_network ? 1 : 0
|
|
|
|
name = var.network_name
|
2022-01-11 21:23:16 +08:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:48:47 +08:00
|
|
|
resource "openstack_compute_keypair_v2" "k8s" {
|
2018-01-05 19:09:04 +08:00
|
|
|
name = "kubernetes-${var.cluster_name}"
|
2020-06-05 15:05:43 +08:00
|
|
|
public_key = chomp(file(var.public_key_path))
|
2017-12-05 20:48:47 +08:00
|
|
|
}
|
|
|
|
|
2018-09-28 17:35:02 +08:00
|
|
|
resource "openstack_networking_secgroup_v2" "k8s_master" {
|
2019-04-17 17:10:03 +08:00
|
|
|
name = "${var.cluster_name}-k8s-master"
|
|
|
|
description = "${var.cluster_name} - Kubernetes Master"
|
|
|
|
delete_default_rules = true
|
2018-09-28 17:35:02 +08:00
|
|
|
}
|
2018-01-05 19:09:04 +08:00
|
|
|
|
2020-11-05 21:30:54 +08: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 17:35:02 +08:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "k8s_master" {
|
2020-06-05 15:05:43 +08:00
|
|
|
count = length(var.master_allowed_remote_ips)
|
2019-02-18 13:04:41 +08:00
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = "tcp"
|
|
|
|
port_range_min = "6443"
|
|
|
|
port_range_max = "6443"
|
2020-06-05 15:05:43 +08:00
|
|
|
remote_ip_prefix = var.master_allowed_remote_ips[count.index]
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.k8s_master.id
|
2017-12-05 20:48:47 +08:00
|
|
|
}
|
|
|
|
|
2020-08-27 17:07:13 +08: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 17:35:02 +08:00
|
|
|
resource "openstack_networking_secgroup_v2" "bastion" {
|
2019-04-17 17:10:03 +08:00
|
|
|
name = "${var.cluster_name}-bastion"
|
2020-06-05 15:05:43 +08:00
|
|
|
count = var.number_of_bastions != "" ? 1 : 0
|
2019-04-17 17:10:03 +08:00
|
|
|
description = "${var.cluster_name} - Bastion Server"
|
|
|
|
delete_default_rules = true
|
2018-09-28 17:35:02 +08:00
|
|
|
}
|
2018-01-05 19:09:04 +08:00
|
|
|
|
2018-09-28 17:35:02 +08:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "bastion" {
|
2020-06-05 15:05:43 +08:00
|
|
|
count = var.number_of_bastions != "" ? length(var.bastion_allowed_remote_ips) : 0
|
2019-02-18 13:04:41 +08:00
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = "tcp"
|
|
|
|
port_range_min = "22"
|
|
|
|
port_range_max = "22"
|
2020-06-05 15:05:43 +08:00
|
|
|
remote_ip_prefix = var.bastion_allowed_remote_ips[count.index]
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.bastion[0].id
|
2017-12-05 20:48:47 +08:00
|
|
|
}
|
|
|
|
|
2022-09-28 13:03:35 +08:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "k8s_bastion_ports" {
|
|
|
|
count = length(var.bastion_allowed_ports)
|
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = lookup(var.bastion_allowed_ports[count.index], "protocol", "tcp")
|
|
|
|
port_range_min = lookup(var.bastion_allowed_ports[count.index], "port_range_min")
|
|
|
|
port_range_max = lookup(var.bastion_allowed_ports[count.index], "port_range_max")
|
|
|
|
remote_ip_prefix = lookup(var.bastion_allowed_ports[count.index], "remote_ip_prefix", "0.0.0.0/0")
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.bastion[0].id
|
|
|
|
}
|
|
|
|
|
2018-09-28 17:35:02 +08:00
|
|
|
resource "openstack_networking_secgroup_v2" "k8s" {
|
2019-04-17 17:10:03 +08:00
|
|
|
name = "${var.cluster_name}-k8s"
|
|
|
|
description = "${var.cluster_name} - Kubernetes"
|
|
|
|
delete_default_rules = true
|
2018-09-28 17:35:02 +08:00
|
|
|
}
|
2018-01-05 19:09:04 +08:00
|
|
|
|
2018-09-28 17:35:02 +08:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "k8s" {
|
2019-02-18 13:04:41 +08:00
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
2020-06-05 15:05:43 +08:00
|
|
|
remote_group_id = openstack_networking_secgroup_v2.k8s.id
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.k8s.id
|
2017-12-05 20:48:47 +08:00
|
|
|
}
|
2018-09-28 17:35:02 +08:00
|
|
|
|
2019-04-15 22:22:08 +08:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "k8s_allowed_remote_ips" {
|
2020-06-05 15:05:43 +08:00
|
|
|
count = length(var.k8s_allowed_remote_ips)
|
2019-04-15 22:22:08 +08:00
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = "tcp"
|
|
|
|
port_range_min = "22"
|
|
|
|
port_range_max = "22"
|
2020-06-05 15:05:43 +08:00
|
|
|
remote_ip_prefix = var.k8s_allowed_remote_ips[count.index]
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.k8s.id
|
2019-04-15 22:22:08 +08:00
|
|
|
}
|
|
|
|
|
2019-04-17 17:10:03 +08:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "egress" {
|
2020-06-05 15:05:43 +08:00
|
|
|
count = length(var.k8s_allowed_egress_ips)
|
2019-04-17 17:10:03 +08:00
|
|
|
direction = "egress"
|
|
|
|
ethertype = "IPv4"
|
2020-06-05 15:05:43 +08:00
|
|
|
remote_ip_prefix = var.k8s_allowed_egress_ips[count.index]
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.k8s.id
|
2019-04-17 17:10:03 +08:00
|
|
|
}
|
|
|
|
|
2018-09-28 17:35:02 +08:00
|
|
|
resource "openstack_networking_secgroup_v2" "worker" {
|
2019-04-17 17:10:03 +08:00
|
|
|
name = "${var.cluster_name}-k8s-worker"
|
|
|
|
description = "${var.cluster_name} - Kubernetes worker nodes"
|
|
|
|
delete_default_rules = true
|
2018-09-28 17:35:02 +08:00
|
|
|
}
|
2018-07-27 20:57:29 +08:00
|
|
|
|
2020-11-05 21:30:54 +08: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 17:35:02 +08:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "worker" {
|
2020-06-05 15:05:43 +08:00
|
|
|
count = length(var.worker_allowed_ports)
|
2019-02-18 13:04:41 +08:00
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
2020-06-05 15:05:43 +08: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 20:57:29 +08:00
|
|
|
}
|
2017-12-05 20:48:47 +08:00
|
|
|
|
2019-12-09 17:15:10 +08:00
|
|
|
resource "openstack_compute_servergroup_v2" "k8s_master" {
|
2021-11-22 18:53:09 +08:00
|
|
|
count = var.master_server_group_policy != "" ? 1 : 0
|
2020-03-27 20:46:24 +08:00
|
|
|
name = "k8s-master-srvgrp"
|
2021-11-22 18:53:09 +08:00
|
|
|
policies = [var.master_server_group_policy]
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_servergroup_v2" "k8s_node" {
|
2021-11-22 18:53:09 +08:00
|
|
|
count = var.node_server_group_policy != "" ? 1 : 0
|
2020-03-27 20:46:24 +08:00
|
|
|
name = "k8s-node-srvgrp"
|
2021-11-22 18:53:09 +08:00
|
|
|
policies = [var.node_server_group_policy]
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_servergroup_v2" "k8s_etcd" {
|
2021-11-22 18:53:09 +08:00
|
|
|
count = var.etcd_server_group_policy != "" ? 1 : 0
|
2020-03-27 20:46:24 +08:00
|
|
|
name = "k8s-etcd-srvgrp"
|
2021-11-22 18:53:09 +08:00
|
|
|
policies = [var.etcd_server_group_policy]
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
|
2023-01-05 20:16:00 +08:00
|
|
|
resource "openstack_compute_servergroup_v2" "k8s_node_additional" {
|
|
|
|
for_each = var.additional_server_groups
|
|
|
|
name = "k8s-${each.key}-srvgrp"
|
|
|
|
policies = [each.value.policy]
|
|
|
|
}
|
|
|
|
|
2020-11-05 21:30:54 +08:00
|
|
|
locals {
|
|
|
|
# master groups
|
|
|
|
master_sec_groups = compact([
|
2022-05-03 23:51:56 +08:00
|
|
|
openstack_networking_secgroup_v2.k8s_master.id,
|
|
|
|
openstack_networking_secgroup_v2.k8s.id,
|
|
|
|
var.extra_sec_groups ?openstack_networking_secgroup_v2.k8s_master_extra[0].id : "",
|
2020-11-05 21:30:54 +08:00
|
|
|
])
|
|
|
|
# worker groups
|
|
|
|
worker_sec_groups = compact([
|
2022-05-03 23:51:56 +08:00
|
|
|
openstack_networking_secgroup_v2.k8s.id,
|
|
|
|
openstack_networking_secgroup_v2.worker.id,
|
|
|
|
var.extra_sec_groups ? openstack_networking_secgroup_v2.worker_extra[0].id : "",
|
2020-11-05 21:30:54 +08:00
|
|
|
])
|
2022-01-15 04:58:32 +08:00
|
|
|
# bastion groups
|
|
|
|
bastion_sec_groups = compact(concat([
|
2022-05-03 23:51:56 +08:00
|
|
|
openstack_networking_secgroup_v2.k8s.id,
|
|
|
|
openstack_networking_secgroup_v2.bastion[0].id,
|
2022-01-15 04:58:32 +08:00
|
|
|
]))
|
|
|
|
# etcd groups
|
2022-05-03 23:51:56 +08:00
|
|
|
etcd_sec_groups = compact([openstack_networking_secgroup_v2.k8s.id])
|
2022-01-15 04:58:32 +08:00
|
|
|
# glusterfs groups
|
2022-05-03 23:51:56 +08:00
|
|
|
gfs_sec_groups = compact([openstack_networking_secgroup_v2.k8s.id])
|
2021-02-16 23:05:06 +08:00
|
|
|
|
|
|
|
# Image uuid
|
|
|
|
image_to_use_node = var.image_uuid != "" ? var.image_uuid : data.openstack_images_image_v2.vm_image[0].id
|
|
|
|
# Image_gfs uuid
|
|
|
|
image_to_use_gfs = var.image_gfs_uuid != "" ? var.image_gfs_uuid : var.image_uuid != "" ? var.image_uuid : data.openstack_images_image_v2.gfs_image[0].id
|
|
|
|
# image_master uuidimage_gfs_uuid
|
|
|
|
image_to_use_master = var.image_master_uuid != "" ? var.image_master_uuid : var.image_uuid != "" ? var.image_uuid : data.openstack_images_image_v2.image_master[0].id
|
2023-01-05 20:16:00 +08:00
|
|
|
|
|
|
|
k8s_nodes_settings = {
|
|
|
|
for name, node in var.k8s_nodes :
|
|
|
|
name => {
|
|
|
|
"use_local_disk" = (node.root_volume_size_in_gb != null ? node.root_volume_size_in_gb : var.node_root_volume_size_in_gb) == 0,
|
|
|
|
"image_id" = node.image_id != null ? node.image_id : local.image_to_use_node,
|
|
|
|
"volume_size" = node.root_volume_size_in_gb != null ? node.root_volume_size_in_gb : var.node_root_volume_size_in_gb,
|
|
|
|
"volume_type" = node.volume_type != null ? node.volume_type : var.node_volume_type,
|
|
|
|
"network_id" = node.network_id != null ? node.network_id : (var.use_existing_network ? data.openstack_networking_network_v2.k8s_network[0].id : var.network_id)
|
|
|
|
"server_group" = node.server_group != null ? [openstack_compute_servergroup_v2.k8s_node_additional[node.server_group].id] : (var.node_server_group_policy != "" ? [openstack_compute_servergroup_v2.k8s_node[0].id] : [])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
k8s_masters_settings = {
|
|
|
|
for name, node in var.k8s_masters :
|
|
|
|
name => {
|
|
|
|
"use_local_disk" = (node.root_volume_size_in_gb != null ? node.root_volume_size_in_gb : var.master_root_volume_size_in_gb) == 0,
|
|
|
|
"image_id" = node.image_id != null ? node.image_id : local.image_to_use_master,
|
|
|
|
"volume_size" = node.root_volume_size_in_gb != null ? node.root_volume_size_in_gb : var.master_root_volume_size_in_gb,
|
|
|
|
"volume_type" = node.volume_type != null ? node.volume_type : var.master_volume_type,
|
|
|
|
"network_id" = node.network_id != null ? node.network_id : (var.use_existing_network ? data.openstack_networking_network_v2.k8s_network[0].id : var.network_id)
|
|
|
|
}
|
|
|
|
}
|
2020-11-05 21:30:54 +08:00
|
|
|
}
|
|
|
|
|
2022-02-03 00:50:22 +08:00
|
|
|
resource "openstack_networking_port_v2" "bastion_port" {
|
|
|
|
count = var.number_of_bastions
|
|
|
|
name = "${var.cluster_name}-bastion-${count.index + 1}"
|
2022-05-03 23:51:56 +08:00
|
|
|
network_id = var.use_existing_network ? data.openstack_networking_network_v2.k8s_network[0].id : var.network_id
|
2022-02-03 00:50:22 +08:00
|
|
|
admin_state_up = "true"
|
2022-05-03 23:51:56 +08:00
|
|
|
port_security_enabled = var.force_null_port_security ? null : var.port_security_enabled
|
2022-02-03 00:50:22 +08:00
|
|
|
security_group_ids = var.port_security_enabled ? local.bastion_sec_groups : null
|
|
|
|
no_security_groups = var.port_security_enabled ? null : false
|
2023-01-05 20:16:00 +08:00
|
|
|
dynamic "fixed_ip" {
|
|
|
|
for_each = var.private_subnet_id == "" ? [] : [true]
|
|
|
|
content {
|
|
|
|
subnet_id = var.private_subnet_id
|
|
|
|
}
|
2022-09-30 15:48:29 +08:00
|
|
|
}
|
2022-05-03 23:51:56 +08:00
|
|
|
|
|
|
|
depends_on = [
|
|
|
|
var.network_router_id
|
|
|
|
]
|
2022-02-03 00:50:22 +08:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:48:47 +08:00
|
|
|
resource "openstack_compute_instance_v2" "bastion" {
|
2020-03-27 20:46:24 +08:00
|
|
|
name = "${var.cluster_name}-bastion-${count.index + 1}"
|
2020-06-05 15:05:43 +08:00
|
|
|
count = var.number_of_bastions
|
2021-02-16 23:05:06 +08:00
|
|
|
image_id = var.bastion_root_volume_size_in_gb == 0 ? local.image_to_use_node : null
|
2020-06-05 15:05:43 +08:00
|
|
|
flavor_id = var.flavor_bastion
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2022-12-07 10:28:38 +08:00
|
|
|
user_data = data.cloudinit_config.cloudinit.rendered
|
2018-01-05 19:09:04 +08:00
|
|
|
|
2020-02-24 17:20:49 +08:00
|
|
|
dynamic "block_device" {
|
2021-02-16 23:05:06 +08:00
|
|
|
for_each = var.bastion_root_volume_size_in_gb > 0 ? [local.image_to_use_node] : []
|
2020-02-24 17:20:49 +08:00
|
|
|
content {
|
2021-02-16 23:05:06 +08:00
|
|
|
uuid = local.image_to_use_node
|
2020-02-24 17:20:49 +08:00
|
|
|
source_type = "image"
|
2020-06-05 15:05:43 +08:00
|
|
|
volume_size = var.bastion_root_volume_size_in_gb
|
2020-02-24 17:20:49 +08:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
|
|
|
}
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
network {
|
2022-02-03 00:50:22 +08:00
|
|
|
port = element(openstack_networking_port_v2.bastion_port.*.id, count.index)
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 15:05:43 +08:00
|
|
|
ssh_user = var.ssh_user
|
2019-09-25 20:17:59 +08:00
|
|
|
kubespray_groups = "bastion"
|
2022-05-03 23:51:56 +08:00
|
|
|
depends_on = var.network_router_id
|
2020-06-05 15:05:43 +08:00
|
|
|
use_access_ip = var.use_access_ip
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "local-exec" {
|
2022-03-29 15:07:11 +08:00
|
|
|
command = "sed -e s/USER/${var.ssh_user}/ -e s/BASTION_ADDRESS/${var.bastion_fips[0]}/ ${path.module}/ansible_bastion_template.txt > ${var.group_vars_path}/no_floating.yml"
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-03 00:50:22 +08:00
|
|
|
resource "openstack_networking_port_v2" "k8s_master_port" {
|
|
|
|
count = var.number_of_k8s_masters
|
|
|
|
name = "${var.cluster_name}-k8s-master-${count.index + 1}"
|
2022-05-03 23:51:56 +08:00
|
|
|
network_id = var.use_existing_network ? data.openstack_networking_network_v2.k8s_network[0].id : var.network_id
|
2022-02-03 00:50:22 +08:00
|
|
|
admin_state_up = "true"
|
2022-05-03 23:51:56 +08:00
|
|
|
port_security_enabled = var.force_null_port_security ? null : var.port_security_enabled
|
2022-02-03 00:50:22 +08:00
|
|
|
security_group_ids = var.port_security_enabled ? local.master_sec_groups : null
|
|
|
|
no_security_groups = var.port_security_enabled ? null : false
|
2023-01-05 20:16:00 +08:00
|
|
|
dynamic "fixed_ip" {
|
|
|
|
for_each = var.private_subnet_id == "" ? [] : [true]
|
|
|
|
content {
|
|
|
|
subnet_id = var.private_subnet_id
|
|
|
|
}
|
2022-09-30 15:48:29 +08:00
|
|
|
}
|
2022-05-03 23:51:56 +08:00
|
|
|
|
|
|
|
depends_on = [
|
|
|
|
var.network_router_id
|
|
|
|
]
|
2022-02-03 00:50:22 +08:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:48:47 +08:00
|
|
|
resource "openstack_compute_instance_v2" "k8s_master" {
|
2020-03-27 20:46:24 +08:00
|
|
|
name = "${var.cluster_name}-k8s-master-${count.index + 1}"
|
2020-06-05 15:05:43 +08:00
|
|
|
count = var.number_of_k8s_masters
|
|
|
|
availability_zone = element(var.az_list, count.index)
|
2021-02-16 23:05:06 +08:00
|
|
|
image_id = var.master_root_volume_size_in_gb == 0 ? local.image_to_use_master : null
|
2020-06-05 15:05:43 +08:00
|
|
|
flavor_id = var.flavor_k8s_master
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2022-12-07 10:28:38 +08:00
|
|
|
user_data = data.cloudinit_config.cloudinit.rendered
|
2018-01-05 19:09:04 +08:00
|
|
|
|
|
|
|
|
2020-02-24 17:20:49 +08:00
|
|
|
dynamic "block_device" {
|
2021-02-16 23:05:06 +08:00
|
|
|
for_each = var.master_root_volume_size_in_gb > 0 ? [local.image_to_use_master] : []
|
2019-12-09 17:15:10 +08:00
|
|
|
content {
|
2021-02-16 23:05:06 +08:00
|
|
|
uuid = local.image_to_use_master
|
2020-02-24 17:20:49 +08:00
|
|
|
source_type = "image"
|
2020-06-05 15:05:43 +08:00
|
|
|
volume_size = var.master_root_volume_size_in_gb
|
2020-08-18 15:49:29 +08:00
|
|
|
volume_type = var.master_volume_type
|
2020-02-24 17:20:49 +08:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 20:17:59 +08:00
|
|
|
network {
|
2022-02-03 00:50:22 +08:00
|
|
|
port = element(openstack_networking_port_v2.k8s_master_port.*.id, count.index)
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
|
2019-12-09 17:15:10 +08:00
|
|
|
dynamic "scheduler_hints" {
|
2021-11-22 18:53:09 +08:00
|
|
|
for_each = var.master_server_group_policy != "" ? [openstack_compute_servergroup_v2.k8s_master[0]] : []
|
2019-12-09 17:15:10 +08:00
|
|
|
content {
|
2020-06-05 15:05:43 +08:00
|
|
|
group = openstack_compute_servergroup_v2.k8s_master[0].id
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 20:17:59 +08:00
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 15:05:43 +08:00
|
|
|
ssh_user = var.ssh_user
|
2021-04-29 20:20:50 +08:00
|
|
|
kubespray_groups = "etcd,kube_control_plane,${var.supplementary_master_groups},k8s_cluster"
|
2022-05-03 23:51:56 +08:00
|
|
|
depends_on = var.network_router_id
|
2020-06-05 15:05:43 +08:00
|
|
|
use_access_ip = var.use_access_ip
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
2020-02-24 17:20:49 +08:00
|
|
|
|
2019-09-25 20:17:59 +08:00
|
|
|
provisioner "local-exec" {
|
2022-03-29 15:07:11 +08:00
|
|
|
command = "sed -e s/USER/${var.ssh_user}/ -e s/BASTION_ADDRESS/${element(concat(var.bastion_fips, var.k8s_master_fips), 0)}/ ${path.module}/ansible_bastion_template.txt > ${var.group_vars_path}/no_floating.yml"
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-03 23:51:56 +08:00
|
|
|
resource "openstack_networking_port_v2" "k8s_masters_port" {
|
|
|
|
for_each = var.number_of_k8s_masters == 0 && var.number_of_k8s_masters_no_etcd == 0 && var.number_of_k8s_masters_no_floating_ip == 0 && var.number_of_k8s_masters_no_floating_ip_no_etcd == 0 ? var.k8s_masters : {}
|
|
|
|
name = "${var.cluster_name}-k8s-${each.key}"
|
2023-01-05 20:16:00 +08:00
|
|
|
network_id = local.k8s_masters_settings[each.key].network_id
|
2022-05-03 23:51:56 +08:00
|
|
|
admin_state_up = "true"
|
|
|
|
port_security_enabled = var.force_null_port_security ? null : var.port_security_enabled
|
|
|
|
security_group_ids = var.port_security_enabled ? local.master_sec_groups : null
|
|
|
|
no_security_groups = var.port_security_enabled ? null : false
|
2023-01-05 20:16:00 +08:00
|
|
|
dynamic "fixed_ip" {
|
|
|
|
for_each = var.private_subnet_id == "" ? [] : [true]
|
|
|
|
content {
|
|
|
|
subnet_id = var.private_subnet_id
|
|
|
|
}
|
2022-09-30 15:48:29 +08:00
|
|
|
}
|
2022-05-03 23:51:56 +08:00
|
|
|
|
|
|
|
depends_on = [
|
|
|
|
var.network_router_id
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_instance_v2" "k8s_masters" {
|
|
|
|
for_each = var.number_of_k8s_masters == 0 && var.number_of_k8s_masters_no_etcd == 0 && var.number_of_k8s_masters_no_floating_ip == 0 && var.number_of_k8s_masters_no_floating_ip_no_etcd == 0 ? var.k8s_masters : {}
|
|
|
|
name = "${var.cluster_name}-k8s-${each.key}"
|
|
|
|
availability_zone = each.value.az
|
2023-01-05 20:16:00 +08:00
|
|
|
image_id = local.k8s_masters_settings[each.key].use_local_disk ? local.k8s_masters_settings[each.key].image_id : null
|
2022-05-03 23:51:56 +08:00
|
|
|
flavor_id = each.value.flavor
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
|
|
|
|
|
|
|
dynamic "block_device" {
|
2023-01-05 20:16:00 +08:00
|
|
|
for_each = !local.k8s_masters_settings[each.key].use_local_disk ? [local.k8s_masters_settings[each.key].image_id] : []
|
2022-05-03 23:51:56 +08:00
|
|
|
content {
|
2023-01-05 20:16:00 +08:00
|
|
|
uuid = block_device.value
|
2022-05-03 23:51:56 +08:00
|
|
|
source_type = "image"
|
2023-01-05 20:16:00 +08:00
|
|
|
volume_size = local.k8s_masters_settings[each.key].volume_size
|
|
|
|
volume_type = local.k8s_masters_settings[each.key].volume_type
|
2022-05-03 23:51:56 +08:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
network {
|
|
|
|
port = openstack_networking_port_v2.k8s_masters_port[each.key].id
|
|
|
|
}
|
|
|
|
|
|
|
|
dynamic "scheduler_hints" {
|
|
|
|
for_each = var.master_server_group_policy != "" ? [openstack_compute_servergroup_v2.k8s_master[0]] : []
|
|
|
|
content {
|
|
|
|
group = openstack_compute_servergroup_v2.k8s_master[0].id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata = {
|
|
|
|
ssh_user = var.ssh_user
|
|
|
|
kubespray_groups = "%{if each.value.etcd == true}etcd,%{endif}kube_control_plane,${var.supplementary_master_groups},k8s_cluster%{if each.value.floating_ip == false},no_floating%{endif}"
|
|
|
|
depends_on = var.network_router_id
|
|
|
|
use_access_ip = var.use_access_ip
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "local-exec" {
|
2023-01-05 20:16:00 +08:00
|
|
|
command = "%{if each.value.floating_ip}sed s/USER/${var.ssh_user}/ ${path.module}/ansible_bastion_template.txt | sed s/BASTION_ADDRESS/${element(concat(var.bastion_fips, [for key, value in var.k8s_masters_fips : value.address]), 0)}/ > ${var.group_vars_path}/no_floating.yml%{else}true%{endif}"
|
2022-05-03 23:51:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-03 00:50:22 +08:00
|
|
|
resource "openstack_networking_port_v2" "k8s_master_no_etcd_port" {
|
|
|
|
count = var.number_of_k8s_masters_no_etcd
|
|
|
|
name = "${var.cluster_name}-k8s-master-ne-${count.index + 1}"
|
2022-05-03 23:51:56 +08:00
|
|
|
network_id = var.use_existing_network ? data.openstack_networking_network_v2.k8s_network[0].id : var.network_id
|
2022-02-03 00:50:22 +08:00
|
|
|
admin_state_up = "true"
|
2022-05-03 23:51:56 +08:00
|
|
|
port_security_enabled = var.force_null_port_security ? null : var.port_security_enabled
|
2022-02-03 00:50:22 +08:00
|
|
|
security_group_ids = var.port_security_enabled ? local.master_sec_groups : null
|
|
|
|
no_security_groups = var.port_security_enabled ? null : false
|
2023-01-05 20:16:00 +08:00
|
|
|
dynamic "fixed_ip" {
|
|
|
|
for_each = var.private_subnet_id == "" ? [] : [true]
|
|
|
|
content {
|
|
|
|
subnet_id = var.private_subnet_id
|
|
|
|
}
|
2022-09-30 15:48:29 +08:00
|
|
|
}
|
2022-05-03 23:51:56 +08:00
|
|
|
|
|
|
|
depends_on = [
|
|
|
|
var.network_router_id
|
|
|
|
]
|
2022-02-03 00:50:22 +08:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:48:47 +08:00
|
|
|
resource "openstack_compute_instance_v2" "k8s_master_no_etcd" {
|
2020-03-27 20:46:24 +08:00
|
|
|
name = "${var.cluster_name}-k8s-master-ne-${count.index + 1}"
|
2020-06-05 15:05:43 +08:00
|
|
|
count = var.number_of_k8s_masters_no_etcd
|
|
|
|
availability_zone = element(var.az_list, count.index)
|
2021-02-16 23:05:06 +08:00
|
|
|
image_id = var.master_root_volume_size_in_gb == 0 ? local.image_to_use_master : null
|
2020-06-05 15:05:43 +08:00
|
|
|
flavor_id = var.flavor_k8s_master
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2022-12-07 10:28:38 +08:00
|
|
|
user_data = data.cloudinit_config.cloudinit.rendered
|
2019-09-25 20:17:59 +08:00
|
|
|
|
|
|
|
|
2020-02-24 17:20:49 +08:00
|
|
|
dynamic "block_device" {
|
2021-02-16 23:05:06 +08:00
|
|
|
for_each = var.master_root_volume_size_in_gb > 0 ? [local.image_to_use_master] : []
|
2019-12-09 17:15:10 +08:00
|
|
|
content {
|
2021-02-16 23:05:06 +08:00
|
|
|
uuid = local.image_to_use_master
|
2020-02-24 17:20:49 +08:00
|
|
|
source_type = "image"
|
2020-06-05 15:05:43 +08:00
|
|
|
volume_size = var.master_root_volume_size_in_gb
|
2020-08-18 15:49:29 +08:00
|
|
|
volume_type = var.master_volume_type
|
2020-02-24 17:20:49 +08:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 20:17:59 +08:00
|
|
|
|
2018-01-05 19:09:04 +08:00
|
|
|
network {
|
2022-02-03 00:50:22 +08:00
|
|
|
port = element(openstack_networking_port_v2.k8s_master_no_etcd_port.*.id, count.index)
|
2018-01-05 19:09:04 +08:00
|
|
|
}
|
|
|
|
|
2019-12-09 17:15:10 +08:00
|
|
|
dynamic "scheduler_hints" {
|
2021-11-22 18:53:09 +08:00
|
|
|
for_each = var.master_server_group_policy != "" ? [openstack_compute_servergroup_v2.k8s_master[0]] : []
|
2019-12-09 17:15:10 +08:00
|
|
|
content {
|
2020-06-05 15:05:43 +08:00
|
|
|
group = openstack_compute_servergroup_v2.k8s_master[0].id
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-05 19:09:04 +08:00
|
|
|
metadata = {
|
2020-06-05 15:05:43 +08:00
|
|
|
ssh_user = var.ssh_user
|
2021-04-29 20:20:50 +08:00
|
|
|
kubespray_groups = "kube_control_plane,${var.supplementary_master_groups},k8s_cluster"
|
2022-05-03 23:51:56 +08:00
|
|
|
depends_on = var.network_router_id
|
2020-06-05 15:05:43 +08:00
|
|
|
use_access_ip = var.use_access_ip
|
2018-01-05 19:09:04 +08:00
|
|
|
}
|
|
|
|
|
2018-04-30 23:11:07 +08:00
|
|
|
provisioner "local-exec" {
|
2022-03-29 15:07:11 +08:00
|
|
|
command = "sed -e s/USER/${var.ssh_user}/ -e s/BASTION_ADDRESS/${element(concat(var.bastion_fips, var.k8s_master_fips), 0)}/ ${path.module}/ansible_bastion_template.txt > ${var.group_vars_path}/no_floating.yml"
|
2018-04-30 23:11:07 +08:00
|
|
|
}
|
2017-12-05 20:48:47 +08:00
|
|
|
}
|
|
|
|
|
2022-02-03 00:50:22 +08:00
|
|
|
resource "openstack_networking_port_v2" "etcd_port" {
|
|
|
|
count = var.number_of_etcd
|
|
|
|
name = "${var.cluster_name}-etcd-${count.index + 1}"
|
2022-05-03 23:51:56 +08:00
|
|
|
network_id = var.use_existing_network ? data.openstack_networking_network_v2.k8s_network[0].id : var.network_id
|
2022-02-03 00:50:22 +08:00
|
|
|
admin_state_up = "true"
|
2022-05-03 23:51:56 +08:00
|
|
|
port_security_enabled = var.force_null_port_security ? null : var.port_security_enabled
|
2022-02-03 00:50:22 +08:00
|
|
|
security_group_ids = var.port_security_enabled ? local.etcd_sec_groups : null
|
|
|
|
no_security_groups = var.port_security_enabled ? null : false
|
2023-01-05 20:16:00 +08:00
|
|
|
dynamic "fixed_ip" {
|
|
|
|
for_each = var.private_subnet_id == "" ? [] : [true]
|
|
|
|
content {
|
|
|
|
subnet_id = var.private_subnet_id
|
|
|
|
}
|
2022-09-30 15:48:29 +08:00
|
|
|
}
|
2022-05-03 23:51:56 +08:00
|
|
|
|
|
|
|
depends_on = [
|
|
|
|
var.network_router_id
|
|
|
|
]
|
2022-02-03 00:50:22 +08:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:48:47 +08:00
|
|
|
resource "openstack_compute_instance_v2" "etcd" {
|
2020-03-27 20:46:24 +08:00
|
|
|
name = "${var.cluster_name}-etcd-${count.index + 1}"
|
2020-06-05 15:05:43 +08:00
|
|
|
count = var.number_of_etcd
|
|
|
|
availability_zone = element(var.az_list, count.index)
|
2021-02-16 23:05:06 +08:00
|
|
|
image_id = var.etcd_root_volume_size_in_gb == 0 ? local.image_to_use_master : null
|
2020-06-05 15:05:43 +08:00
|
|
|
flavor_id = var.flavor_etcd
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2022-12-07 10:28:38 +08:00
|
|
|
user_data = data.cloudinit_config.cloudinit.rendered
|
2020-03-27 20:46:24 +08:00
|
|
|
|
2020-02-24 17:20:49 +08:00
|
|
|
dynamic "block_device" {
|
2021-02-16 23:05:06 +08:00
|
|
|
for_each = var.etcd_root_volume_size_in_gb > 0 ? [local.image_to_use_master] : []
|
2019-12-09 17:15:10 +08:00
|
|
|
content {
|
2021-02-16 23:05:06 +08:00
|
|
|
uuid = local.image_to_use_master
|
2020-02-24 17:20:49 +08:00
|
|
|
source_type = "image"
|
2020-06-05 15:05:43 +08:00
|
|
|
volume_size = var.etcd_root_volume_size_in_gb
|
2020-02-24 17:20:49 +08:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 20:17:59 +08:00
|
|
|
network {
|
2022-02-03 00:50:22 +08:00
|
|
|
port = element(openstack_networking_port_v2.etcd_port.*.id, count.index)
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
|
2019-12-09 17:15:10 +08:00
|
|
|
dynamic "scheduler_hints" {
|
2022-05-14 05:09:56 +08:00
|
|
|
for_each = var.etcd_server_group_policy != "" ? [openstack_compute_servergroup_v2.k8s_etcd[0]] : []
|
2019-12-09 17:15:10 +08:00
|
|
|
content {
|
2020-06-05 15:05:43 +08:00
|
|
|
group = openstack_compute_servergroup_v2.k8s_etcd[0].id
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 20:17:59 +08:00
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 15:05:43 +08:00
|
|
|
ssh_user = var.ssh_user
|
2021-04-29 20:20:50 +08:00
|
|
|
kubespray_groups = "etcd,no_floating"
|
2022-05-03 23:51:56 +08:00
|
|
|
depends_on = var.network_router_id
|
2020-06-05 15:05:43 +08:00
|
|
|
use_access_ip = var.use_access_ip
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-03 00:50:22 +08:00
|
|
|
resource "openstack_networking_port_v2" "k8s_master_no_floating_ip_port" {
|
|
|
|
count = var.number_of_k8s_masters_no_floating_ip
|
|
|
|
name = "${var.cluster_name}-k8s-master-nf-${count.index + 1}"
|
2022-05-03 23:51:56 +08:00
|
|
|
network_id = var.use_existing_network ? data.openstack_networking_network_v2.k8s_network[0].id : var.network_id
|
2022-02-03 00:50:22 +08:00
|
|
|
admin_state_up = "true"
|
2022-05-03 23:51:56 +08:00
|
|
|
port_security_enabled = var.force_null_port_security ? null : var.port_security_enabled
|
2022-02-03 00:50:22 +08:00
|
|
|
security_group_ids = var.port_security_enabled ? local.master_sec_groups : null
|
|
|
|
no_security_groups = var.port_security_enabled ? null : false
|
2023-01-05 20:16:00 +08:00
|
|
|
dynamic "fixed_ip" {
|
|
|
|
for_each = var.private_subnet_id == "" ? [] : [true]
|
|
|
|
content {
|
|
|
|
subnet_id = var.private_subnet_id
|
|
|
|
}
|
2022-09-30 15:48:29 +08:00
|
|
|
}
|
2022-05-03 23:51:56 +08:00
|
|
|
|
|
|
|
depends_on = [
|
|
|
|
var.network_router_id
|
|
|
|
]
|
2022-02-03 00:50:22 +08:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:48:47 +08:00
|
|
|
resource "openstack_compute_instance_v2" "k8s_master_no_floating_ip" {
|
2020-03-27 20:46:24 +08:00
|
|
|
name = "${var.cluster_name}-k8s-master-nf-${count.index + 1}"
|
2020-06-05 15:05:43 +08:00
|
|
|
count = var.number_of_k8s_masters_no_floating_ip
|
|
|
|
availability_zone = element(var.az_list, count.index)
|
2021-02-16 23:05:06 +08:00
|
|
|
image_id = var.master_root_volume_size_in_gb == 0 ? local.image_to_use_master : null
|
2020-06-05 15:05:43 +08:00
|
|
|
flavor_id = var.flavor_k8s_master
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2019-09-25 20:17:59 +08:00
|
|
|
|
2020-02-24 17:20:49 +08:00
|
|
|
dynamic "block_device" {
|
2021-02-16 23:05:06 +08:00
|
|
|
for_each = var.master_root_volume_size_in_gb > 0 ? [local.image_to_use_master] : []
|
2019-12-09 17:15:10 +08:00
|
|
|
content {
|
2021-02-16 23:05:06 +08:00
|
|
|
uuid = local.image_to_use_master
|
2020-02-24 17:20:49 +08:00
|
|
|
source_type = "image"
|
2020-06-05 15:05:43 +08:00
|
|
|
volume_size = var.master_root_volume_size_in_gb
|
2020-08-18 15:49:29 +08:00
|
|
|
volume_type = var.master_volume_type
|
2020-02-24 17:20:49 +08:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 20:17:59 +08:00
|
|
|
|
2018-01-05 19:09:04 +08:00
|
|
|
network {
|
2022-02-03 00:50:22 +08:00
|
|
|
port = element(openstack_networking_port_v2.k8s_master_no_floating_ip_port.*.id, count.index)
|
2018-01-05 19:09:04 +08:00
|
|
|
}
|
|
|
|
|
2019-12-09 17:15:10 +08:00
|
|
|
dynamic "scheduler_hints" {
|
2021-11-22 18:53:09 +08:00
|
|
|
for_each = var.master_server_group_policy != "" ? [openstack_compute_servergroup_v2.k8s_master[0]] : []
|
2019-12-09 17:15:10 +08:00
|
|
|
content {
|
2020-06-05 15:05:43 +08:00
|
|
|
group = openstack_compute_servergroup_v2.k8s_master[0].id
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
}
|
2018-01-05 19:09:04 +08:00
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 15:05:43 +08:00
|
|
|
ssh_user = var.ssh_user
|
2021-04-29 20:20:50 +08:00
|
|
|
kubespray_groups = "etcd,kube_control_plane,${var.supplementary_master_groups},k8s_cluster,no_floating"
|
2022-05-03 23:51:56 +08:00
|
|
|
depends_on = var.network_router_id
|
2020-06-05 15:05:43 +08:00
|
|
|
use_access_ip = var.use_access_ip
|
2018-01-05 19:09:04 +08:00
|
|
|
}
|
2017-12-05 20:48:47 +08:00
|
|
|
}
|
|
|
|
|
2022-02-03 00:50:22 +08:00
|
|
|
resource "openstack_networking_port_v2" "k8s_master_no_floating_ip_no_etcd_port" {
|
|
|
|
count = var.number_of_k8s_masters_no_floating_ip_no_etcd
|
|
|
|
name = "${var.cluster_name}-k8s-master-ne-nf-${count.index + 1}"
|
2022-05-03 23:51:56 +08:00
|
|
|
network_id = var.use_existing_network ? data.openstack_networking_network_v2.k8s_network[0].id : var.network_id
|
2022-02-03 00:50:22 +08:00
|
|
|
admin_state_up = "true"
|
2022-05-03 23:51:56 +08:00
|
|
|
port_security_enabled = var.force_null_port_security ? null : var.port_security_enabled
|
2022-02-03 00:50:22 +08:00
|
|
|
security_group_ids = var.port_security_enabled ? local.master_sec_groups : null
|
|
|
|
no_security_groups = var.port_security_enabled ? null : false
|
2023-01-05 20:16:00 +08:00
|
|
|
dynamic "fixed_ip" {
|
|
|
|
for_each = var.private_subnet_id == "" ? [] : [true]
|
|
|
|
content {
|
|
|
|
subnet_id = var.private_subnet_id
|
|
|
|
}
|
2022-09-30 15:48:29 +08:00
|
|
|
}
|
2022-05-03 23:51:56 +08:00
|
|
|
|
|
|
|
depends_on = [
|
|
|
|
var.network_router_id
|
|
|
|
]
|
2022-02-03 00:50:22 +08:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:48:47 +08:00
|
|
|
resource "openstack_compute_instance_v2" "k8s_master_no_floating_ip_no_etcd" {
|
2020-03-27 20:46:24 +08:00
|
|
|
name = "${var.cluster_name}-k8s-master-ne-nf-${count.index + 1}"
|
2020-06-05 15:05:43 +08:00
|
|
|
count = var.number_of_k8s_masters_no_floating_ip_no_etcd
|
|
|
|
availability_zone = element(var.az_list, count.index)
|
2021-02-16 23:05:06 +08:00
|
|
|
image_id = var.master_root_volume_size_in_gb == 0 ? local.image_to_use_master : null
|
2020-06-05 15:05:43 +08:00
|
|
|
flavor_id = var.flavor_k8s_master
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2022-12-07 10:28:38 +08:00
|
|
|
user_data = data.cloudinit_config.cloudinit.rendered
|
2018-01-05 19:09:04 +08:00
|
|
|
|
2020-02-24 17:20:49 +08:00
|
|
|
dynamic "block_device" {
|
2021-02-16 23:05:06 +08:00
|
|
|
for_each = var.master_root_volume_size_in_gb > 0 ? [local.image_to_use_master] : []
|
2019-12-09 17:15:10 +08:00
|
|
|
content {
|
2021-02-16 23:05:06 +08:00
|
|
|
uuid = local.image_to_use_master
|
2020-02-24 17:20:49 +08:00
|
|
|
source_type = "image"
|
2020-06-05 15:05:43 +08:00
|
|
|
volume_size = var.master_root_volume_size_in_gb
|
2020-08-18 15:49:29 +08:00
|
|
|
volume_type = var.master_volume_type
|
2020-02-24 17:20:49 +08:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
}
|
2017-12-05 20:48:47 +08:00
|
|
|
|
2019-09-25 20:17:59 +08:00
|
|
|
network {
|
2022-02-03 00:50:22 +08:00
|
|
|
port = element(openstack_networking_port_v2.k8s_master_no_floating_ip_no_etcd_port.*.id, count.index)
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
|
2019-12-09 17:15:10 +08:00
|
|
|
dynamic "scheduler_hints" {
|
2021-11-22 18:53:09 +08:00
|
|
|
for_each = var.master_server_group_policy != "" ? [openstack_compute_servergroup_v2.k8s_master[0]] : []
|
2019-12-09 17:15:10 +08:00
|
|
|
content {
|
2020-06-05 15:05:43 +08:00
|
|
|
group = openstack_compute_servergroup_v2.k8s_master[0].id
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 20:17:59 +08:00
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 15:05:43 +08:00
|
|
|
ssh_user = var.ssh_user
|
2021-04-29 20:20:50 +08:00
|
|
|
kubespray_groups = "kube_control_plane,${var.supplementary_master_groups},k8s_cluster,no_floating"
|
2022-05-03 23:51:56 +08:00
|
|
|
depends_on = var.network_router_id
|
2020-06-05 15:05:43 +08:00
|
|
|
use_access_ip = var.use_access_ip
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-03 00:50:22 +08:00
|
|
|
resource "openstack_networking_port_v2" "k8s_node_port" {
|
|
|
|
count = var.number_of_k8s_nodes
|
|
|
|
name = "${var.cluster_name}-k8s-node-${count.index + 1}"
|
2022-05-03 23:51:56 +08:00
|
|
|
network_id = var.use_existing_network ? data.openstack_networking_network_v2.k8s_network[0].id : var.network_id
|
2022-02-03 00:50:22 +08:00
|
|
|
admin_state_up = "true"
|
2022-05-03 23:51:56 +08:00
|
|
|
port_security_enabled = var.force_null_port_security ? null : var.port_security_enabled
|
2022-02-03 00:50:22 +08:00
|
|
|
security_group_ids = var.port_security_enabled ? local.worker_sec_groups : null
|
|
|
|
no_security_groups = var.port_security_enabled ? null : false
|
2023-01-05 20:16:00 +08:00
|
|
|
dynamic "fixed_ip" {
|
|
|
|
for_each = var.private_subnet_id == "" ? [] : [true]
|
|
|
|
content {
|
|
|
|
subnet_id = var.private_subnet_id
|
|
|
|
}
|
2022-09-30 15:48:29 +08:00
|
|
|
}
|
2022-05-03 23:51:56 +08:00
|
|
|
|
|
|
|
depends_on = [
|
|
|
|
var.network_router_id
|
|
|
|
]
|
2022-02-03 00:50:22 +08:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:48:47 +08:00
|
|
|
resource "openstack_compute_instance_v2" "k8s_node" {
|
2020-03-27 20:46:24 +08:00
|
|
|
name = "${var.cluster_name}-k8s-node-${count.index + 1}"
|
2020-06-05 15:05:43 +08:00
|
|
|
count = var.number_of_k8s_nodes
|
|
|
|
availability_zone = element(var.az_list_node, count.index)
|
2021-02-16 23:05:06 +08:00
|
|
|
image_id = var.node_root_volume_size_in_gb == 0 ? local.image_to_use_node : null
|
2020-06-05 15:05:43 +08:00
|
|
|
flavor_id = var.flavor_k8s_node
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2022-12-07 10:28:38 +08:00
|
|
|
user_data = data.cloudinit_config.cloudinit.rendered
|
2018-01-05 19:09:04 +08:00
|
|
|
|
2020-02-24 17:20:49 +08:00
|
|
|
dynamic "block_device" {
|
2021-02-16 23:05:06 +08:00
|
|
|
for_each = var.node_root_volume_size_in_gb > 0 ? [local.image_to_use_node] : []
|
2019-12-09 17:15:10 +08:00
|
|
|
content {
|
2021-02-16 23:05:06 +08:00
|
|
|
uuid = local.image_to_use_node
|
2020-02-24 17:20:49 +08:00
|
|
|
source_type = "image"
|
2020-06-05 15:05:43 +08:00
|
|
|
volume_size = var.node_root_volume_size_in_gb
|
2021-12-01 04:59:01 +08:00
|
|
|
volume_type = var.node_volume_type
|
2020-02-24 17:20:49 +08:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 20:17:59 +08:00
|
|
|
network {
|
2022-02-03 00:50:22 +08:00
|
|
|
port = element(openstack_networking_port_v2.k8s_node_port.*.id, count.index)
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
|
2020-02-24 17:20:49 +08:00
|
|
|
|
2019-12-09 17:15:10 +08:00
|
|
|
dynamic "scheduler_hints" {
|
2021-11-22 18:53:09 +08:00
|
|
|
for_each = var.node_server_group_policy != "" ? [openstack_compute_servergroup_v2.k8s_node[0]] : []
|
2019-12-09 17:15:10 +08:00
|
|
|
content {
|
2020-06-05 15:05:43 +08:00
|
|
|
group = openstack_compute_servergroup_v2.k8s_node[0].id
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 20:17:59 +08:00
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 15:05:43 +08:00
|
|
|
ssh_user = var.ssh_user
|
2021-04-29 20:20:50 +08:00
|
|
|
kubespray_groups = "kube_node,k8s_cluster,${var.supplementary_node_groups}"
|
2022-05-03 23:51:56 +08:00
|
|
|
depends_on = var.network_router_id
|
2020-06-05 15:05:43 +08:00
|
|
|
use_access_ip = var.use_access_ip
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "local-exec" {
|
2022-03-29 15:07:11 +08:00
|
|
|
command = "sed -e s/USER/${var.ssh_user}/ -e s/BASTION_ADDRESS/${element(concat(var.bastion_fips, var.k8s_node_fips), 0)}/ ${path.module}/ansible_bastion_template.txt > ${var.group_vars_path}/no_floating.yml"
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-03 00:50:22 +08:00
|
|
|
resource "openstack_networking_port_v2" "k8s_node_no_floating_ip_port" {
|
|
|
|
count = var.number_of_k8s_nodes_no_floating_ip
|
|
|
|
name = "${var.cluster_name}-k8s-node-nf-${count.index + 1}"
|
2022-05-03 23:51:56 +08:00
|
|
|
network_id = var.use_existing_network ? data.openstack_networking_network_v2.k8s_network[0].id : var.network_id
|
2022-02-03 00:50:22 +08:00
|
|
|
admin_state_up = "true"
|
2022-05-03 23:51:56 +08:00
|
|
|
port_security_enabled = var.force_null_port_security ? null : var.port_security_enabled
|
2022-02-03 00:50:22 +08:00
|
|
|
security_group_ids = var.port_security_enabled ? local.worker_sec_groups : null
|
|
|
|
no_security_groups = var.port_security_enabled ? null : false
|
2023-01-05 20:16:00 +08:00
|
|
|
dynamic "fixed_ip" {
|
|
|
|
for_each = var.private_subnet_id == "" ? [] : [true]
|
|
|
|
content {
|
|
|
|
subnet_id = var.private_subnet_id
|
|
|
|
}
|
2022-09-30 15:48:29 +08:00
|
|
|
}
|
2022-05-03 23:51:56 +08:00
|
|
|
|
|
|
|
depends_on = [
|
|
|
|
var.network_router_id
|
|
|
|
]
|
2022-02-03 00:50:22 +08:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:48:47 +08:00
|
|
|
resource "openstack_compute_instance_v2" "k8s_node_no_floating_ip" {
|
2020-03-27 20:46:24 +08:00
|
|
|
name = "${var.cluster_name}-k8s-node-nf-${count.index + 1}"
|
2020-06-05 15:05:43 +08:00
|
|
|
count = var.number_of_k8s_nodes_no_floating_ip
|
|
|
|
availability_zone = element(var.az_list_node, count.index)
|
2021-02-16 23:05:06 +08:00
|
|
|
image_id = var.node_root_volume_size_in_gb == 0 ? local.image_to_use_node : null
|
2020-06-05 15:05:43 +08:00
|
|
|
flavor_id = var.flavor_k8s_node
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2022-12-07 10:28:38 +08:00
|
|
|
user_data = data.cloudinit_config.cloudinit.rendered
|
2019-09-25 20:17:59 +08:00
|
|
|
|
2020-02-24 17:20:49 +08:00
|
|
|
dynamic "block_device" {
|
2021-02-16 23:05:06 +08:00
|
|
|
for_each = var.node_root_volume_size_in_gb > 0 ? [local.image_to_use_node] : []
|
2020-02-24 17:20:49 +08:00
|
|
|
content {
|
2021-02-16 23:05:06 +08:00
|
|
|
uuid = local.image_to_use_node
|
2020-02-24 17:20:49 +08:00
|
|
|
source_type = "image"
|
2020-06-05 15:05:43 +08:00
|
|
|
volume_size = var.node_root_volume_size_in_gb
|
2021-12-01 04:59:01 +08:00
|
|
|
volume_type = var.node_volume_type
|
2020-02-24 17:20:49 +08:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 20:17:59 +08:00
|
|
|
network {
|
2022-02-03 00:50:22 +08:00
|
|
|
port = element(openstack_networking_port_v2.k8s_node_no_floating_ip_port.*.id, count.index)
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
|
2019-12-09 17:15:10 +08:00
|
|
|
dynamic "scheduler_hints" {
|
2023-01-05 20:16:00 +08:00
|
|
|
for_each = var.node_server_group_policy != "" ? [openstack_compute_servergroup_v2.k8s_node[0].id] : []
|
2019-12-09 17:15:10 +08:00
|
|
|
content {
|
2023-01-05 20:16:00 +08:00
|
|
|
group = scheduler_hints.value
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 20:17:59 +08:00
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 15:05:43 +08:00
|
|
|
ssh_user = var.ssh_user
|
2021-04-29 20:20:50 +08:00
|
|
|
kubespray_groups = "kube_node,k8s_cluster,no_floating,${var.supplementary_node_groups}"
|
2022-05-03 23:51:56 +08:00
|
|
|
depends_on = var.network_router_id
|
2020-06-05 15:05:43 +08:00
|
|
|
use_access_ip = var.use_access_ip
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-03 00:50:22 +08:00
|
|
|
resource "openstack_networking_port_v2" "k8s_nodes_port" {
|
|
|
|
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}"
|
2023-01-05 20:16:00 +08:00
|
|
|
network_id = local.k8s_nodes_settings[each.key].network_id
|
2022-02-03 00:50:22 +08:00
|
|
|
admin_state_up = "true"
|
2022-05-03 23:51:56 +08:00
|
|
|
port_security_enabled = var.force_null_port_security ? null : var.port_security_enabled
|
2022-02-03 00:50:22 +08:00
|
|
|
security_group_ids = var.port_security_enabled ? local.worker_sec_groups : null
|
|
|
|
no_security_groups = var.port_security_enabled ? null : false
|
2023-01-05 20:16:00 +08:00
|
|
|
dynamic "fixed_ip" {
|
|
|
|
for_each = var.private_subnet_id == "" ? [] : [true]
|
|
|
|
content {
|
|
|
|
subnet_id = var.private_subnet_id
|
|
|
|
}
|
2022-09-30 15:48:29 +08:00
|
|
|
}
|
2022-05-03 23:51:56 +08:00
|
|
|
|
|
|
|
depends_on = [
|
|
|
|
var.network_router_id
|
|
|
|
]
|
2022-02-03 00:50:22 +08:00
|
|
|
}
|
|
|
|
|
2020-04-16 22:52:45 +08: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 15:05:43 +08:00
|
|
|
availability_zone = each.value.az
|
2023-01-05 20:16:00 +08:00
|
|
|
image_id = local.k8s_nodes_settings[each.key].use_local_disk ? local.k8s_nodes_settings[each.key].image_id : null
|
2020-06-05 15:05:43 +08:00
|
|
|
flavor_id = each.value.flavor
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2023-01-05 20:16:00 +08:00
|
|
|
user_data = each.value.cloudinit != null ? templatefile("${path.module}/templates/cloudinit.yaml.tmpl", {
|
|
|
|
extra_partitions = each.value.cloudinit.extra_partitions
|
|
|
|
}) : data.cloudinit_config.cloudinit.rendered
|
2020-04-16 22:52:45 +08:00
|
|
|
|
|
|
|
dynamic "block_device" {
|
2023-01-05 20:16:00 +08:00
|
|
|
for_each = !local.k8s_nodes_settings[each.key].use_local_disk ? [local.k8s_nodes_settings[each.key].image_id] : []
|
2020-04-16 22:52:45 +08:00
|
|
|
content {
|
2023-01-05 20:16:00 +08:00
|
|
|
uuid = block_device.value
|
2020-04-16 22:52:45 +08:00
|
|
|
source_type = "image"
|
2023-01-05 20:16:00 +08:00
|
|
|
volume_size = local.k8s_nodes_settings[each.key].volume_size
|
|
|
|
volume_type = local.k8s_nodes_settings[each.key].volume_type
|
2020-04-16 22:52:45 +08:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
network {
|
2022-02-03 00:50:22 +08:00
|
|
|
port = openstack_networking_port_v2.k8s_nodes_port[each.key].id
|
2020-04-16 22:52:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dynamic "scheduler_hints" {
|
2023-01-05 20:16:00 +08:00
|
|
|
for_each = local.k8s_nodes_settings[each.key].server_group
|
2020-04-16 22:52:45 +08:00
|
|
|
content {
|
2023-01-05 20:16:00 +08:00
|
|
|
group = scheduler_hints.value
|
2020-04-16 22:52:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 15:05:43 +08:00
|
|
|
ssh_user = var.ssh_user
|
2023-01-05 20:16:00 +08:00
|
|
|
kubespray_groups = "kube_node,k8s_cluster,%{if each.value.floating_ip == false}no_floating,%{endif}${var.supplementary_node_groups}${each.value.extra_groups != null ? ",${each.value.extra_groups}" : ""}"
|
2022-05-03 23:51:56 +08:00
|
|
|
depends_on = var.network_router_id
|
2020-06-05 15:05:43 +08:00
|
|
|
use_access_ip = var.use_access_ip
|
2020-04-16 22:52:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "local-exec" {
|
2022-03-29 15:07:11 +08:00
|
|
|
command = "%{if each.value.floating_ip}sed -e s/USER/${var.ssh_user}/ -e s/BASTION_ADDRESS/${element(concat(var.bastion_fips, [for key, value in var.k8s_nodes_fips : value.address]), 0)}/ ${path.module}/ansible_bastion_template.txt > ${var.group_vars_path}/no_floating.yml%{else}true%{endif}"
|
2020-04-16 22:52:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-03 00:50:22 +08:00
|
|
|
resource "openstack_networking_port_v2" "glusterfs_node_no_floating_ip_port" {
|
|
|
|
count = var.number_of_gfs_nodes_no_floating_ip
|
|
|
|
name = "${var.cluster_name}-gfs-node-nf-${count.index + 1}"
|
2022-05-03 23:51:56 +08:00
|
|
|
network_id = var.use_existing_network ? data.openstack_networking_network_v2.k8s_network[0].id : var.network_id
|
2022-02-03 00:50:22 +08:00
|
|
|
admin_state_up = "true"
|
2022-05-03 23:51:56 +08:00
|
|
|
port_security_enabled = var.force_null_port_security ? null : var.port_security_enabled
|
|
|
|
security_group_ids = var.port_security_enabled ? local.gfs_sec_groups : null
|
2022-02-03 00:50:22 +08:00
|
|
|
no_security_groups = var.port_security_enabled ? null : false
|
2023-01-05 20:16:00 +08:00
|
|
|
dynamic "fixed_ip" {
|
|
|
|
for_each = var.private_subnet_id == "" ? [] : [true]
|
|
|
|
content {
|
|
|
|
subnet_id = var.private_subnet_id
|
|
|
|
}
|
2022-09-30 15:48:29 +08:00
|
|
|
}
|
2022-05-03 23:51:56 +08:00
|
|
|
|
|
|
|
depends_on = [
|
|
|
|
var.network_router_id
|
|
|
|
]
|
2022-02-03 00:50:22 +08:00
|
|
|
}
|
|
|
|
|
2020-02-24 17:20:49 +08:00
|
|
|
resource "openstack_compute_instance_v2" "glusterfs_node_no_floating_ip" {
|
2020-03-27 20:46:24 +08:00
|
|
|
name = "${var.cluster_name}-gfs-node-nf-${count.index + 1}"
|
2020-06-05 15:05:43 +08:00
|
|
|
count = var.number_of_gfs_nodes_no_floating_ip
|
|
|
|
availability_zone = element(var.az_list, count.index)
|
2021-02-16 23:05:06 +08:00
|
|
|
image_name = var.gfs_root_volume_size_in_gb == 0 ? local.image_to_use_gfs : null
|
2020-06-05 15:05:43 +08:00
|
|
|
flavor_id = var.flavor_gfs_node
|
|
|
|
key_pair = openstack_compute_keypair_v2.k8s.name
|
2018-01-05 19:09:04 +08:00
|
|
|
|
2020-02-24 17:20:49 +08:00
|
|
|
dynamic "block_device" {
|
2021-02-16 23:05:06 +08:00
|
|
|
for_each = var.gfs_root_volume_size_in_gb > 0 ? [local.image_to_use_gfs] : []
|
2020-02-24 17:20:49 +08:00
|
|
|
content {
|
2021-02-16 23:05:06 +08:00
|
|
|
uuid = local.image_to_use_gfs
|
2020-02-24 17:20:49 +08:00
|
|
|
source_type = "image"
|
2020-06-05 15:05:43 +08:00
|
|
|
volume_size = var.gfs_root_volume_size_in_gb
|
2020-02-24 17:20:49 +08:00
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = true
|
|
|
|
}
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
|
2018-01-05 19:09:04 +08:00
|
|
|
network {
|
2022-02-03 00:50:22 +08:00
|
|
|
port = element(openstack_networking_port_v2.glusterfs_node_no_floating_ip_port.*.id, count.index)
|
2018-01-05 19:09:04 +08:00
|
|
|
}
|
|
|
|
|
2019-12-09 17:15:10 +08:00
|
|
|
dynamic "scheduler_hints" {
|
2021-11-22 18:53:09 +08:00
|
|
|
for_each = var.node_server_group_policy != "" ? [openstack_compute_servergroup_v2.k8s_node[0]] : []
|
2019-12-09 17:15:10 +08:00
|
|
|
content {
|
2020-06-05 15:05:43 +08:00
|
|
|
group = openstack_compute_servergroup_v2.k8s_node[0].id
|
2019-12-09 17:15:10 +08:00
|
|
|
}
|
|
|
|
}
|
2018-01-05 19:09:04 +08:00
|
|
|
|
|
|
|
metadata = {
|
2020-06-05 15:05:43 +08:00
|
|
|
ssh_user = var.ssh_user_gfs
|
2021-04-29 20:20:50 +08:00
|
|
|
kubespray_groups = "gfs-cluster,network-storage,no_floating"
|
2022-05-03 23:51:56 +08:00
|
|
|
depends_on = var.network_router_id
|
2020-06-05 15:05:43 +08:00
|
|
|
use_access_ip = var.use_access_ip
|
2018-01-05 19:09:04 +08:00
|
|
|
}
|
2017-12-05 20:48:47 +08:00
|
|
|
}
|
|
|
|
|
2022-02-03 00:50:22 +08:00
|
|
|
resource "openstack_networking_floatingip_associate_v2" "bastion" {
|
2020-06-05 15:05:43 +08:00
|
|
|
count = var.number_of_bastions
|
|
|
|
floating_ip = var.bastion_fips[count.index]
|
2022-02-03 00:50:22 +08:00
|
|
|
port_id = element(openstack_networking_port_v2.bastion_port.*.id, count.index)
|
2017-12-05 20:48:47 +08:00
|
|
|
}
|
|
|
|
|
2019-09-25 20:17:59 +08:00
|
|
|
|
2022-02-03 00:50:22 +08:00
|
|
|
resource "openstack_networking_floatingip_associate_v2" "k8s_master" {
|
2020-06-05 15:05:43 +08:00
|
|
|
count = var.number_of_k8s_masters
|
|
|
|
floating_ip = var.k8s_master_fips[count.index]
|
2022-02-03 00:50:22 +08:00
|
|
|
port_id = element(openstack_networking_port_v2.k8s_master_port.*.id, count.index)
|
2017-12-05 20:48:47 +08:00
|
|
|
}
|
|
|
|
|
2022-05-03 23:51:56 +08:00
|
|
|
resource "openstack_networking_floatingip_associate_v2" "k8s_masters" {
|
|
|
|
for_each = var.number_of_k8s_masters == 0 && var.number_of_k8s_masters_no_etcd == 0 && var.number_of_k8s_masters_no_floating_ip == 0 && var.number_of_k8s_masters_no_floating_ip_no_etcd == 0 ? { for key, value in var.k8s_masters : key => value if value.floating_ip } : {}
|
|
|
|
floating_ip = var.k8s_masters_fips[each.key].address
|
|
|
|
port_id = openstack_networking_port_v2.k8s_masters_port[each.key].id
|
|
|
|
}
|
|
|
|
|
2022-02-03 00:50:22 +08:00
|
|
|
resource "openstack_networking_floatingip_associate_v2" "k8s_master_no_etcd" {
|
|
|
|
count = var.master_root_volume_size_in_gb == 0 ? var.number_of_k8s_masters_no_etcd : 0
|
|
|
|
floating_ip = var.k8s_master_no_etcd_fips[count.index]
|
|
|
|
port_id = element(openstack_networking_port_v2.k8s_master_no_etcd_port.*.id, count.index)
|
2019-04-29 13:58:20 +08:00
|
|
|
}
|
|
|
|
|
2022-02-03 00:50:22 +08:00
|
|
|
resource "openstack_networking_floatingip_associate_v2" "k8s_node" {
|
2020-06-05 15:05:43 +08:00
|
|
|
count = var.node_root_volume_size_in_gb == 0 ? var.number_of_k8s_nodes : 0
|
|
|
|
floating_ip = var.k8s_node_fips[count.index]
|
2022-02-03 00:50:22 +08:00
|
|
|
port_id = element(openstack_networking_port_v2.k8s_node_port.*.id, count.index)
|
2020-04-16 22:52:45 +08:00
|
|
|
}
|
|
|
|
|
2022-02-03 00:50:22 +08:00
|
|
|
resource "openstack_networking_floatingip_associate_v2" "k8s_nodes" {
|
2020-04-16 22:52:45 +08:00
|
|
|
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 15:05:43 +08:00
|
|
|
floating_ip = var.k8s_nodes_fips[each.key].address
|
2022-02-03 00:50:22 +08:00
|
|
|
port_id = openstack_networking_port_v2.k8s_nodes_port[each.key].id
|
2017-12-05 20:48:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_blockstorage_volume_v2" "glusterfs_volume" {
|
2020-03-27 20:46:24 +08:00
|
|
|
name = "${var.cluster_name}-glusterfs_volume-${count.index + 1}"
|
2020-06-05 15:05:43 +08:00
|
|
|
count = var.gfs_root_volume_size_in_gb == 0 ? var.number_of_gfs_nodes_no_floating_ip : 0
|
2019-09-25 20:17:59 +08:00
|
|
|
description = "Non-ephemeral volume for GlusterFS"
|
2020-06-05 15:05:43 +08:00
|
|
|
size = var.gfs_volume_size_in_gb
|
2019-09-25 20:17:59 +08:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:48:47 +08:00
|
|
|
resource "openstack_compute_volume_attach_v2" "glusterfs_volume" {
|
2020-06-05 15:05:43 +08: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 22:52:45 +08:00
|
|
|
}
|