2023-12-11 22:15:33 +01:00
|
|
|
#
|
2023-11-17 16:50:33 +01:00
|
|
|
# TimeScaleDB shared server
|
|
|
|
# Network
|
|
|
|
resource "openstack_networking_network_v2" "timescaledb_net" {
|
2023-12-01 17:49:38 +01:00
|
|
|
name = var.timescaledb_net.network_name
|
|
|
|
admin_state_up = "true"
|
|
|
|
external = "false"
|
|
|
|
description = var.timescaledb_net.network_description
|
2023-12-11 22:15:33 +01:00
|
|
|
dns_domain = data.terraform_remote_state.privnet_dns_router.outputs.dns_zone.zone_name
|
|
|
|
mtu = module.common_variables.mtu_size
|
2023-11-17 16:50:33 +01:00
|
|
|
port_security_enabled = true
|
2023-12-01 17:49:38 +01:00
|
|
|
shared = false
|
2023-12-11 22:15:33 +01:00
|
|
|
region = module.common_variables.main_region
|
2023-11-17 16:50:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Subnet
|
|
|
|
resource "openstack_networking_subnet_v2" "timescaledb_subnet" {
|
|
|
|
name = "timescaledb-subnet"
|
2023-12-01 17:49:38 +01:00
|
|
|
description = "subnet used to connect to the shared TimeScaleDB service"
|
2023-11-17 16:50:33 +01:00
|
|
|
network_id = openstack_networking_network_v2.timescaledb_net.id
|
2023-11-20 18:37:55 +01:00
|
|
|
cidr = var.timescaledb_net.network_cidr
|
2023-12-11 22:15:33 +01:00
|
|
|
dns_nameservers = module.common_variables.resolvers_ip
|
2023-12-01 17:49:38 +01:00
|
|
|
ip_version = 4
|
|
|
|
enable_dhcp = true
|
|
|
|
no_gateway = true
|
2023-11-17 16:50:33 +01:00
|
|
|
allocation_pool {
|
2023-11-20 18:37:55 +01:00
|
|
|
start = var.timescaledb_net.allocation_pool_start
|
|
|
|
end = var.timescaledb_net.allocation_pool_end
|
2023-11-17 16:50:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Security group
|
|
|
|
resource "openstack_networking_secgroup_v2" "timescaledb_access" {
|
2023-12-01 17:49:38 +01:00
|
|
|
name = "access_to_the_timescaledb_service"
|
|
|
|
delete_default_rules = "true"
|
|
|
|
description = "Access the shared TimeScaleDB service using the dedicated network"
|
2023-11-17 16:50:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_networking_secgroup_rule_v2" "timescaledb_access_from_dedicated_subnet" {
|
2023-12-01 17:49:38 +01:00
|
|
|
security_group_id = openstack_networking_secgroup_v2.timescaledb_access.id
|
|
|
|
description = "Allow connections to port 5432 from the 192.168.11.0/24 network"
|
|
|
|
direction = "ingress"
|
|
|
|
ethertype = "IPv4"
|
|
|
|
protocol = "tcp"
|
|
|
|
port_range_min = 5432
|
|
|
|
port_range_max = 5432
|
|
|
|
remote_ip_prefix = var.timescaledb_net.network_cidr
|
2023-11-17 16:50:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_servergroup_v2" "timescaledb_cluster" {
|
|
|
|
name = "timescaledb_cluster"
|
2023-12-13 16:55:40 +01:00
|
|
|
policies = [var.timescaledb_affinity_policy]
|
2023-11-17 16:50:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Instances with an additional block device
|
|
|
|
resource "openstack_compute_instance_v2" "timescaledb_server" {
|
2023-12-01 17:49:38 +01:00
|
|
|
count = var.timescaledb_nodes_count
|
2023-12-13 17:17:42 +01:00
|
|
|
name = format("%s-%02d", var.timescaledb_server_data.node_name, count.index + 1)
|
2023-12-11 22:15:33 +01:00
|
|
|
availability_zone_hints = module.common_variables.availability_zones_names.availability_zone_no_gpu
|
2023-12-13 17:17:42 +01:00
|
|
|
image_name = module.common_variables.ubuntu_2204.name
|
2023-12-01 17:49:38 +01:00
|
|
|
flavor_name = var.timescaledb_node_flavor
|
2023-12-11 22:15:33 +01:00
|
|
|
key_pair = module.ssh_settings.ssh_key_name
|
2024-03-05 18:33:26 +01:00
|
|
|
security_groups = [data.terraform_remote_state.privnet_dns_router.outputs.default_security_group_name, openstack_networking_secgroup_v2.timescaledb_access.name,"timescaledb_temporary"]
|
2023-11-17 16:50:33 +01:00
|
|
|
scheduler_hints {
|
|
|
|
group = openstack_compute_servergroup_v2.timescaledb_cluster.id
|
|
|
|
}
|
|
|
|
block_device {
|
2023-12-11 22:15:33 +01:00
|
|
|
uuid = module.common_variables.ubuntu_2204.uuid
|
2023-11-17 16:50:33 +01:00
|
|
|
source_type = "image"
|
|
|
|
volume_size = 10
|
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = false
|
|
|
|
}
|
|
|
|
|
|
|
|
block_device {
|
|
|
|
source_type = "blank"
|
2023-11-20 18:37:55 +01:00
|
|
|
volume_size = var.timescaledb_server_data.node_data_disk_size
|
2023-11-17 16:50:33 +01:00
|
|
|
boot_index = -1
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = false
|
|
|
|
}
|
|
|
|
|
|
|
|
network {
|
2023-12-11 22:30:46 +01:00
|
|
|
name = data.terraform_remote_state.privnet_dns_router.outputs.main_private_network.name
|
2023-11-17 16:50:33 +01:00
|
|
|
}
|
|
|
|
network {
|
2023-12-01 17:49:38 +01:00
|
|
|
name = var.timescaledb_net.network_name
|
|
|
|
fixed_ip_v4 = var.timescaledb_ip.* [count.index]
|
2023-11-17 16:50:33 +01:00
|
|
|
}
|
|
|
|
|
2023-12-11 22:15:33 +01:00
|
|
|
user_data = file("${module.common_variables.ubuntu_2204.user_data_file}")
|
2023-11-17 16:50:33 +01:00
|
|
|
depends_on = [openstack_networking_subnet_v2.timescaledb_subnet]
|
2023-12-14 12:55:20 +01:00
|
|
|
# Do not replace the instance when the ssh key changes
|
|
|
|
lifecycle {
|
|
|
|
ignore_changes = [
|
|
|
|
# Ignore changes to tags, e.g. because a management agent
|
|
|
|
# updates these based on some ruleset managed elsewhere.
|
2023-12-19 14:51:53 +01:00
|
|
|
key_pair, user_data, network
|
2023-12-14 12:55:20 +01:00
|
|
|
]
|
|
|
|
}
|
2023-11-17 16:50:33 +01:00
|
|
|
}
|