Another cleanup. Add the mongodb module.

This commit is contained in:
Andrea Dell'Amico 2023-11-17 16:50:33 +01:00
parent d59195c253
commit 8350b51931
Signed by untrusted user: andrea.dellamico
GPG Key ID: 147ABE6CEB9E20FF
60 changed files with 1794 additions and 180 deletions

View File

@ -1 +0,0 @@
../../common_variables/00-terraform-provider.tf

View File

@ -1 +0,0 @@
../variables/00-variables.tf

View File

@ -1 +0,0 @@
../../common_variables/01-external-network-and-resolvers.tf

View File

@ -1 +0,0 @@
../../common_variables/05-projects-and-users-vars.tf

View File

@ -1 +1 @@
../../docker_swarm_setup/docker-swarm.tf
../../modules/docker_swarm/docker-swarm.tf

View File

@ -0,0 +1,26 @@
# Define required providers
terraform {
required_version = ">= 0.14.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 1.53.0"
}
}
}
data "terraform_remote_state" "privnet_dns_router" {
backend = "local"
config = {
path = "../project-setup/terraform.tfstate"
}
}
# module "variables" {
# source = "../variables"
# }
# module "basic_setup" {
# source = "../../modules/basic_setup"
# }

View File

@ -1 +1 @@
../../docker_swarm_setup/swarm-variables.tf
../../modules/docker_swarm/swarm-variables.tf

View File

@ -0,0 +1 @@
../variables/variables-dev.tf

View File

@ -0,0 +1 @@
../../modules/common_variables/variables.tf

View File

@ -1 +0,0 @@
../variables/00-variables.tf

View File

@ -1 +0,0 @@
../../modules/common_variables/external-network-and-resolvers.tf

View File

@ -1 +0,0 @@
../../modules/common_variables/projects-and-users-vars.tf

View File

@ -0,0 +1 @@
../variables/variables-dev.tf

View File

@ -0,0 +1 @@
../../modules/common_variables/variables.tf

View File

@ -9,8 +9,7 @@ required_version = ">= 0.14.0"
}
}
provider "openstack" {
cloud = "d4s-dev"
# cloud = "ISTI-Cloud"
module "main-network" {
source = "../../modules/main_private_net_and_dns_zone"
}

View File

@ -1,4 +0,0 @@
module "main-network" {
source = "../../modules/main_private_net_and_dns_zone"
}

View File

@ -0,0 +1,5 @@
provider "openstack" {
cloud = "d4s-dev"
# cloud = "ISTI-Cloud"
}

View File

@ -0,0 +1,4 @@
provider "openstack" {
cloud = "d4s-dev"
}

View File

@ -0,0 +1,26 @@
# Define required providers
terraform {
required_version = ">= 0.14.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 1.53.0"
}
}
}
data "terraform_remote_state" "privnet_dns_router" {
backend = "local"
config = {
path = "../project-setup/terraform.tfstate"
}
}
# module "variables" {
# source = "../variables"
# }
# module "orientdb" {
# source = "../../modules/timescaledb"
# }

View File

@ -0,0 +1 @@
../../common_variables/outputs.tf

View File

@ -0,0 +1 @@
../variables/variables-dev.tf

View File

@ -0,0 +1 @@
../../common_variables/variables.tf

View File

