Added public db

This commit is contained in:
Giancarlo Panichi 2024-07-09 18:07:58 +02:00
parent 875de807a1
commit b95dfefe80
5 changed files with 251 additions and 251 deletions

View File

@ -0,0 +1,165 @@
# Define required providers
terraform {
required_version = ">= 0.14.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = ">= 1.54.0"
}
}
}
data "terraform_remote_state" "privnet_dns_router" {
backend = "local"
config = {
path = "../project-setup/terraform.tfstate"
}
}
data "terraform_remote_state" "infrastructure_setup" {
backend = "local"
config = {
path = "../basic-infrastructure/terraform.tfstate"
}
}
#
# Uses common_variables as module
#
module "common_variables" {
source = "../../modules/common_variables"
}
# Module used
module "ssh_settings" {
source = "../../modules/ssh-key-ref"
}
resource "openstack_networking_secgroup_v2" "d4science_db_access_list" {
name = "d4science_db_access_list"
delete_default_rules = "true"
description = "Allowed connections to the d4science database"
}
resource "openstack_networking_secgroup_rule_v2" "access_to_the_d4science_db" {
for_each = toset([var.d4science_db_allowed_sources.public])
security_group_id = openstack_networking_secgroup_v2.d4science_db_access_list.id
description = "Access to the d4science db"
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
port_range_min = 5432
port_range_max = 5432
remote_ip_prefix = each.value
}
# Block device
resource "openstack_blockstorage_volume_v3" "d4science_db_data_vol" {
name = var.d4science_db_data.vol_data_name
size = var.d4science_db_data.vol_data_size
}
resource "openstack_blockstorage_volume_v3" "d4science_db_backup_vol" {
name = var.d4science_db_data.vol_backup_name
size = var.d4science_db_data.vol_backup_size
}
#
# Ports in d4science db network
resource "openstack_networking_port_v2" "d4science_db_port_on_main_net" {
name = "d4science_db_port_on_main_net"
network_id = data.terraform_remote_state.privnet_dns_router.outputs.main_private_network_id
admin_state_up = "true"
fixed_ip {
subnet_id = data.terraform_remote_state.privnet_dns_router.outputs.main_subnet_network_id
}
security_group_ids = [
openstack_networking_secgroup_v2.d4science_db_access_list.id,
data.terraform_remote_state.infrastructure_setup.outputs.default_security_group.id
]
}
# Instance
resource "openstack_compute_instance_v2" "d4science_db_server" {
name = var.d4science_db_data.name
#availability_zone_hints = module.common_variables.availability_zone_no_gpu_name
flavor_name = var.d4science_db_data.flavor
key_pair = module.ssh_settings.ssh_key_name
security_groups = [data.terraform_remote_state.infrastructure_setup.outputs.default_security_group.name, data.terraform_remote_state.infrastructure_setup.outputs.access_postgresql_security_group.name, openstack_networking_secgroup_v2.d4science_db_access_list.name]
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
}
network {
name = module.common_variables.networks_list.shared_postgresql
fixed_ip_v4 = var.d4science_db_data.server_ip
}
user_data = file("${module.common_variables.ubuntu2204_data_file}")
# 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
]
}
}
resource "openstack_compute_volume_attach_v2" "d4science_db_attach_data_vol" {
instance_id = openstack_compute_instance_v2.d4science_db_server.id
volume_id = openstack_blockstorage_volume_v3.d4science_db_data_vol.id
device = var.d4science_db_data.vol_data_device
depends_on = [openstack_compute_instance_v2.d4science_db_server]
}
resource "openstack_compute_volume_attach_v2" "d4science_db_attach_backup_vol" {
instance_id = openstack_compute_instance_v2.d4science_db_server.id
volume_id = openstack_blockstorage_volume_v3.d4science_db_backup_vol.id
device = var.d4science_db_data.vol_backup_device
depends_on = [openstack_compute_instance_v2.d4science_db_server]
}
resource "openstack_compute_interface_attach_v2" "main_network_to_d4science_db" {
instance_id = openstack_compute_instance_v2.d4science_db_server.id
port_id = openstack_networking_port_v2.d4science_db_port_on_main_net.id
}
# Floating IP and DNS record
resource "openstack_networking_floatingip_v2" "d4science_db_ip" {
pool = data.terraform_remote_state.privnet_dns_router.outputs.floating_ip_pools.main_public_ip_pool
# The DNS association does not work because of a bug in the OpenStack API
description = "D4Science DB"
}
resource "openstack_networking_floatingip_associate_v2" "d4science_db_associate_floatingip" {
floating_ip = openstack_networking_floatingip_v2.d4science_db_ip.address
port_id = openstack_networking_port_v2.d4science_db_port_on_main_net.id
}
locals {
d4science_db_recordset_name = "d4science-db.${data.terraform_remote_state.privnet_dns_router.outputs.dns_zone.zone_name}"
}
resource "openstack_dns_recordset_v2" "d4science_db_recordset" {
zone_id = data.terraform_remote_state.privnet_dns_router.outputs.dns_zone_id
name = local.d4science_db_recordset_name
description = "Public IP address of D4Science DB"
ttl = 8600
type = "A"
records = [openstack_networking_floatingip_v2.d4science_db_ip.address]
}
output "d4science_db_public_ip_address" {
value = openstack_networking_floatingip_v2.d4science_db_ip.address
}
output "d4science_db_hostname" {
value = openstack_dns_recordset_v2.d4science_db_recordset.name
}

