2023-02-27 12:19:52 -05:00
|
|
|
terraform {
|
|
|
|
required_providers {
|
|
|
|
openstack = {
|
|
|
|
source = "terraform-provider-openstack/openstack"
|
2024-02-12 09:25:23 -05:00
|
|
|
version = "1.54.1"
|
2023-02-27 12:19:52 -05:00
|
|
|
}
|
|
|
|
|
2024-02-22 11:39:34 -05:00
|
|
|
stackit = {
|
|
|
|
source = "stackitcloud/stackit"
|
2024-04-26 08:02:35 -04:00
|
|
|
version = "0.16.0"
|
2024-02-22 11:39:34 -05:00
|
|
|
}
|
|
|
|
|
2023-02-27 12:19:52 -05:00
|
|
|
random = {
|
|
|
|
source = "hashicorp/random"
|
2023-12-12 10:00:16 -05:00
|
|
|
version = "3.6.0"
|
2023-02-27 12:19:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
provider "openstack" {
|
|
|
|
cloud = var.cloud
|
|
|
|
}
|
|
|
|
|
2024-02-22 11:39:34 -05:00
|
|
|
provider "stackit" {
|
|
|
|
region = "eu01"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-03 04:10:36 -05:00
|
|
|
data "openstack_identity_auth_scope_v3" "scope" {
|
|
|
|
name = "scope"
|
|
|
|
}
|
|
|
|
|
2023-02-27 12:19:52 -05:00
|
|
|
locals {
|
|
|
|
uid = random_id.uid.hex
|
|
|
|
name = "${var.name}-${local.uid}"
|
2023-12-15 04:36:58 -05:00
|
|
|
init_secret_hash = random_password.init_secret.bcrypt_hash
|
2023-02-27 12:19:52 -05:00
|
|
|
ports_node_range_start = "30000"
|
|
|
|
ports_node_range_end = "32767"
|
2024-02-22 11:39:34 -05:00
|
|
|
control_plane_named_ports = flatten([
|
|
|
|
{ name = "kubernetes", port = "6443", health_check = "HTTPS" },
|
|
|
|
{ name = "bootstrapper", port = "9000", health_check = "TCP" },
|
|
|
|
{ name = "verify", port = "30081", health_check = "TCP" },
|
|
|
|
{ name = "recovery", port = "9999", health_check = "TCP" },
|
|
|
|
{ name = "join", port = "30090", health_check = "TCP" },
|
|
|
|
var.debug ? [{ name = "debugd", port = "4000", health_check = "TCP" }] : [],
|
|
|
|
])
|
|
|
|
cidr_vpc_subnet_nodes = "192.168.178.0/24"
|
|
|
|
cidr_vpc_subnet_lbs = "192.168.177.0/24"
|
2024-04-19 05:07:57 -04:00
|
|
|
tags = concat(["constellation-uid-${local.uid}"], var.additional_tags)
|
2023-03-03 04:10:36 -05:00
|
|
|
identity_service = [
|
|
|
|
for entry in data.openstack_identity_auth_scope_v3.scope.service_catalog :
|
|
|
|
entry if entry.type == "identity"
|
|
|
|
][0]
|
|
|
|
identity_endpoint = [
|
|
|
|
for endpoint in local.identity_service.endpoints :
|
2023-03-03 09:28:28 -05:00
|
|
|
endpoint if(endpoint.interface == "public")
|
2023-03-03 04:10:36 -05:00
|
|
|
][0]
|
|
|
|
identity_internal_url = local.identity_endpoint.url
|
2024-03-11 09:20:19 -04:00
|
|
|
cloudsyaml_path = length(var.openstack_clouds_yaml_path) > 0 ? var.openstack_clouds_yaml_path : "~/.config/openstack/clouds.yaml"
|
|
|
|
cloudsyaml = yamldecode(file(pathexpand(local.cloudsyaml_path)))
|
|
|
|
cloudyaml = local.cloudsyaml.clouds[var.cloud]
|
2023-02-27 12:19:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "random_id" "uid" {
|
|
|
|
byte_length = 4
|
|
|
|
}
|
|
|
|
|
2023-12-15 04:36:58 -05:00
|
|
|
resource "random_password" "init_secret" {
|
2023-02-27 12:19:52 -05:00
|
|
|
length = 32
|
|
|
|
special = true
|
|
|
|
override_special = "_%@"
|
|
|
|
}
|
|
|
|
|
|
|
|
data "openstack_networking_network_v2" "floating_ip_pool" {
|
|
|
|
network_id = var.floating_ip_pool_id
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_networking_network_v2" "vpc_network" {
|
|
|
|
name = local.name
|
|
|
|
description = "Constellation VPC network"
|
|
|
|
tags = local.tags
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_networking_subnet_v2" "vpc_subnetwork" {
|
|
|
|
name = local.name
|
|
|
|
description = "Constellation VPC subnetwork"
|
|
|
|
network_id = openstack_networking_network_v2.vpc_network.id
|
|
|
|
cidr = local.cidr_vpc_subnet_nodes
|
|
|
|
dns_nameservers = [
|
|
|
|
"1.1.1.1",
|
|
|
|
"8.8.8.8",
|
|
|
|
"9.9.9.9",
|
|
|
|
]
|
|
|
|
tags = local.tags
|
|
|
|
}
|
|
|
|
|
2024-02-14 10:37:26 -05:00
|
|
|
resource "openstack_networking_subnet_v2" "lb_subnetwork" {
|
|
|
|
name = "${var.name}-${local.uid}-lb"
|
|
|
|
description = "Constellation LB subnetwork"
|
|
|
|
network_id = openstack_networking_network_v2.vpc_network.id
|
|
|
|
cidr = local.cidr_vpc_subnet_lbs
|
|
|
|
dns_nameservers = [
|
|
|
|
"1.1.1.1",
|
|
|
|
"8.8.8.8",
|
|
|
|
"9.9.9.9",
|
|
|
|
]
|
|
|
|
tags = local.tags
|
|
|
|
}
|
|
|
|
|
2023-02-27 12:19:52 -05:00
|
|
|
resource "openstack_networking_router_v2" "vpc_router" {
|
|
|
|
name = local.name
|
|
|
|
external_network_id = data.openstack_networking_network_v2.floating_ip_pool.network_id
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_networking_router_interface_v2" "vpc_router_interface" {
|
|
|
|
router_id = openstack_networking_router_v2.vpc_router.id
|
|
|
|
subnet_id = openstack_networking_subnet_v2.vpc_subnetwork.id
|
|
|
|
}
|
|
|
|
|
2024-02-14 10:37:26 -05:00
|
|
|
resource "openstack_networking_router_interface_v2" "lbs_router_interface_lbs" {
|
|
|
|
router_id = openstack_networking_router_v2.vpc_router.id
|
|
|
|
subnet_id = openstack_networking_subnet_v2.lb_subnetwork.id
|
|
|
|
}
|
|
|
|
|
2024-02-12 09:25:23 -05:00
|
|
|
resource "openstack_networking_secgroup_v2" "vpc_secgroup" {
|
2023-02-27 12:19:52 -05:00
|
|
|
name = local.name
|
|
|
|
description = "Constellation VPC security group"
|
2024-02-12 09:25:23 -05:00
|
|
|
}
|
2023-02-27 12:19:52 -05:00
|
|
|
|
2024-02-12 09:25:23 -05:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "icmp_in" {
|
|
|
|
description = "icmp ingress"
|
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = "icmp"
|
|
|
|
port_range_min = 0
|
|
|
|
port_range_max = 0
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.vpc_secgroup.id
|
|
|
|
}
|
2023-02-27 12:19:52 -05:00
|
|
|
|
2024-02-12 09:25:23 -05:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "icmp_out" {
|
|
|
|
description = "icmp egress"
|
|
|
|
direction = "egress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = "icmp"
|
|
|
|
port_range_min = 0
|
|
|
|
port_range_max = 0
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.vpc_secgroup.id
|
|
|
|
}
|
2023-04-05 10:49:03 -04:00
|
|
|
|
2024-02-12 09:25:23 -05:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "tcp_out" {
|
|
|
|
description = "tcp egress"
|
|
|
|
direction = "egress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = "tcp"
|
|
|
|
port_range_min = 0
|
|
|
|
port_range_max = 0
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.vpc_secgroup.id
|
|
|
|
}
|
2023-04-05 10:49:03 -04:00
|
|
|
|
2024-02-12 09:25:23 -05:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "udp_out" {
|
|
|
|
description = "udp egress"
|
|
|
|
direction = "egress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = "udp"
|
|
|
|
port_range_min = 0
|
|
|
|
port_range_max = 0
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.vpc_secgroup.id
|
|
|
|
}
|
2023-02-27 12:19:52 -05:00
|
|
|
|
2024-02-12 09:25:23 -05:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "tcp_between_nodes" {
|
|
|
|
description = "tcp between nodes"
|
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = "tcp"
|
|
|
|
port_range_min = 0
|
|
|
|
port_range_max = 0
|
|
|
|
remote_ip_prefix = local.cidr_vpc_subnet_nodes
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.vpc_secgroup.id
|
|
|
|
}
|
2023-04-05 10:49:03 -04:00
|
|
|
|
2024-02-12 09:25:23 -05:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "udp_between_nodes" {
|
|
|
|
description = "udp between nodes"
|
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = "udp"
|
|
|
|
port_range_min = 0
|
|
|
|
port_range_max = 0
|
|
|
|
remote_ip_prefix = local.cidr_vpc_subnet_nodes
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.vpc_secgroup.id
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_networking_secgroup_rule_v2" "nodeport_tcp" {
|
|
|
|
description = "nodeport tcp"
|
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = "tcp"
|
|
|
|
port_range_min = local.ports_node_range_start
|
|
|
|
port_range_max = local.ports_node_range_end
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.vpc_secgroup.id
|
2023-02-27 12:19:52 -05:00
|
|
|
}
|
|
|
|
|
2024-02-12 09:25:23 -05:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "nodeport_udp" {
|
|
|
|
description = "nodeport udp"
|
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = "udp"
|
|
|
|
port_range_min = local.ports_node_range_start
|
|
|
|
port_range_max = local.ports_node_range_end
|
|
|
|
security_group_id = openstack_networking_secgroup_v2.vpc_secgroup.id
|
|
|
|
}
|
|
|
|
|
2024-02-22 11:39:34 -05:00
|
|
|
resource "openstack_networking_secgroup_rule_v2" "tcp_ingress" {
|
|
|
|
for_each = { for item in local.control_plane_named_ports : item.name => item }
|
2024-02-12 09:25:23 -05:00
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = "tcp"
|
2024-02-22 11:39:34 -05:00
|
|
|
port_range_min = each.value.port
|
|
|
|
port_range_max = each.value.port
|
2024-02-12 09:25:23 -05:00
|
|
|
security_group_id = openstack_networking_secgroup_v2.vpc_secgroup.id
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-03 10:33:00 -04:00
|
|
|
module "instance_group" {
|
2024-02-22 11:39:34 -05:00
|
|
|
source = "./modules/instance_group"
|
|
|
|
for_each = var.node_groups
|
|
|
|
base_name = local.name
|
|
|
|
node_group_name = each.key
|
|
|
|
role = each.value.role
|
|
|
|
initial_count = each.value.initial_count
|
|
|
|
disk_size = each.value.state_disk_size
|
|
|
|
state_disk_type = each.value.state_disk_type
|
|
|
|
availability_zone = each.value.zone
|
|
|
|
image_id = var.image_id
|
|
|
|
flavor_id = each.value.flavor_id
|
|
|
|
security_groups = [openstack_networking_secgroup_v2.vpc_secgroup.id]
|
|
|
|
tags = local.tags
|
|
|
|
uid = local.uid
|
|
|
|
network_id = openstack_networking_network_v2.vpc_network.id
|
|
|
|
subnet_id = openstack_networking_subnet_v2.vpc_subnetwork.id
|
|
|
|
init_secret_hash = local.init_secret_hash
|
|
|
|
identity_internal_url = local.identity_internal_url
|
2024-03-11 09:20:19 -04:00
|
|
|
openstack_username = local.cloudyaml["auth"]["username"]
|
|
|
|
openstack_password = local.cloudyaml["auth"]["password"]
|
|
|
|
openstack_user_domain_name = local.cloudyaml["auth"]["user_domain_name"]
|
2024-02-22 11:39:34 -05:00
|
|
|
openstack_load_balancer_endpoint = openstack_networking_floatingip_v2.public_ip.address
|
2023-02-27 12:19:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_networking_floatingip_v2" "public_ip" {
|
|
|
|
pool = data.openstack_networking_network_v2.floating_ip_pool.name
|
|
|
|
description = "Public ip for first control plane node"
|
|
|
|
tags = local.tags
|
|
|
|
}
|
|
|
|
|
2024-02-14 10:37:26 -05:00
|
|
|
resource "openstack_networking_floatingip_associate_v2" "public_ip_associate" {
|
2024-02-22 11:39:34 -05:00
|
|
|
count = var.cloud == "stackit" ? 0 : 1
|
2023-02-27 12:19:52 -05:00
|
|
|
floating_ip = openstack_networking_floatingip_v2.public_ip.address
|
2024-02-14 10:37:26 -05:00
|
|
|
port_id = module.instance_group["control_plane_default"].port_ids.0
|
2023-02-27 12:19:52 -05:00
|
|
|
depends_on = [
|
|
|
|
openstack_networking_router_v2.vpc_router,
|
|
|
|
openstack_networking_router_interface_v2.vpc_router_interface,
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2024-02-22 11:39:34 -05:00
|
|
|
module "stackit_loadbalancer" {
|
|
|
|
count = var.cloud == "stackit" ? 1 : 0
|
|
|
|
source = "./modules/stackit_loadbalancer"
|
|
|
|
name = local.name
|
|
|
|
stackit_project_id = var.stackit_project_id
|
|
|
|
member_ips = module.instance_group["control_plane_default"].ips
|
|
|
|
network_id = openstack_networking_network_v2.vpc_network.id
|
|
|
|
external_address = openstack_networking_floatingip_v2.public_ip.address
|
|
|
|
ports = {
|
|
|
|
for port in local.control_plane_named_ports : port.name => port.port
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-03 10:33:00 -04:00
|
|
|
moved {
|
|
|
|
from = module.instance_group_control_plane
|
|
|
|
to = module.instance_group["control_plane_default"]
|
|
|
|
}
|
2023-02-27 12:19:52 -05:00
|
|
|
|
2023-07-03 10:33:00 -04:00
|
|
|
moved {
|
|
|
|
from = module.instance_group_worker
|
|
|
|
to = module.instance_group["worker_default"]
|
|
|
|
}
|
|
|
|
|
|
|
|
# TODO(malt3): get LoadBalancer API enabled in the test environment
|
2023-02-27 12:19:52 -05:00
|
|
|
# resource "openstack_lb_loadbalancer_v2" "loadbalancer" {
|
|
|
|
# name = local.name
|
|
|
|
# description = "Constellation load balancer"
|
|
|
|
# vip_subnet_id = openstack_networking_subnet_v2.vpc_subnetwork.id
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
|
|
# resource "openstack_networking_floatingip_v2" "loadbalancer_ip" {
|
|
|
|
# pool = data.openstack_networking_network_v2.floating_ip_pool.name
|
|
|
|
# description = "Loadbalancer ip for ${local.name}"
|
|
|
|
# tags = local.tags
|
|
|
|
# }
|
|
|
|
|
|
|
|
# module "loadbalancer_kube" {
|
|
|
|
# source = "./modules/loadbalancer"
|
|
|
|
# name = "${local.name}-kube"
|
|
|
|
# member_ips = module.instance_group_control_plane.ips.value
|
|
|
|
# loadbalancer_id = openstack_lb_loadbalancer_v2.loadbalancer.id
|
|
|
|
# subnet_id = openstack_networking_subnet_v2.vpc_subnetwork.id
|
|
|
|
# port = local.ports_kubernetes
|
|
|
|
# }
|
|
|
|
|
|
|
|
# module "loadbalancer_boot" {
|
|
|
|
# source = "./modules/loadbalancer"
|
|
|
|
# name = "${local.name}-boot"
|
|
|
|
# member_ips = module.instance_group_control_plane.ips
|
|
|
|
# loadbalancer_id = openstack_lb_loadbalancer_v2.loadbalancer.id
|
|
|
|
# subnet_id = openstack_networking_subnet_v2.vpc_subnetwork.id
|
|
|
|
# port = local.ports_bootstrapper
|
|
|
|
# }
|
|
|
|
|
|
|
|
# module "loadbalancer_verify" {
|
|
|
|
# source = "./modules/loadbalancer"
|
|
|
|
# name = "${local.name}-verify"
|
|
|
|
# member_ips = module.instance_group_control_plane.ips
|
|
|
|
# loadbalancer_id = openstack_lb_loadbalancer_v2.loadbalancer.id
|
|
|
|
# subnet_id = openstack_networking_subnet_v2.vpc_subnetwork.id
|
|
|
|
# port = local.ports_verify
|
|
|
|
# }
|
|
|
|
|
|
|
|
# module "loadbalancer_konnectivity" {
|
|
|
|
# source = "./modules/loadbalancer"
|
|
|
|
# name = "${local.name}-konnectivity"
|
|
|
|
# member_ips = module.instance_group_control_plane.ips
|
|
|
|
# loadbalancer_id = openstack_lb_loadbalancer_v2.loadbalancer.id
|
|
|
|
# subnet_id = openstack_networking_subnet_v2.vpc_subnetwork.id
|
|
|
|
# port = local.ports_konnectivity
|
|
|
|
# }
|
|
|
|
|
|
|
|
# module "loadbalancer_recovery" {
|
|
|
|
# source = "./modules/loadbalancer"
|
|
|
|
# name = "${local.name}-recovery"
|
|
|
|
# member_ips = module.instance_group_control_plane.ips
|
|
|
|
# loadbalancer_id = openstack_lb_loadbalancer_v2.loadbalancer.id
|
|
|
|
# subnet_id = openstack_networking_subnet_v2.vpc_subnetwork.id
|
|
|
|
# port = local.ports_recovery
|
|
|
|
# }
|
|
|
|
|
|
|
|
# module "loadbalancer_debugd" {
|
|
|
|
# count = var.debug ? 1 : 0 // only deploy debugd in debug mode
|
|
|
|
# source = "./modules/loadbalancer"
|
|
|
|
# name = "${local.name}-debugd"
|
|
|
|
# member_ips = module.instance_group_control_plane.ips
|
|
|
|
# loadbalancer_id = openstack_lb_loadbalancer_v2.loadbalancer.id
|
|
|
|
# subnet_id = openstack_networking_subnet_v2.vpc_subnetwork.id
|
|
|
|
# port = local.ports_debugd
|
|
|
|
# }
|