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

103 lines
3.9 KiB
Terraform
Raw Normal View History

#
# 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
dns_domain = data.terraform_remote_state.privnet_dns_router.outputs.dns_zone.zone_name
mtu = module.common_variables.mtu_size
port_security_enabled = true
2023-12-01 17:49:38 +01:00
shared = false
region = module.common_variables.main_region
}
# 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"
network_id = openstack_networking_network_v2.timescaledb_net.id
2023-11-20 18:37:55 +01:00
cidr = var.timescaledb_net.network_cidr
dns_nameservers = module.common_variables.resolvers_ip
2023-12-01 17:49:38 +01:00
ip_version = 4
enable_dhcp = true
no_gateway = true
allocation_pool {
2023-11-20 18:37:55 +01:00
start = var.timescaledb_net.allocation_pool_start
end = var.timescaledb_net.allocation_pool_end
}
}
# 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"
}
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
}
resource "openstack_compute_servergroup_v2" "timescaledb_cluster" {
name = "timescaledb_cluster"
policies = [var.timescaledb_affinity_policy]
}
# 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)
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
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"]
scheduler_hints {
group = openstack_compute_servergroup_v2.timescaledb_cluster.id
}
block_device {
uuid = module.common_variables.ubuntu_2204.uuid
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
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
}
network {
2023-12-01 17:49:38 +01:00
name = var.timescaledb_net.network_name
fixed_ip_v4 = var.timescaledb_ip.* [count.index]
}
user_data = file("${module.common_variables.ubuntu_2204.user_data_file}")
depends_on = [openstack_networking_subnet_v2.timescaledb_subnet]
# 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.
key_pair, user_data, network
]
}
}