View File

@ -1,15 +1,15 @@
{ {
"version": 4, "version": 4,
"terraform_version": "1.6.4", "terraform_version": "1.6.4",
"serial": 13, "serial": 41,
"lineage": "f66c6799-6b6a-3a21-b78d-8773f096cb8b", "lineage": "f66c6799-6b6a-3a21-b78d-8773f096cb8b",
"outputs": { "outputs": {
"public_db_hostname": { "d4science_db_hostname": {
"value": "public-db.cloud.d4science.org.", "value": "d4science-db.cloud.d4science.org.",
"type": "string" "type": "string"
}, },
"public_db_public_ip_address": { "d4science_db_public_ip_address": {
"value": "146.48.30.43", "value": "146.48.30.161",
"type": "string" "type": "string"
} }
}, },
@ -5367,7 +5367,7 @@
{ {
"mode": "managed", "mode": "managed",
"type": "openstack_blockstorage_volume_v3", "type": "openstack_blockstorage_volume_v3",
"name": "public_db_backup_vol", "name": "d4science_db_backup_vol",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [ "instances": [
{ {
@ -5379,10 +5379,10 @@
"consistency_group_id": null, "consistency_group_id": null,
"description": "", "description": "",
"enable_online_resize": null, "enable_online_resize": null,
"id": "331bc904-5f93-4a32-92f5-8cd44f3b54a2", "id": "1dc9e359-6de3-4247-a060-21f37ccc93f0",
"image_id": null, "image_id": null,
"metadata": {}, "metadata": {},
"name": "public-db-backup", "name": "d4science-db-backup",
"region": "isti_area_pi_1", "region": "isti_area_pi_1",
"scheduler_hints": [], "scheduler_hints": [],
"size": 400, "size": 400,
@ -5400,7 +5400,7 @@
{ {
"mode": "managed", "mode": "managed",
"type": "openstack_blockstorage_volume_v3", "type": "openstack_blockstorage_volume_v3",
"name": "public_db_data_vol", "name": "d4science_db_data_vol",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [ "instances": [
{ {
@ -5412,10 +5412,10 @@
"consistency_group_id": null, "consistency_group_id": null,
"description": "", "description": "",
"enable_online_resize": null, "enable_online_resize": null,
"id": "70157143-fb93-4b54-a364-44a93a682eda", "id": "b3ceb8eb-6507-486f-aae9-55d97d3fce05",
"image_id": null, "image_id": null,
"metadata": {}, "metadata": {},
"name": "public-db-data", "name": "d4science-db-data",
"region": "isti_area_pi_1", "region": "isti_area_pi_1",
"scheduler_hints": [], "scheduler_hints": [],
"size": 600, "size": 600,
@ -5433,7 +5433,7 @@
{ {
"mode": "managed", "mode": "managed",
"type": "openstack_compute_instance_v2", "type": "openstack_compute_instance_v2",
"name": "public_db_server", "name": "d4science_db_server",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [ "instances": [
{ {
@ -5462,22 +5462,22 @@
} }
], ],
"config_drive": null, "config_drive": null,
"created": "2024-07-09 14:55:57 +0000 UTC", "created": "2024-07-09 15:55:42 +0000 UTC",
"flavor_id": "9", "flavor_id": "9",
"flavor_name": "m1.large", "flavor_name": "m1.large",
"force_delete": false, "force_delete": false,
"id": "ccec0021-6453-404e-afcf-01fc06655fb0", "id": "8b910be8-bfee-4104-b895-0a81c0c24537",
"image_id": "Attempt to boot from volume - no image supplied", "image_id": "Attempt to boot from volume - no image supplied",
"image_name": null, "image_name": null,
"key_pair": "Giancarlo Panichi", "key_pair": "Giancarlo Panichi",
"metadata": null, "metadata": null,
"name": "public-db-server", "name": "d4science-db",
"network": [ "network": [
{ {
"access_network": false, "access_network": false,
"fixed_ip_v4": "192.168.0.20", "fixed_ip_v4": "192.168.0.20",
"fixed_ip_v6": "", "fixed_ip_v6": "",
"mac": "fa:16:3e:08:e2:0e", "mac": "fa:16:3e:54:aa:82",
"name": "postgresql-srv-net", "name": "postgresql-srv-net",
"port": "", "port": "",
"uuid": "f6450bc8-1345-4b52-8f34-2903c0cca7f8" "uuid": "f6450bc8-1345-4b52-8f34-2903c0cca7f8"
@ -5490,13 +5490,13 @@
"scheduler_hints": [], "scheduler_hints": [],
"security_groups": [ "security_groups": [
"access_to_the_shared_postgresql_service", "access_to_the_shared_postgresql_service",
"default_for_all", "d4science_db_access_list",
"public_db_access_list" "default_for_all"
], ],
"stop_before_destroy": false, "stop_before_destroy": false,
"tags": null, "tags": null,
"timeouts": null, "timeouts": null,
"updated": "2024-07-09 14:56:49 +0000 UTC", "updated": "2024-07-09 15:56:38 +0000 UTC",
"user_data": "bb83b25fd1219aa1b850ece9be8d7b0f31714608", "user_data": "bb83b25fd1219aa1b850ece9be8d7b0f31714608",
"vendor_options": [] "vendor_options": []
}, },
@ -5504,7 +5504,7 @@
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJkZWxldGUiOjE4MDAwMDAwMDAwMDAsInVwZGF0ZSI6MTgwMDAwMDAwMDAwMH19", "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJkZWxldGUiOjE4MDAwMDAwMDAwMDAsInVwZGF0ZSI6MTgwMDAwMDAwMDAwMH19",
"dependencies": [ "dependencies": [
"data.terraform_remote_state.infrastructure_setup", "data.terraform_remote_state.infrastructure_setup",
"openstack_networking_secgroup_v2.public_db_access_list" "openstack_networking_secgroup_v2.d4science_db_access_list"
] ]
} }
] ]
@ -5512,17 +5512,17 @@
{ {
"mode": "managed", "mode": "managed",
"type": "openstack_compute_interface_attach_v2", "type": "openstack_compute_interface_attach_v2",
"name": "main_network_to_public_db", "name": "main_network_to_d4science_db",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [ "instances": [
{ {
"schema_version": 0, "schema_version": 0,
"attributes": { "attributes": {
"fixed_ip": "10.1.43.222", "fixed_ip": "10.1.42.125",
"id": "ccec0021-6453-404e-afcf-01fc06655fb0/08895a25-ff6a-43b2-8c47-717ba3b3fe6e", "id": "8b910be8-bfee-4104-b895-0a81c0c24537/aa4ce73d-5cf1-4a97-bb9f-eb35e83035da",
"instance_id": "ccec0021-6453-404e-afcf-01fc06655fb0", "instance_id": "8b910be8-bfee-4104-b895-0a81c0c24537",
"network_id": "020df98d-ae72-452a-b376-3b6dc289acac", "network_id": "020df98d-ae72-452a-b376-3b6dc289acac",
"port_id": "08895a25-ff6a-43b2-8c47-717ba3b3fe6e", "port_id": "aa4ce73d-5cf1-4a97-bb9f-eb35e83035da",
"region": "isti_area_pi_1", "region": "isti_area_pi_1",
"timeouts": null "timeouts": null
}, },
@ -5531,9 +5531,9 @@
"dependencies": [ "dependencies": [
"data.terraform_remote_state.infrastructure_setup", "data.terraform_remote_state.infrastructure_setup",
"data.terraform_remote_state.privnet_dns_router", "data.terraform_remote_state.privnet_dns_router",
"openstack_compute_instance_v2.public_db_server", "openstack_compute_instance_v2.d4science_db_server",
"openstack_networking_port_v2.public_db_port_on_main_net", "openstack_networking_port_v2.d4science_db_port_on_main_net",
"openstack_networking_secgroup_v2.public_db_access_list" "openstack_networking_secgroup_v2.d4science_db_access_list"
] ]
} }
] ]
@ -5541,29 +5541,29 @@
{ {
"mode": "managed", "mode": "managed",
"type": "openstack_compute_volume_attach_v2", "type": "openstack_compute_volume_attach_v2",
"name": "public_db_attach_backup_vol", "name": "d4science_db_attach_backup_vol",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [ "instances": [
{ {
"schema_version": 0, "schema_version": 0,
"attributes": { "attributes": {
"device": "/dev/vdc", "device": "/dev/vdc",
"id": "ccec0021-6453-404e-afcf-01fc06655fb0/331bc904-5f93-4a32-92f5-8cd44f3b54a2", "id": "8b910be8-bfee-4104-b895-0a81c0c24537/1dc9e359-6de3-4247-a060-21f37ccc93f0",
"instance_id": "ccec0021-6453-404e-afcf-01fc06655fb0", "instance_id": "8b910be8-bfee-4104-b895-0a81c0c24537",
"multiattach": null, "multiattach": null,
"region": "isti_area_pi_1", "region": "isti_area_pi_1",
"tag": null, "tag": null,
"timeouts": null, "timeouts": null,
"vendor_options": [], "vendor_options": [],
"volume_id": "331bc904-5f93-4a32-92f5-8cd44f3b54a2" "volume_id": "1dc9e359-6de3-4247-a060-21f37ccc93f0"
}, },
"sensitive_attributes": [], "sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0=", "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0=",
"dependencies": [ "dependencies": [
"data.terraform_remote_state.infrastructure_setup", "data.terraform_remote_state.infrastructure_setup",
"openstack_blockstorage_volume_v3.public_db_backup_vol", "openstack_blockstorage_volume_v3.d4science_db_backup_vol",
"openstack_compute_instance_v2.public_db_server", "openstack_compute_instance_v2.d4science_db_server",
"openstack_networking_secgroup_v2.public_db_access_list" "openstack_networking_secgroup_v2.d4science_db_access_list"
] ]
} }
] ]
@ -5571,29 +5571,29 @@
{ {
"mode": "managed", "mode": "managed",
"type": "openstack_compute_volume_attach_v2", "type": "openstack_compute_volume_attach_v2",
"name": "public_db_attach_data_vol", "name": "d4science_db_attach_data_vol",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [ "instances": [
{ {
"schema_version": 0, "schema_version": 0,
"attributes": { "attributes": {
"device": "/dev/vdb", "device": "/dev/vdb",
"id": "ccec0021-6453-404e-afcf-01fc06655fb0/70157143-fb93-4b54-a364-44a93a682eda", "id": "8b910be8-bfee-4104-b895-0a81c0c24537/b3ceb8eb-6507-486f-aae9-55d97d3fce05",
"instance_id": "ccec0021-6453-404e-afcf-01fc06655fb0", "instance_id": "8b910be8-bfee-4104-b895-0a81c0c24537",
"multiattach": null, "multiattach": null,
"region": "isti_area_pi_1", "region": "isti_area_pi_1",
"tag": null, "tag": null,
"timeouts": null, "timeouts": null,
"vendor_options": [], "vendor_options": [],
"volume_id": "70157143-fb93-4b54-a364-44a93a682eda" "volume_id": "b3ceb8eb-6507-486f-aae9-55d97d3fce05"
}, },
"sensitive_attributes": [], "sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0=", "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfX0=",
"dependencies": [ "dependencies": [
"data.terraform_remote_state.infrastructure_setup", "data.terraform_remote_state.infrastructure_setup",
"openstack_blockstorage_volume_v3.public_db_data_vol", "openstack_blockstorage_volume_v3.d4science_db_data_vol",
"openstack_compute_instance_v2.public_db_server", "openstack_compute_instance_v2.d4science_db_server",
"openstack_networking_secgroup_v2.public_db_access_list" "openstack_networking_secgroup_v2.d4science_db_access_list"
] ]
} }
] ]
@ -5601,19 +5601,19 @@
{ {
"mode": "managed", "mode": "managed",
"type": "openstack_dns_recordset_v2", "type": "openstack_dns_recordset_v2",
"name": "public_db_recordset", "name": "d4science_db_recordset",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [ "instances": [
{ {
"schema_version": 0, "schema_version": 0,
"attributes": { "attributes": {
"description": "Public IP address of Public DB", "description": "Public IP address of D4Science DB",
"disable_status_check": false, "disable_status_check": false,
"id": "74135b34-1a9c-4c01-8cf0-22450a5660c4/874ddba2-9060-4992-98ce-ca239f0a3068", "id": "74135b34-1a9c-4c01-8cf0-22450a5660c4/bb979116-cdef-4493-9c5b-de928619c546",
"name": "public-db.cloud.d4science.org.", "name": "d4science-db.cloud.d4science.org.",
"project_id": "1b45adf388934758b56d0dfdb4bfacf3", "project_id": "1b45adf388934758b56d0dfdb4bfacf3",
"records": [ "records": [
"146.48.30.43" "146.48.30.161"
], ],
"region": "isti_area_pi_1", "region": "isti_area_pi_1",
"timeouts": null, "timeouts": null,
@ -5626,7 +5626,7 @@
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwLCJ1cGRhdGUiOjYwMDAwMDAwMDAwMH19", "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwLCJ1cGRhdGUiOjYwMDAwMDAwMDAwMH19",
"dependencies": [ "dependencies": [
"data.terraform_remote_state.privnet_dns_router", "data.terraform_remote_state.privnet_dns_router",
"openstack_networking_floatingip_v2.public_db_ip" "openstack_networking_floatingip_v2.d4science_db_ip"
] ]
} }
] ]
@ -5634,16 +5634,16 @@
{ {
"mode": "managed", "mode": "managed",
"type": "openstack_networking_floatingip_associate_v2", "type": "openstack_networking_floatingip_associate_v2",
"name": "public_db_associate_floatingip", "name": "d4science_db_associate_floatingip",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [ "instances": [
{ {
"schema_version": 0, "schema_version": 0,
"attributes": { "attributes": {
"fixed_ip": "10.1.43.222", "fixed_ip": "10.1.42.125",
"floating_ip": "146.48.30.43", "floating_ip": "146.48.30.161",
"id": "b1cad88f-5631-4381-a044-e6521d2b53af", "id": "edce1a47-07f9-453c-bc50-5d94d27fb57e",
"port_id": "08895a25-ff6a-43b2-8c47-717ba3b3fe6e", "port_id": "aa4ce73d-5cf1-4a97-bb9f-eb35e83035da",
"region": "isti_area_pi_1" "region": "isti_area_pi_1"
}, },
"sensitive_attributes": [], "sensitive_attributes": [],
@ -5651,9 +5651,9 @@
"dependencies": [ "dependencies": [
"data.terraform_remote_state.infrastructure_setup", "data.terraform_remote_state.infrastructure_setup",
"data.terraform_remote_state.privnet_dns_router", "data.terraform_remote_state.privnet_dns_router",
"openstack_networking_floatingip_v2.public_db_ip", "openstack_networking_floatingip_v2.d4science_db_ip",
"openstack_networking_port_v2.public_db_port_on_main_net", "openstack_networking_port_v2.d4science_db_port_on_main_net",
"openstack_networking_secgroup_v2.public_db_access_list" "openstack_networking_secgroup_v2.d4science_db_access_list"
] ]
} }
] ]
@ -5661,19 +5661,19 @@
{ {
"mode": "managed", "mode": "managed",
"type": "openstack_networking_floatingip_v2", "type": "openstack_networking_floatingip_v2",
"name": "public_db_ip", "name": "d4science_db_ip",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [ "instances": [
{ {
"schema_version": 0, "schema_version": 0,
"attributes": { "attributes": {
"address": "146.48.30.43", "address": "146.48.30.161",
"all_tags": [], "all_tags": [],
"description": "Public DB", "description": "D4Science DB",
"dns_domain": "", "dns_domain": "",
"dns_name": "", "dns_name": "",
"fixed_ip": "", "fixed_ip": "",
"id": "b1cad88f-5631-4381-a044-e6521d2b53af", "id": "edce1a47-07f9-453c-bc50-5d94d27fb57e",
"pool": "external-network", "pool": "external-network",
"port_id": "", "port_id": "",
"region": "isti_area_pi_1", "region": "isti_area_pi_1",
@ -5695,7 +5695,7 @@
{ {
"mode": "managed", "mode": "managed",
"type": "openstack_networking_port_v2", "type": "openstack_networking_port_v2",
"name": "public_db_port_on_main_net", "name": "d4science_db_port_on_main_net",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [ "instances": [
{ {
@ -5703,10 +5703,10 @@
"attributes": { "attributes": {
"admin_state_up": true, "admin_state_up": true,
"all_fixed_ips": [ "all_fixed_ips": [
"10.1.43.222" "10.1.42.125"
], ],
"all_security_group_ids": [ "all_security_group_ids": [
"6aade127-1ed2-425c-939d-c5a08806818a", "12568ab8-4b35-411d-b3da-48b0002a07b6",
"ec201518-ab19-4342-8465-4b5524030a8e" "ec201518-ab19-4342-8465-4b5524030a8e"
], ],
"all_tags": [], "all_tags": [],
@ -5725,9 +5725,9 @@
"device_owner": "", "device_owner": "",
"dns_assignment": [ "dns_assignment": [
{ {
"fqdn": "host-10-1-43-222.openstacklocal.", "fqdn": "host-10-1-42-125.openstacklocal.",
"hostname": "host-10-1-43-222", "hostname": "host-10-1-42-125",
"ip_address": "10.1.43.222" "ip_address": "10.1.42.125"
} }
], ],
"dns_name": "", "dns_name": "",
@ -5738,9 +5738,9 @@
"subnet_id": "5d7b83ad-e058-4a3a-bfd8-d20ba6d42e1a" "subnet_id": "5d7b83ad-e058-4a3a-bfd8-d20ba6d42e1a"
} }
], ],
"id": "08895a25-ff6a-43b2-8c47-717ba3b3fe6e", "id": "aa4ce73d-5cf1-4a97-bb9f-eb35e83035da",
"mac_address": "fa:16:3e:20:b8:17", "mac_address": "fa:16:3e:52:4d:ce",
"name": "public_db_port_on_main_net", "name": "d4science_db_port_on_main_net",
"network_id": "020df98d-ae72-452a-b376-3b6dc289acac", "network_id": "020df98d-ae72-452a-b376-3b6dc289acac",
"no_fixed_ip": null, "no_fixed_ip": null,
"no_security_groups": null, "no_security_groups": null,
@ -5748,7 +5748,7 @@
"qos_policy_id": "", "qos_policy_id": "",
"region": "isti_area_pi_1", "region": "isti_area_pi_1",
"security_group_ids": [ "security_group_ids": [
"6aade127-1ed2-425c-939d-c5a08806818a", "12568ab8-4b35-411d-b3da-48b0002a07b6",
"ec201518-ab19-4342-8465-4b5524030a8e" "ec201518-ab19-4342-8465-4b5524030a8e"
], ],
"tags": null, "tags": null,
@ -5761,7 +5761,7 @@
"dependencies": [ "dependencies": [
"data.terraform_remote_state.infrastructure_setup", "data.terraform_remote_state.infrastructure_setup",
"data.terraform_remote_state.privnet_dns_router", "data.terraform_remote_state.privnet_dns_router",
"openstack_networking_secgroup_v2.public_db_access_list" "openstack_networking_secgroup_v2.d4science_db_access_list"
] ]
} }
] ]
@ -5769,31 +5769,31 @@
{ {
"mode": "managed", "mode": "managed",
"type": "openstack_networking_secgroup_rule_v2", "type": "openstack_networking_secgroup_rule_v2",
"name": "access_to_the_public_db", "name": "access_to_the_d4science_db",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [ "instances": [
{ {
"index_key": "0.0.0.0/0", "index_key": "0.0.0.0/0",
"schema_version": 0, "schema_version": 0,
"attributes": { "attributes": {
"description": "Access to the public db", "description": "Access to the d4science db",
"direction": "ingress", "direction": "ingress",
"ethertype": "IPv4", "ethertype": "IPv4",
"id": "d04686b5-2399-469f-af88-a5d67eccee04", "id": "8bc3c262-1901-46ee-bddb-55c66a958364",
"port_range_max": 5432, "port_range_max": 5432,
"port_range_min": 5432, "port_range_min": 5432,
"protocol": "tcp", "protocol": "tcp",
"region": "isti_area_pi_1", "region": "isti_area_pi_1",
"remote_group_id": "", "remote_group_id": "",
"remote_ip_prefix": "0.0.0.0/0", "remote_ip_prefix": "0.0.0.0/0",
"security_group_id": "6aade127-1ed2-425c-939d-c5a08806818a", "security_group_id": "12568ab8-4b35-411d-b3da-48b0002a07b6",
"tenant_id": "1b45adf388934758b56d0dfdb4bfacf3", "tenant_id": "1b45adf388934758b56d0dfdb4bfacf3",
"timeouts": null "timeouts": null
}, },
"sensitive_attributes": [], "sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiZGVsZXRlIjo2MDAwMDAwMDAwMDB9fQ==", "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiZGVsZXRlIjo2MDAwMDAwMDAwMDB9fQ==",
"dependencies": [ "dependencies": [
"openstack_networking_secgroup_v2.public_db_access_list" "openstack_networking_secgroup_v2.d4science_db_access_list"
] ]
} }
] ]
@ -5801,7 +5801,7 @@
{ {
"mode": "managed", "mode": "managed",
"type": "openstack_networking_secgroup_v2", "type": "openstack_networking_secgroup_v2",
"name": "public_db_access_list", "name": "d4science_db_access_list",
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]", "provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
"instances": [ "instances": [
{ {
@ -5809,9 +5809,9 @@
"attributes": { "attributes": {
"all_tags": [], "all_tags": [],
"delete_default_rules": true, "delete_default_rules": true,
"description": "Allowed connections to the public database", "description": "Allowed connections to the d4science database",
"id": "6aade127-1ed2-425c-939d-c5a08806818a", "id": "12568ab8-4b35-411d-b3da-48b0002a07b6",
"name": "public_db_access_list", "name": "d4science_db_access_list",
"region": "isti_area_pi_1", "region": "isti_area_pi_1",
"tags": null, "tags": null,
"tenant_id": "1b45adf388934758b56d0dfdb4bfacf3", "tenant_id": "1b45adf388934758b56d0dfdb4bfacf3",

View File

@ -1,21 +1,21 @@
#Public DB variables #D4Science DB variables
variable "public_db_data" { variable "d4science_db_data" {
type = map(string) type = map(string)
default = { default = {
name = "public-db-server" name = "d4science-db"
flavor = "m1.large" flavor = "m1.large"
vol_data_name = "public-db-data" vol_data_name = "d4science-db-data"
vol_data_size = "600" vol_data_size = "600"
vol_data_device = "/dev/vdb" vol_data_device = "/dev/vdb"
vol_backup_name = "public-db-backup" vol_backup_name = "d4science-db-backup"
vol_backup_size = "400" vol_backup_size = "400"
vol_backup_device = "/dev/vdc" vol_backup_device = "/dev/vdc"
server_ip = "192.168.0.20" server_ip = "192.168.0.20"
} }
} }
variable "public_db_allowed_sources" { variable "d4science_db_allowed_sources" {
type = map(string) type = map(string)
default = { default = {
"public" = "0.0.0.0/0" "public" = "0.0.0.0/0"

View File

@ -1,165 +0,0 @@
# Define required providers
terraform {
required_version = ">= 0.14.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = ">= 1.54.0"
}
}
}
data "terraform_remote_state" "privnet_dns_router" {
backend = "local"
config = {
path = "../project-setup/terraform.tfstate"
}
}
data "terraform_remote_state" "infrastructure_setup" {
backend = "local"
config = {
path = "../basic-infrastructure/terraform.tfstate"
}
}
#
# Uses common_variables as module
#
module "common_variables" {
source = "../../modules/common_variables"
}
# Module used
module "ssh_settings" {
source = "../../modules/ssh-key-ref"
}
resource "openstack_networking_secgroup_v2" "public_db_access_list" {
name = "public_db_access_list"
delete_default_rules = "true"
description = "Allowed connections to the public database"
}
resource "openstack_networking_secgroup_rule_v2" "access_to_the_public_db" {
for_each = toset([var.public_db_allowed_sources.public])
security_group_id = openstack_networking_secgroup_v2.public_db_access_list.id
description = "Access to the public db"
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
port_range_min = 5432
port_range_max = 5432
remote_ip_prefix = each.value
}
# Block device
resource "openstack_blockstorage_volume_v3" "public_db_data_vol" {
name = var.public_db_data.vol_data_name
size = var.public_db_data.vol_data_size
}
resource "openstack_blockstorage_volume_v3" "public_db_backup_vol" {
name = var.public_db_data.vol_backup_name
size = var.public_db_data.vol_backup_size
}
#
# Ports in public db network
resource "openstack_networking_port_v2" "public_db_port_on_main_net" {
name = "public_db_port_on_main_net"
network_id = data.terraform_remote_state.privnet_dns_router.outputs.main_private_network_id
admin_state_up = "true"
fixed_ip {
subnet_id = data.terraform_remote_state.privnet_dns_router.outputs.main_subnet_network_id
}
security_group_ids = [
openstack_networking_secgroup_v2.public_db_access_list.id,
data.terraform_remote_state.infrastructure_setup.outputs.default_security_group.id
]
}
# Instance
resource "openstack_compute_instance_v2" "public_db_server" {
name = var.public_db_data.name
#availability_zone_hints = module.common_variables.availability_zone_no_gpu_name
flavor_name = var.public_db_data.flavor
key_pair = module.ssh_settings.ssh_key_name
security_groups = [data.terraform_remote_state.infrastructure_setup.outputs.default_security_group.name, data.terraform_remote_state.infrastructure_setup.outputs.access_postgresql_security_group.name, openstack_networking_secgroup_v2.public_db_access_list.name]
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
}
network {
name = module.common_variables.networks_list.shared_postgresql
fixed_ip_v4 = var.public_db_data.server_ip
}
user_data = file("${module.common_variables.ubuntu2204_data_file}")
# 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
]
}
}
resource "openstack_compute_volume_attach_v2" "public_db_attach_data_vol" {
instance_id = openstack_compute_instance_v2.public_db_server.id
volume_id = openstack_blockstorage_volume_v3.public_db_data_vol.id
device = var.public_db_data.vol_data_device
depends_on = [openstack_compute_instance_v2.public_db_server]
}
resource "openstack_compute_volume_attach_v2" "public_db_attach_backup_vol" {
instance_id = openstack_compute_instance_v2.public_db_server.id
volume_id = openstack_blockstorage_volume_v3.public_db_backup_vol.id
device = var.public_db_data.vol_backup_device
depends_on = [openstack_compute_instance_v2.public_db_server]
}
resource "openstack_compute_interface_attach_v2" "main_network_to_public_db" {
instance_id = openstack_compute_instance_v2.public_db_server.id
port_id = openstack_networking_port_v2.public_db_port_on_main_net.id
}
# Floating IP and DNS record
resource "openstack_networking_floatingip_v2" "public_db_ip" {
pool = data.terraform_remote_state.privnet_dns_router.outputs.floating_ip_pools.main_public_ip_pool
# The DNS association does not work because of a bug in the OpenStack API
description = "Public DB"
}
resource "openstack_networking_floatingip_associate_v2" "public_db_associate_floatingip" {
floating_ip = openstack_networking_floatingip_v2.public_db_ip.address
port_id = openstack_networking_port_v2.public_db_port_on_main_net.id
}
locals {
public_db_recordset_name = "public-db.${data.terraform_remote_state.privnet_dns_router.outputs.dns_zone.zone_name}"
}
resource "openstack_dns_recordset_v2" "public_db_recordset" {
zone_id = data.terraform_remote_state.privnet_dns_router.outputs.dns_zone_id
name = local.public_db_recordset_name
description = "Public IP address of Public DB"
ttl = 8600
type = "A"
records = [openstack_networking_floatingip_v2.public_db_ip.address]
}
output "public_db_public_ip_address" {
value = openstack_networking_floatingip_v2.public_db_ip.address
}
output "public_db_hostname" {
value = openstack_dns_recordset_v2.public_db_recordset.name
}