@ -29,11 +29,6 @@ variable "main_private_network" {
}
}
variable "main_private_network_id" {
# Set with the correct value after the setup is complete
default = ""
}
variable "main_private_subnet" {
type = map(string)
default = {
@ -46,11 +41,6 @@ variable "main_private_subnet" {
}
}
variable "main_private_subnet_id" {
# Set with the correct value after the setup is complete
default = ""
}
variable "external_router" {
type = map(string)
default = {
@ -60,6 +50,22 @@ variable "external_router" {
}
}
variable "main_haproxy_l7_ip" {
type = list(string)
default = ["10.1.28.50", "10.1.30.241"]
}
variable "octavia_information" {
type = map(string)
default = {
main_lb_name = "lb-dev-l4"
main_lb_description = "Main L4 load balancer for the D4Science DEV"
octavia_flavor = "octavia_amphora-mvcpu-ha"
octavia_flavor_id = "394988b5-6603-4a1e-a939-8e177c6681c7"
main_lb_hostname = "main-lb"
}
}
variable "basic_services_ip" {
type = map(string)
default = {
@ -77,39 +83,3 @@ variable "basic_services_ip" {
octavia_main_cidr = "10.1.28.227/32"
}
}
variable "main_haproxy_l7_ip" {
type = list(string)
default = ["10.1.28.50", "10.1.30.241"]
}
variable "octavia_information" {
type = map(string)
default = {
main_lb_name = "lb-dev-l4"
main_lb_description = "Main L4 load balancer for the D4Science DEV"
octavia_flavor = "octavia_amphora-mvcpu-ha"
octavia_flavor_id = "394988b5-6603-4a1e-a939-8e177c6681c7"
main_lb_hostname = "main-lb"
}
}
variable "default_security_group_name" {
default = "default"
}
variable "resource_registry_addresses" {
type = map(string)
default = {
r1 = "10.1.28.73"
r2 = "10.1.28.157"
}
}
variable "smartexecutor_addresses" {
type = map(string)
default = {
r1 = "10.1.28.73"
r2 = "10.1.28.157"
}
}

View File

@ -1 +0,0 @@
../../common_variables/00-terraform-provider.tf

View File

@ -1 +0,0 @@
../variables/00-variables.tf

View File

@ -1 +0,0 @@
../../common_variables/01-external-network-and-resolvers.tf

View File

@ -1 +0,0 @@
../../common_variables/05-projects-and-users-vars.tf

View File

@ -1 +1 @@
../../docker_swarm_setup/docker-swarm.tf
../../modules/docker_swarm/docker-swarm.tf

View File

@ -1,3 +1,14 @@
# Define required providers
terraform {
required_version = ">= 0.14.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 1.53.0"
}
}
}
provider "openstack" {
cloud = "d4s-production"
}

View File

@ -1 +1 @@
../../docker_swarm_setup/swarm-variables.tf
../../modules/docker_swarm/swarm-variables.tf

View File

@ -0,0 +1 @@
../variables/variables-production.tf

View File

@ -0,0 +1 @@
../../modules/common_variables/variables.tf

View File

@ -0,0 +1,24 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/terraform-provider-openstack/openstack" {
version = "1.53.0"
constraints = "~> 1.53.0"
hashes = [
"h1:ZSJPqrlaHQ3sj7wyJuPSG+NblFZbAA6Y0d3GjSJf3o8=",
"zh:09da7ca98ffd3de7b9ce36c4c13446212a6e763ba1162be71b50f95d453cb68e",
"zh:14041bcbb87312411d88612056ed185650bfd01284b8ea0761ce8105a331708e",
"zh:35bf4c788fdbc17c8e40ebc7b33c7de4b45a2fa2efaa657b10f0e3bd37c9627f",
"zh:46ede8ef4cfa12d654c538afc1e1ec34a1f3e8eb4e986ee23dceae398b7176a6",
"zh:59675734990dab1e8d87997853ea75e8104bba730b3f5a7146ac735540c9d6bf",
"zh:6de52428849806498670e827b54810be7510a2a79449602c1aede4235a0ec036",
"zh:78b2a20601272afceffac8f8ca78a6b647b84196c0dd8dc710fae297f6be15a4",
"zh:7c41ed3a4fac09677e676ecf9f9edd1e38eef449e656cb01a848d2c799c6de8f",
"zh:852800228f4118a4aa6cfaa4468b851247cbed6f037fd204f08de69eb1edc149",
"zh:86d618e7f9a07d978b8bc4b190be350a00de64ec535f9c8f5dfe133542a55483",
"zh:963a9e72b66d8bcf43de9b14a674ae3ca3719ce2f829217f7a65b66fc3773397",
"zh:a8e72ab67795071bda61f99a6de3d2d40122fb51971768fd75e1324abe874ced",
"zh:ce1890cf3af17d569af3bc7673cec0a8f78e6f5d701767593f3d29c551f44848",
"zh:e6f1b96eb684f527a47f71923f268c86a36d7894751b31ee9e726d7502a639cd",
]
}

