infrastructure-as-code/openstack-tf/modules/timescaledb/timescaledb.tf

94 lines
3.1 KiB
HCL

# TimeScaleDB shared server
# Network
resource "openstack_networking_network_v2" "timescaledb_net" {
name = var.timescaledb_server_data.network_name
admin_state_up = "true"
external = "false"
description = var.timescaledb_server_data.network_description
dns_domain = var.dns_zone.zone_name
mtu = var.mtu_size
port_security_enabled = true
shared = false
region = var.main_region
}
# Subnet
resource "openstack_networking_subnet_v2" "timescaledb_subnet" {
name = "timescaledb-subnet"
description = "subnet used to connect to the shared TimeScaleDB service"
network_id = openstack_networking_network_v2.timescaledb_net.id
cidr = var.timescaledb_server_data.network_cidr
dns_nameservers = var.resolvers_ip
ip_version = 4
enable_dhcp = true
no_gateway = true
allocation_pool {
start = var.timescaledb_server_data.allocation_pool_start
end = var.timescaledb_server_data.allocation_pool_end
}
}
# Security group
resource "openstack_networking_secgroup_v2" "timescaledb_access" {
name = "access_to_the_timescaledb_service"
delete_default_rules = "true"
description = "Access the shared TimeScaleDB service using the dedicated network"
}
resource "openstack_networking_secgroup_rule_v2" "timescaledb_access_from_dedicated_subnet" {
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_server_data.network_cidr
}
resource "openstack_compute_servergroup_v2" "timescaledb_cluster" {
name = "timescaledb_cluster"
policies = ["soft-anti-affinity"]
}
# Instances with an additional block device
resource "openstack_compute_instance_v2" "timescaledb_server" {
count = var.timescaledb_machines_count
name = var.timescaledb_server_data.name
availability_zone_hints = var.availability_zones_names.availability_zone_no_gpu
flavor_name = var.timescaledb_server_data.flavor
key_pair = var.ssh_key_file.name
security_groups = [var.default_security_group_name,openstack_networking_secgroup_v2.timescaledb_access.name]
scheduler_hints {
group = openstack_compute_servergroup_v2.timescaledb_cluster.id
}
block_device {
uuid = var.ubuntu_2204.uuid
source_type = "image"
volume_size = 10
boot_index = 0
destination_type = "volume"
delete_on_termination = false
}
block_device {
source_type = "blank"
volume_size = var.timescaledb_data.node_data_disk_size
boot_index = -1
destination_type = "volume"
delete_on_termination = false
}
network {
name = var.main_private_network.name
}
network {
name = var.timescaledb_server_data.network_name
fixed_ip_v4 = var.timescaledb_ip.*[count.index]
}
user_data = "${file("${var.ubuntu2204_data_file}")}"
depends_on = [openstack_networking_subnet_v2.timescaledb_subnet]
}