View File

@ -0,0 +1,26 @@
# Define required providers
terraform {
required_version = ">= 0.14.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 1.53.0"
}
}
}
data "terraform_remote_state" "privnet_dns_router" {
backend = "local"
config = {
path = "../project-setup/terraform.tfstate"
}
}
# module "variables" {
# source = "../variables"
# }
# module "mongodb" {
# source = "../../modules/mongodb"
# }

View File

@ -0,0 +1,20 @@
mongodb_cluster_data = {
count = 4
name = "mongodb-replica"
flavor = "m2.large"
data_disk_size = 10000
image_type_name = "Ubuntu-Focal-20.04"
image_type_uuid = "75c23040-2be7-49e9-8029-a16dc9f755d1"
}
mongodb_ip = [ "10.1.40.22", "10.1.40.23", "10.1.40.24", "10.1.40.25" ]
mongodb_vol_data = {
name = "mongodb-vol"
flavor = "m1.medium"
data_disk_size = 200
image_type_name = "Ubuntu-Focal-20.04"
image_type_uuid = "75c23040-2be7-49e9-8029-a16dc9f755d1"
}
mongodb_vol_ip = "10.1.40.29"

View File

@ -0,0 +1 @@
../../modules/mongodb/mongodb.tf

View File

@ -0,0 +1,3 @@
provider "openstack" {
cloud = "d4s-production"
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
../../modules/mongodb/variables-mongodb.tf

View File

@ -0,0 +1 @@
../variables/variables-production.tf

View File

@ -0,0 +1 @@
../../modules/common_variables/variables.tf

View File

@ -1 +0,0 @@
../../common_variables/00-terraform-provider.tf

View File

@ -1 +0,0 @@
../variables/00-variables.tf

View File

@ -1 +0,0 @@
../../common_variables/01-external-network-and-resolvers.tf

View File

@ -1,3 +1,14 @@
# Define required providers
terraform {
required_version = ">= 0.14.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 1.53.0"
}
}
}
provider "openstack" {
# cloud = "d4s-production"
cloud = "ISTI-Cloud"

View File

@ -0,0 +1 @@
../variables/variables-production.tf

View File

@ -0,0 +1 @@
../../modules/common_variables/variables.tf

View File

@ -18,7 +18,7 @@ variable "dns_zone" {
variable "dns_zone_id" {
# Set with the correct value after the setup is complete
default = ""
default = "74135b34-1a9c-4c01-8cf0-22450a5660c4"
}
variable "main_private_network" {
@ -31,7 +31,7 @@ variable "main_private_network" {
variable "main_private_network_id" {
# Set with the correct value after the setup is complete
default = ""
default = "020df98d-ae72-452a-b376-3b6dc289acac"
}
variable "main_private_subnet" {
@ -48,7 +48,7 @@ variable "main_private_subnet" {
variable "main_private_subnet_id" {
# Set with the correct value after the setup is complete
default = ""
default = "5d7b83ad-e058-4a3a-bfd8-d20ba6d42e1a"
}
variable "external_router" {
@ -95,3 +95,4 @@ variable "octavia_information" {
main_lb_hostname = "main-lb"
}
}

View File

@ -1,50 +0,0 @@
# Global definitions
variable "main_region" {
type = string
default = "isti_area_pi_1"
}
variable "external_network" {
type = map(string)
default = {
name = "external-network"
id = "1d2ff137-6ff7-4017-be2b-0d6c4af2353b"
}
}
variable "floating_ip_pools" {
type = map(string)
default = {
main_public_ip_pool = "external-network"
}
}
variable "resolvers_ip" {
type = list(string)
default = ["146.48.29.97", "146.48.29.98", "146.48.29.99"]
}
variable "mtu_size" {
type = number
default = 8942
}
variable "availability_zones_names" {
type = map(string)
default = {
availability_zone_no_gpu = "cnr-isti-nova-a"
availability_zone_with_gpu = "cnr-isti-nova-gpu-a"
}
}
variable "ssh_sources" {
type = map(string)
default = {
s2i2s_vpn_1_cidr = "146.48.28.10/32"
s2i2s_vpn_2_cidr = "146.48.28.11/32"
d4s_vpn_1_cidr = "146.48.122.27/32"
d4s_vpn_2_cidr = "146.48.122.49/32"
shell_d4s_cidr = "146.48.122.95/32"
infrascience_net_cidr = "146.48.122.0/23"
}
}

View File

@ -1,52 +0,0 @@
variable "ssh_key_file" {
type = map(string)
default = {
file = "~/.ssh/id_ed25519"
name = "adellam"
}
}
variable "ubuntu_1804" {
type = map(string)
default = {
name = "Ubuntu-Bionic-18.04"
uuid = "7ed6a2cd-2b07-482e-8ce4-f018dff16c89"
}
}
variable "ubuntu_2204" {
type = map(string)
default = {
name = "Ubuntu-Jammy-22.04"
uuid = "54768889-8556-4be4-a2eb-82a4d9b34627"
}
}
variable "centos_7" {
type = map(string)
default = {
name = "CentOS-7"
uuid = "f0187a99-64f6-462a-ab5f-ef52fe62f2ca"
}
}
variable "almalinux_9" {
type = map(string)
default = {
name = "AlmaLinux-9.0-20220718"
uuid = "541650fc-dd19-4f38-bb1d-7333ed9dd688"
}
}
variable "ubuntu1804_data_file" {
default = "../../openstack_vm_data_scripts/ubuntu1804.sh"
}
variable "ubuntu2204_data_file" {
default = "../../openstack_vm_data_scripts/ubuntu2204.sh"
}
variable "el7_data_file" {
default = "../../openstack_vm_data_scripts/el7.sh"
}

View File

@ -49,6 +49,18 @@ variable "ssh_sources" {
}
}
variable "networks_with_d4s_services" {
type = map(string)
default = {
"isti_net" = "146.48.80.0/21"
"s2i2s_net" = "146.48.28.0/22"
"infrascience_net" = "146.48.122.0/23"
"garr_ct1_net" = "90.147.166.0/23"
"garr_pa1_net" = "90.147.188.0/23"
"garr_na_net" = "90.147.152.0/24"
}
}
variable "ssh_key_file" {
type = map(string)
default = {

View File

@ -0,0 +1,185 @@
#
# Server groups for both the masters and the workers
#
resource "openstack_compute_servergroup_v2" "mongodb" {
name = "mongodb"
policies = ["anti-affinity"]
}
#
# Security groups
#
# Rules
# 80 from 0/0
# 9101 from prometheus
# 27017 da: garr-ct1, garr-na, garr-pa1, InfraScience, S2I2S
resource "openstack_networking_secgroup_v2" "mongodb_cluster_traffic" {
name = "mongodb_cluster_traffic"
delete_default_rules = "true"
description = "Traffic between the MongoDB nodes"
}
resource "openstack_networking_secgroup_rule_v2" "access_to_the_mongodb_service_from_the_internal_network" {
security_group_id = openstack_networking_secgroup_v2.mongodb_cluster_traffic.id
description = "Access to the MongoDB service"
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
port_range_min = 27017
port_range_max = 27017
remote_ip_prefix = var.main_private_subnet.cidr
}
resource "openstack_networking_secgroup_rule_v2" "access_to_the_mongodb_service_from_the_outside" {
for_each = toset([var.networks_with_d4s_services.infrascience_net,var.networks_with_d4s_services.s2i2s_net,var.networks_with_d4s_services.garr_ct1_net,var.networks_with_d4s_services.garr_pa1_net,var.networks_with_d4s_services.garr_na_net])
security_group_id = openstack_networking_secgroup_v2.mongodb_cluster_traffic.id
description = "Access to the MongoDB service"
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
port_range_min = 27017
port_range_max = 27017
remote_ip_prefix = each.value
}
resource "openstack_networking_secgroup_rule_v2" "mongodb_plain_http_for_letsencrypt" {
security_group_id = openstack_networking_secgroup_v2.mongodb_cluster_traffic.id
description = "Plain HTTP for letsencrypt"
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
port_range_min = 80
port_range_max = 80
remote_ip_prefix = "0.0.0.0/0"
}
resource "openstack_networking_secgroup_rule_v2" "mongodb_prometheus_exporter" {
security_group_id = openstack_networking_secgroup_v2.mongodb_cluster_traffic.id
description = "Prometheus exporter for MongoDB"
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
port_range_min = 9101
port_range_max = 9101
remote_ip_prefix = var.basic_services_ip.prometheus_cidr
}
#
# Mongodb cluster VMs
#
# Instance
resource "openstack_compute_instance_v2" "mongodb_cluster_nodes" {
count = var.mongodb_cluster_data.count
name = format("%s-%02d", var.mongodb_cluster_data.name, count.index+2)
availability_zone_hints = var.availability_zones_names.availability_zone_no_gpu
flavor_name = var.mongodb_cluster_data.flavor
key_pair = var.ssh_key_file.name
security_groups = [var.default_security_group_name,openstack_networking_secgroup_v2.mongodb_cluster_traffic.name]
scheduler_hints {
group = openstack_compute_servergroup_v2.mongodb.id
}
block_device {
uuid = var.mongodb_cluster_data.image_type_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.mongodb_cluster_data.data_disk_size
boot_index = -1
destination_type = "volume"
delete_on_termination = false
}
network {
name = var.main_private_network.name
fixed_ip_v4 = var.mongodb_ip.*[count.index]
}
user_data = "${file("${var.ubuntu2204_data_file}")}"
}
# Allocate a floating IP
resource "openstack_networking_floatingip_v2" "mongodb_cluster_floating_ip" {
count = var.mongodb_cluster_data.count
pool = var.floating_ip_pools.main_public_ip_pool
# The DNS association does not work because of a bug in the OpenStack API
# dns_name = "main-lb"
# dns_domain = var.dns_zone.zone_name
description = format("MongoDB cluster node %s-%02d", var.mongodb_cluster_data.name, count.index+2)
}
resource "openstack_compute_floatingip_associate_v2" "mongodb_cluster_ip" {
count = var.mongodb_cluster_data.count
floating_ip = element(openstack_networking_floatingip_v2.mongodb_cluster_floating_ip.*.address, count.index)
instance_id = element(openstack_compute_instance_v2.mongodb_cluster_nodes.*.id, count.index)
depends_on = [openstack_networking_floatingip_v2.mongodb_cluster_floating_ip]
}
resource "openstack_dns_recordset_v2" "mongodb_cluster_dns_recordsets" {
count = var.mongodb_cluster_data.count
zone_id = var.dns_zone_id
name = join(".", [element(openstack_compute_instance_v2.mongodb_cluster_nodes.*.name, count.index), var.dns_zone.zone_name])
description = "Mongodb public hostnames"
ttl = 8600
type = "A"
records = [element(openstack_networking_floatingip_v2.mongodb_cluster_floating_ip.*.address, count.index)]
depends_on = [openstack_networking_floatingip_v2.mongodb_cluster_floating_ip]
}
#
# MongoDB vol node
#
# Instance
resource "openstack_compute_instance_v2" "mongodb_vol_node" {
name = "mongodb-vol"
availability_zone_hints = var.availability_zones_names.availability_zone_no_gpu
flavor_name = var.mongodb_vol_data.flavor
key_pair = var.ssh_key_file.name
security_groups = [var.default_security_group_name,openstack_networking_secgroup_v2.mongodb_cluster_traffic.name]
block_device {
uuid = var.mongodb_vol_data.image_type_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.mongodb_vol_data.data_disk_size
boot_index = -1
destination_type = "volume"
delete_on_termination = false
}
network {
name = var.main_private_network.name
fixed_ip_v4 = var.mongodb_vol_ip
}
user_data = "${file("${var.ubuntu2204_data_file}")}"
}
# Allocate a floating IP
resource "openstack_networking_floatingip_v2" "mongodb_vol_floating_ip" {
pool = var.floating_ip_pools.main_public_ip_pool
# The DNS association does not work because of a bug in the OpenStack API
# dns_name = "main-lb"
# dns_domain = var.dns_zone.zone_name
description = "MongoDB Volatile"
}
resource "openstack_compute_floatingip_associate_v2" "mongodb_vol_public_ip" {
floating_ip = openstack_networking_floatingip_v2.mongodb_vol_floating_ip.address
instance_id = openstack_compute_instance_v2.mongodb_vol_node.id
depends_on = [openstack_networking_floatingip_v2.mongodb_vol_floating_ip]
}
resource "openstack_dns_recordset_v2" "mongodb_vol_dns_recordsets" {
zone_id = var.dns_zone_id
name = join(".", [openstack_compute_instance_v2.mongodb_vol_node.name], [var.dns_zone.zone_name])
description = "Mongodb Volatile public hostnames"
ttl = 8600
type = "A"
records = [openstack_networking_floatingip_v2.mongodb_vol_floating_ip.address]
depends_on = [openstack_networking_floatingip_v2.mongodb_vol_floating_ip]
}

View File

@ -0,0 +1,32 @@
variable "mongodb_cluster_data" {
type = map(string)
default = {
count = 3
name = "mongodb-replica"
flavor = "m1.small"
data_disk_size = 100
image_type_name = "Ubuntu-Focal-20.04"
image_type_uuid = "75c23040-2be7-49e9-8029-a16dc9f755d1"
}
}
variable "mongodb_ip" {
type = list(string)
default = []
}
variable "mongodb_vol_data" {
type = map(string)
default = {
name = "mongodb-vol"
flavor = "m1.small"
data_disk_size = 100
image_type_name = "Ubuntu-Focal-20.04"
image_type_uuid = "75c23040-2be7-49e9-8029-a16dc9f755d1"
}
}
variable "mongodb_vol_ip" {
default = ""
}

View File

@ -220,7 +220,7 @@ resource "openstack_networking_secgroup_rule_v2" "access_to_orient_from_clients"
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
remote_ip_prefix = each.key
remote_ip_prefix = each.value
}
resource "openstack_networking_secgroup_rule_v2" "access_to_orient_from_haproxy" {
for_each = toset( [var.basic_services_ip.haproxy_l7_1_cidr, var.basic_services_ip.haproxy_l7_2_cidr])
@ -231,7 +231,7 @@ resource "openstack_networking_secgroup_rule_v2" "access_to_orient_from_haproxy"
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
remote_ip_prefix = each.key
remote_ip_prefix = each.value
}
# OrientDB for the Smart Executor nodes
@ -250,7 +250,7 @@ resource "openstack_networking_secgroup_rule_v2" "access_to_orient_se_from_clien
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
remote_ip_prefix = each.key
remote_ip_prefix = each.value
}
resource "openstack_networking_secgroup_rule_v2" "access_to_orient_se_from_haproxy" {
for_each = toset( [var.basic_services_ip.haproxy_l7_1_cidr, var.basic_services_ip.haproxy_l7_2_cidr])
@ -261,7 +261,7 @@ resource "openstack_networking_secgroup_rule_v2" "access_to_orient_se_from_hapro
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
remote_ip_prefix = each.key
remote_ip_prefix = each.value
}
#

View File

@ -0,0 +1,93 @@
# 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]
}

View File

@ -0,0 +1,37 @@
variable "timescaledb_data" {
type = map(string)
default = {
node_name = "timescaledb"
node_data_disk_size = 10
node_data_disk_device = "/dev/vdb"
}
}
variable "timescaledb_node_flavor" {
default = ""
}
variable "timescaledb_nodes_count" {
default = 1
}
variable "timescaledb_ip" {
type = list(string)
default = []
}
variable "timescaledb_cidr" {
type = list(string)
default = [ ]
}
variable "timescaledb_net" {
type = map(string)
default = {
network_name = "timescaledb-net"
network_description = "Network used by the Timescaledb cluster and to access the service"
network_cidr = "192.168.11.0/24"
allocation_pool_start = "192.168.11.20"
allocation_pool_end = "192.168.11.254"
}
}